1 // Copyright 2007, Google Inc. 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are 6 // met: 7 // 8 // * Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // * Redistributions in binary form must reproduce the above 11 // copyright notice, this list of conditions and the following disclaimer 12 // in the documentation and/or other materials provided with the 13 // distribution. 14 // * Neither the name of Google Inc. nor the names of its 15 // contributors may be used to endorse or promote products derived from 16 // this software without specific prior written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 // 30 // Author: wan@google.com (Zhanyong Wan) 31 32 // Google Mock - a framework for writing C++ mock classes. 33 // 34 // This is the main header file a user should include. 35 36 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_ 37 #define GMOCK_INCLUDE_GMOCK_GMOCK_H_ 38 39 #ifdef __clang__ 40 # pragma clang diagnostic ignored "-Wc99-extensions" 41 #endif 42 43 // This file implements the following syntax: 44 // 45 // ON_CALL(mock_object.Method(...)) 46 // .With(...) ? 47 // .WillByDefault(...); 48 // 49 // where With() is optional and WillByDefault() must appear exactly 50 // once. 51 // 52 // EXPECT_CALL(mock_object.Method(...)) 53 // .With(...) ? 54 // .Times(...) ? 55 // .InSequence(...) * 56 // .WillOnce(...) * 57 // .WillRepeatedly(...) ? 58 // .RetiresOnSaturation() ? ; 59 // 60 // where all clauses are optional and WillOnce() can be repeated. 61 62 // Copyright 2007, Google Inc. 63 // All rights reserved. 64 // 65 // Redistribution and use in source and binary forms, with or without 66 // modification, are permitted provided that the following conditions are 67 // met: 68 // 69 // * Redistributions of source code must retain the above copyright 70 // notice, this list of conditions and the following disclaimer. 71 // * Redistributions in binary form must reproduce the above 72 // copyright notice, this list of conditions and the following disclaimer 73 // in the documentation and/or other materials provided with the 74 // distribution. 75 // * Neither the name of Google Inc. nor the names of its 76 // contributors may be used to endorse or promote products derived from 77 // this software without specific prior written permission. 78 // 79 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 80 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 81 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 82 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 83 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 84 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 85 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 86 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 87 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 88 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 89 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 90 // 91 // Author: wan@google.com (Zhanyong Wan) 92 93 // Google Mock - a framework for writing C++ mock classes. 94 // 95 // This file implements some commonly used actions. 96 97 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 98 #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 99 100 #ifndef _WIN32_WCE 101 # include <errno.h> 102 #endif 103 104 #include <algorithm> 105 #include <string> 106 107 // Copyright 2007, Google Inc. 108 // All rights reserved. 109 // 110 // Redistribution and use in source and binary forms, with or without 111 // modification, are permitted provided that the following conditions are 112 // met: 113 // 114 // * Redistributions of source code must retain the above copyright 115 // notice, this list of conditions and the following disclaimer. 116 // * Redistributions in binary form must reproduce the above 117 // copyright notice, this list of conditions and the following disclaimer 118 // in the documentation and/or other materials provided with the 119 // distribution. 120 // * Neither the name of Google Inc. nor the names of its 121 // contributors may be used to endorse or promote products derived from 122 // this software without specific prior written permission. 123 // 124 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 125 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 126 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 127 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 128 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 129 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 130 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 131 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 132 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 133 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 134 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 135 // 136 // Author: wan@google.com (Zhanyong Wan) 137 138 // Google Mock - a framework for writing C++ mock classes. 139 // 140 // This file defines some utilities useful for implementing Google 141 // Mock. They are subject to change without notice, so please DO NOT 142 // USE THEM IN USER CODE. 143 144 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ 145 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ 146 147 #include <stdio.h> 148 #include <ostream> // NOLINT 149 #include <string> 150 151 // This file was GENERATED by command: 152 // pump.py gmock-generated-internal-utils.h.pump 153 // DO NOT EDIT BY HAND!!! 154 155 // Copyright 2007, Google Inc. 156 // All rights reserved. 157 // 158 // Redistribution and use in source and binary forms, with or without 159 // modification, are permitted provided that the following conditions are 160 // met: 161 // 162 // * Redistributions of source code must retain the above copyright 163 // notice, this list of conditions and the following disclaimer. 164 // * Redistributions in binary form must reproduce the above 165 // copyright notice, this list of conditions and the following disclaimer 166 // in the documentation and/or other materials provided with the 167 // distribution. 168 // * Neither the name of Google Inc. nor the names of its 169 // contributors may be used to endorse or promote products derived from 170 // this software without specific prior written permission. 171 // 172 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 174 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 175 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 176 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 177 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 178 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 179 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 180 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 181 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 182 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 183 // 184 // Author: wan@google.com (Zhanyong Wan) 185 186 // Google Mock - a framework for writing C++ mock classes. 187 // 188 // This file contains template meta-programming utility classes needed 189 // for implementing Google Mock. 190 191 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ 192 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ 193 194 // Copyright 2008, Google Inc. 195 // All rights reserved. 196 // 197 // Redistribution and use in source and binary forms, with or without 198 // modification, are permitted provided that the following conditions are 199 // met: 200 // 201 // * Redistributions of source code must retain the above copyright 202 // notice, this list of conditions and the following disclaimer. 203 // * Redistributions in binary form must reproduce the above 204 // copyright notice, this list of conditions and the following disclaimer 205 // in the documentation and/or other materials provided with the 206 // distribution. 207 // * Neither the name of Google Inc. nor the names of its 208 // contributors may be used to endorse or promote products derived from 209 // this software without specific prior written permission. 210 // 211 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 212 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 213 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 214 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 215 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 217 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 218 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 219 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 220 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 221 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 222 // 223 // Author: vadimb@google.com (Vadim Berman) 224 // 225 // Low-level types and utilities for porting Google Mock to various 226 // platforms. They are subject to change without notice. DO NOT USE 227 // THEM IN USER CODE. 228 229 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 230 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 231 232 #include <assert.h> 233 #include <stdlib.h> 234 #include <iostream> 235 236 // Most of the types needed for porting Google Mock are also required 237 // for Google Test and are defined in gtest-port.h. 238 #include "gtest/gtest.h" 239 240 // To avoid conditional compilation everywhere, we make it 241 // gmock-port.h's responsibility to #include the header implementing 242 // tr1/tuple. gmock-port.h does this via gtest-port.h, which is 243 // guaranteed to pull in the tuple header. 244 245 // For MS Visual C++, check the compiler version. At least VS 2003 is 246 // required to compile Google Mock. 247 #if defined(_MSC_VER) && _MSC_VER < 1310 248 # error "At least Visual C++ 2003 (7.1) is required to compile Google Mock." 249 #endif 250 251 // Macro for referencing flags. This is public as we want the user to 252 // use this syntax to reference Google Mock flags. 253 #define GMOCK_FLAG(name) FLAGS_gmock_##name 254 255 // Macros for declaring flags. 256 #define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name) 257 #define GMOCK_DECLARE_int32_(name) \ 258 extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) 259 #define GMOCK_DECLARE_string_(name) \ 260 extern GTEST_API_ ::std::string GMOCK_FLAG(name) 261 262 // Macros for defining flags. 263 #define GMOCK_DEFINE_bool_(name, default_val, doc) \ 264 GTEST_API_ bool GMOCK_FLAG(name) = (default_val) 265 #define GMOCK_DEFINE_int32_(name, default_val, doc) \ 266 GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val) 267 #define GMOCK_DEFINE_string_(name, default_val, doc) \ 268 GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val) 269 270 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 271 272 namespace testing { 273 274 template <typename T> 275 class Matcher; 276 277 namespace internal { 278 279 // An IgnoredValue object can be implicitly constructed from ANY value. 280 // This is used in implementing the IgnoreResult(a) action. 281 class IgnoredValue { 282 public: 283 // This constructor template allows any value to be implicitly 284 // converted to IgnoredValue. The object has no data member and 285 // doesn't try to remember anything about the argument. We 286 // deliberately omit the 'explicit' keyword in order to allow the 287 // conversion to be implicit. 288 template <typename T> IgnoredValue(const T &)289 IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit) 290 }; 291 292 // MatcherTuple<T>::type is a tuple type where each field is a Matcher 293 // for the corresponding field in tuple type T. 294 template <typename Tuple> 295 struct MatcherTuple; 296 297 template <> 298 struct MatcherTuple< ::std::tr1::tuple<> > { 299 typedef ::std::tr1::tuple< > type; 300 }; 301 302 template <typename A1> 303 struct MatcherTuple< ::std::tr1::tuple<A1> > { 304 typedef ::std::tr1::tuple<Matcher<A1> > type; 305 }; 306 307 template <typename A1, typename A2> 308 struct MatcherTuple< ::std::tr1::tuple<A1, A2> > { 309 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2> > type; 310 }; 311 312 template <typename A1, typename A2, typename A3> 313 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3> > { 314 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3> > type; 315 }; 316 317 template <typename A1, typename A2, typename A3, typename A4> 318 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4> > { 319 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, 320 Matcher<A4> > type; 321 }; 322 323 template <typename A1, typename A2, typename A3, typename A4, typename A5> 324 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5> > { 325 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, 326 Matcher<A5> > type; 327 }; 328 329 template <typename A1, typename A2, typename A3, typename A4, typename A5, 330 typename A6> 331 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > { 332 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, 333 Matcher<A5>, Matcher<A6> > type; 334 }; 335 336 template <typename A1, typename A2, typename A3, typename A4, typename A5, 337 typename A6, typename A7> 338 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > { 339 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, 340 Matcher<A5>, Matcher<A6>, Matcher<A7> > type; 341 }; 342 343 template <typename A1, typename A2, typename A3, typename A4, typename A5, 344 typename A6, typename A7, typename A8> 345 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > { 346 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, 347 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8> > type; 348 }; 349 350 template <typename A1, typename A2, typename A3, typename A4, typename A5, 351 typename A6, typename A7, typename A8, typename A9> 352 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > { 353 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, 354 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9> > type; 355 }; 356 357 template <typename A1, typename A2, typename A3, typename A4, typename A5, 358 typename A6, typename A7, typename A8, typename A9, typename A10> 359 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, 360 A10> > { 361 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, 362 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9>, 363 Matcher<A10> > type; 364 }; 365 366 // Template struct Function<F>, where F must be a function type, contains 367 // the following typedefs: 368 // 369 // Result: the function's return type. 370 // ArgumentN: the type of the N-th argument, where N starts with 1. 371 // ArgumentTuple: the tuple type consisting of all parameters of F. 372 // ArgumentMatcherTuple: the tuple type consisting of Matchers for all 373 // parameters of F. 374 // MakeResultVoid: the function type obtained by substituting void 375 // for the return type of F. 376 // MakeResultIgnoredValue: 377 // the function type obtained by substituting Something 378 // for the return type of F. 379 template <typename F> 380 struct Function; 381 382 template <typename R> 383 struct Function<R()> { 384 typedef R Result; 385 typedef ::std::tr1::tuple<> ArgumentTuple; 386 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; 387 typedef void MakeResultVoid(); 388 typedef IgnoredValue MakeResultIgnoredValue(); 389 }; 390 391 template <typename R, typename A1> 392 struct Function<R(A1)> 393 : Function<R()> { 394 typedef A1 Argument1; 395 typedef ::std::tr1::tuple<A1> ArgumentTuple; 396 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; 397 typedef void MakeResultVoid(A1); 398 typedef IgnoredValue MakeResultIgnoredValue(A1); 399 }; 400 401 template <typename R, typename A1, typename A2> 402 struct Function<R(A1, A2)> 403 : Function<R(A1)> { 404 typedef A2 Argument2; 405 typedef ::std::tr1::tuple<A1, A2> ArgumentTuple; 406 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; 407 typedef void MakeResultVoid(A1, A2); 408 typedef IgnoredValue MakeResultIgnoredValue(A1, A2); 409 }; 410 411 template <typename R, typename A1, typename A2, typename A3> 412 struct Function<R(A1, A2, A3)> 413 : Function<R(A1, A2)> { 414 typedef A3 Argument3; 415 typedef ::std::tr1::tuple<A1, A2, A3> ArgumentTuple; 416 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; 417 typedef void MakeResultVoid(A1, A2, A3); 418 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3); 419 }; 420 421 template <typename R, typename A1, typename A2, typename A3, typename A4> 422 struct Function<R(A1, A2, A3, A4)> 423 : Function<R(A1, A2, A3)> { 424 typedef A4 Argument4; 425 typedef ::std::tr1::tuple<A1, A2, A3, A4> ArgumentTuple; 426 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; 427 typedef void MakeResultVoid(A1, A2, A3, A4); 428 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4); 429 }; 430 431 template <typename R, typename A1, typename A2, typename A3, typename A4, 432 typename A5> 433 struct Function<R(A1, A2, A3, A4, A5)> 434 : Function<R(A1, A2, A3, A4)> { 435 typedef A5 Argument5; 436 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5> ArgumentTuple; 437 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; 438 typedef void MakeResultVoid(A1, A2, A3, A4, A5); 439 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5); 440 }; 441 442 template <typename R, typename A1, typename A2, typename A3, typename A4, 443 typename A5, typename A6> 444 struct Function<R(A1, A2, A3, A4, A5, A6)> 445 : Function<R(A1, A2, A3, A4, A5)> { 446 typedef A6 Argument6; 447 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> ArgumentTuple; 448 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; 449 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6); 450 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6); 451 }; 452 453 template <typename R, typename A1, typename A2, typename A3, typename A4, 454 typename A5, typename A6, typename A7> 455 struct Function<R(A1, A2, A3, A4, A5, A6, A7)> 456 : Function<R(A1, A2, A3, A4, A5, A6)> { 457 typedef A7 Argument7; 458 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> ArgumentTuple; 459 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; 460 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7); 461 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7); 462 }; 463 464 template <typename R, typename A1, typename A2, typename A3, typename A4, 465 typename A5, typename A6, typename A7, typename A8> 466 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> 467 : Function<R(A1, A2, A3, A4, A5, A6, A7)> { 468 typedef A8 Argument8; 469 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> ArgumentTuple; 470 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; 471 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8); 472 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8); 473 }; 474 475 template <typename R, typename A1, typename A2, typename A3, typename A4, 476 typename A5, typename A6, typename A7, typename A8, typename A9> 477 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> 478 : Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> { 479 typedef A9 Argument9; 480 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> ArgumentTuple; 481 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; 482 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9); 483 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8, 484 A9); 485 }; 486 487 template <typename R, typename A1, typename A2, typename A3, typename A4, 488 typename A5, typename A6, typename A7, typename A8, typename A9, 489 typename A10> 490 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> 491 : Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> { 492 typedef A10 Argument10; 493 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, 494 A10> ArgumentTuple; 495 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; 496 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); 497 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8, 498 A9, A10); 499 }; 500 501 } // namespace internal 502 503 } // namespace testing 504 505 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ 506 507 namespace testing { 508 namespace internal { 509 510 // Converts an identifier name to a space-separated list of lower-case 511 // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is 512 // treated as one word. For example, both "FooBar123" and 513 // "foo_bar_123" are converted to "foo bar 123". 514 GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name); 515 516 // PointeeOf<Pointer>::type is the type of a value pointed to by a 517 // Pointer, which can be either a smart pointer or a raw pointer. The 518 // following default implementation is for the case where Pointer is a 519 // smart pointer. 520 template <typename Pointer> 521 struct PointeeOf { 522 // Smart pointer classes define type element_type as the type of 523 // their pointees. 524 typedef typename Pointer::element_type type; 525 }; 526 // This specialization is for the raw pointer case. 527 template <typename T> 528 struct PointeeOf<T*> { typedef T type; }; // NOLINT 529 530 // GetRawPointer(p) returns the raw pointer underlying p when p is a 531 // smart pointer, or returns p itself when p is already a raw pointer. 532 // The following default implementation is for the smart pointer case. 533 template <typename Pointer> 534 inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) { 535 return p.get(); 536 } 537 // This overloaded version is for the raw pointer case. 538 template <typename Element> 539 inline Element* GetRawPointer(Element* p) { return p; } 540 541 // This comparator allows linked_ptr to be stored in sets. 542 template <typename T> 543 struct LinkedPtrLessThan { 544 bool operator()(const ::testing::internal::linked_ptr<T>& lhs, 545 const ::testing::internal::linked_ptr<T>& rhs) const { 546 return lhs.get() < rhs.get(); 547 } 548 }; 549 550 // Symbian compilation can be done with wchar_t being either a native 551 // type or a typedef. Using Google Mock with OpenC without wchar_t 552 // should require the definition of _STLP_NO_WCHAR_T. 553 // 554 // MSVC treats wchar_t as a native type usually, but treats it as the 555 // same as unsigned short when the compiler option /Zc:wchar_t- is 556 // specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t 557 // is a native type. 558 #if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \ 559 (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)) 560 // wchar_t is a typedef. 561 #else 562 # define GMOCK_WCHAR_T_IS_NATIVE_ 1 563 #endif 564 565 // signed wchar_t and unsigned wchar_t are NOT in the C++ standard. 566 // Using them is a bad practice and not portable. So DON'T use them. 567 // 568 // Still, Google Mock is designed to work even if the user uses signed 569 // wchar_t or unsigned wchar_t (obviously, assuming the compiler 570 // supports them). 571 // 572 // To gcc, 573 // wchar_t == signed wchar_t != unsigned wchar_t == unsigned int 574 #ifdef __GNUC__ 575 // signed/unsigned wchar_t are valid types. 576 # define GMOCK_HAS_SIGNED_WCHAR_T_ 1 577 #endif 578 579 // In what follows, we use the term "kind" to indicate whether a type 580 // is bool, an integer type (excluding bool), a floating-point type, 581 // or none of them. This categorization is useful for determining 582 // when a matcher argument type can be safely converted to another 583 // type in the implementation of SafeMatcherCast. 584 enum TypeKind { 585 kBool, kInteger, kFloatingPoint, kOther 586 }; 587 588 // KindOf<T>::value is the kind of type T. 589 template <typename T> struct KindOf { 590 enum { value = kOther }; // The default kind. 591 }; 592 593 // This macro declares that the kind of 'type' is 'kind'. 594 #define GMOCK_DECLARE_KIND_(type, kind) \ 595 template <> struct KindOf<type> { enum { value = kind }; } 596 597 GMOCK_DECLARE_KIND_(bool, kBool); 598 599 // All standard integer types. 600 GMOCK_DECLARE_KIND_(char, kInteger); 601 GMOCK_DECLARE_KIND_(signed char, kInteger); 602 GMOCK_DECLARE_KIND_(unsigned char, kInteger); 603 GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT 604 GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT 605 GMOCK_DECLARE_KIND_(int, kInteger); 606 GMOCK_DECLARE_KIND_(unsigned int, kInteger); 607 GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT 608 GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT 609 610 #if GMOCK_WCHAR_T_IS_NATIVE_ 611 GMOCK_DECLARE_KIND_(wchar_t, kInteger); 612 #endif 613 614 // Non-standard integer types. 615 GMOCK_DECLARE_KIND_(Int64, kInteger); 616 GMOCK_DECLARE_KIND_(UInt64, kInteger); 617 618 // All standard floating-point types. 619 GMOCK_DECLARE_KIND_(float, kFloatingPoint); 620 GMOCK_DECLARE_KIND_(double, kFloatingPoint); 621 GMOCK_DECLARE_KIND_(long double, kFloatingPoint); 622 623 #undef GMOCK_DECLARE_KIND_ 624 625 // Evaluates to the kind of 'type'. 626 #define GMOCK_KIND_OF_(type) \ 627 static_cast< ::testing::internal::TypeKind>( \ 628 ::testing::internal::KindOf<type>::value) 629 630 // Evaluates to true iff integer type T is signed. 631 #define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0) 632 633 // LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value 634 // is true iff arithmetic type From can be losslessly converted to 635 // arithmetic type To. 636 // 637 // It's the user's responsibility to ensure that both From and To are 638 // raw (i.e. has no CV modifier, is not a pointer, and is not a 639 // reference) built-in arithmetic types, kFromKind is the kind of 640 // From, and kToKind is the kind of To; the value is 641 // implementation-defined when the above pre-condition is violated. 642 template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To> 643 struct LosslessArithmeticConvertibleImpl : public false_type {}; 644 645 // Converting bool to bool is lossless. 646 template <> 647 struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool> 648 : public true_type {}; // NOLINT 649 650 // Converting bool to any integer type is lossless. 651 template <typename To> 652 struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To> 653 : public true_type {}; // NOLINT 654 655 // Converting bool to any floating-point type is lossless. 656 template <typename To> 657 struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To> 658 : public true_type {}; // NOLINT 659 660 // Converting an integer to bool is lossy. 661 template <typename From> 662 struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool> 663 : public false_type {}; // NOLINT 664 665 // Converting an integer to another non-bool integer is lossless iff 666 // the target type's range encloses the source type's range. 667 template <typename From, typename To> 668 struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To> 669 : public bool_constant< 670 // When converting from a smaller size to a larger size, we are 671 // fine as long as we are not converting from signed to unsigned. 672 ((sizeof(From) < sizeof(To)) && 673 (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) || 674 // When converting between the same size, the signedness must match. 675 ((sizeof(From) == sizeof(To)) && 676 (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT 677 678 #undef GMOCK_IS_SIGNED_ 679 680 // Converting an integer to a floating-point type may be lossy, since 681 // the format of a floating-point number is implementation-defined. 682 template <typename From, typename To> 683 struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To> 684 : public false_type {}; // NOLINT 685 686 // Converting a floating-point to bool is lossy. 687 template <typename From> 688 struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool> 689 : public false_type {}; // NOLINT 690 691 // Converting a floating-point to an integer is lossy. 692 template <typename From, typename To> 693 struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To> 694 : public false_type {}; // NOLINT 695 696 // Converting a floating-point to another floating-point is lossless 697 // iff the target type is at least as big as the source type. 698 template <typename From, typename To> 699 struct LosslessArithmeticConvertibleImpl< 700 kFloatingPoint, From, kFloatingPoint, To> 701 : public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT 702 703 // LosslessArithmeticConvertible<From, To>::value is true iff arithmetic 704 // type From can be losslessly converted to arithmetic type To. 705 // 706 // It's the user's responsibility to ensure that both From and To are 707 // raw (i.e. has no CV modifier, is not a pointer, and is not a 708 // reference) built-in arithmetic types; the value is 709 // implementation-defined when the above pre-condition is violated. 710 template <typename From, typename To> 711 struct LosslessArithmeticConvertible 712 : public LosslessArithmeticConvertibleImpl< 713 GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT 714 715 // This interface knows how to report a Google Mock failure (either 716 // non-fatal or fatal). 717 class FailureReporterInterface { 718 public: 719 // The type of a failure (either non-fatal or fatal). 720 enum FailureType { 721 kNonfatal, kFatal 722 }; 723 724 virtual ~FailureReporterInterface() {} 725 726 // Reports a failure that occurred at the given source file location. 727 virtual void ReportFailure(FailureType type, const char* file, int line, 728 const string& message) = 0; 729 }; 730 731 // Returns the failure reporter used by Google Mock. 732 GTEST_API_ FailureReporterInterface* GetFailureReporter(); 733 734 // Asserts that condition is true; aborts the process with the given 735 // message if condition is false. We cannot use LOG(FATAL) or CHECK() 736 // as Google Mock might be used to mock the log sink itself. We 737 // inline this function to prevent it from showing up in the stack 738 // trace. 739 inline void Assert(bool condition, const char* file, int line, 740 const string& msg) { 741 if (!condition) { 742 GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal, 743 file, line, msg); 744 } 745 } 746 inline void Assert(bool condition, const char* file, int line) { 747 Assert(condition, file, line, "Assertion failed."); 748 } 749 750 // Verifies that condition is true; generates a non-fatal failure if 751 // condition is false. 752 inline void Expect(bool condition, const char* file, int line, 753 const string& msg) { 754 if (!condition) { 755 GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal, 756 file, line, msg); 757 } 758 } 759 inline void Expect(bool condition, const char* file, int line) { 760 Expect(condition, file, line, "Expectation failed."); 761 } 762 763 // Severity level of a log. 764 enum LogSeverity { 765 kInfo = 0, 766 kWarning = 1 767 }; 768 769 // Valid values for the --gmock_verbose flag. 770 771 // All logs (informational and warnings) are printed. 772 const char kInfoVerbosity[] = "info"; 773 // Only warnings are printed. 774 const char kWarningVerbosity[] = "warning"; 775 // No logs are printed. 776 const char kErrorVerbosity[] = "error"; 777 778 // Returns true iff a log with the given severity is visible according 779 // to the --gmock_verbose flag. 780 GTEST_API_ bool LogIsVisible(LogSeverity severity); 781 782 // Prints the given message to stdout iff 'severity' >= the level 783 // specified by the --gmock_verbose flag. If stack_frames_to_skip >= 784 // 0, also prints the stack trace excluding the top 785 // stack_frames_to_skip frames. In opt mode, any positive 786 // stack_frames_to_skip is treated as 0, since we don't know which 787 // function calls will be inlined by the compiler and need to be 788 // conservative. 789 GTEST_API_ void Log(LogSeverity severity, 790 const string& message, 791 int stack_frames_to_skip); 792 793 // TODO(wan@google.com): group all type utilities together. 794 795 // Type traits. 796 797 // is_reference<T>::value is non-zero iff T is a reference type. 798 template <typename T> struct is_reference : public false_type {}; 799 template <typename T> struct is_reference<T&> : public true_type {}; 800 801 // type_equals<T1, T2>::value is non-zero iff T1 and T2 are the same type. 802 template <typename T1, typename T2> struct type_equals : public false_type {}; 803 template <typename T> struct type_equals<T, T> : public true_type {}; 804 805 // remove_reference<T>::type removes the reference from type T, if any. 806 template <typename T> struct remove_reference { typedef T type; }; // NOLINT 807 template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT 808 809 // DecayArray<T>::type turns an array type U[N] to const U* and preserves 810 // other types. Useful for saving a copy of a function argument. 811 template <typename T> struct DecayArray { typedef T type; }; // NOLINT 812 template <typename T, size_t N> struct DecayArray<T[N]> { 813 typedef const T* type; 814 }; 815 // Sometimes people use arrays whose size is not available at the use site 816 // (e.g. extern const char kNamePrefix[]). This specialization covers that 817 // case. 818 template <typename T> struct DecayArray<T[]> { 819 typedef const T* type; 820 }; 821 822 // Invalid<T>() returns an invalid value of type T. This is useful 823 // when a value of type T is needed for compilation, but the statement 824 // will not really be executed (or we don't care if the statement 825 // crashes). 826 template <typename T> 827 inline T Invalid() { 828 return const_cast<typename remove_reference<T>::type&>( 829 *static_cast<volatile typename remove_reference<T>::type*>(NULL)); 830 } 831 template <> 832 inline void Invalid<void>() {} 833 834 // Given a raw type (i.e. having no top-level reference or const 835 // modifier) RawContainer that's either an STL-style container or a 836 // native array, class StlContainerView<RawContainer> has the 837 // following members: 838 // 839 // - type is a type that provides an STL-style container view to 840 // (i.e. implements the STL container concept for) RawContainer; 841 // - const_reference is a type that provides a reference to a const 842 // RawContainer; 843 // - ConstReference(raw_container) returns a const reference to an STL-style 844 // container view to raw_container, which is a RawContainer. 845 // - Copy(raw_container) returns an STL-style container view of a 846 // copy of raw_container, which is a RawContainer. 847 // 848 // This generic version is used when RawContainer itself is already an 849 // STL-style container. 850 template <class RawContainer> 851 class StlContainerView { 852 public: 853 typedef RawContainer type; 854 typedef const type& const_reference; 855 856 static const_reference ConstReference(const RawContainer& container) { 857 // Ensures that RawContainer is not a const type. 858 testing::StaticAssertTypeEq<RawContainer, 859 GTEST_REMOVE_CONST_(RawContainer)>(); 860 return container; 861 } 862 static type Copy(const RawContainer& container) { return container; } 863 }; 864 865 // This specialization is used when RawContainer is a native array type. 866 template <typename Element, size_t N> 867 class StlContainerView<Element[N]> { 868 public: 869 typedef GTEST_REMOVE_CONST_(Element) RawElement; 870 typedef internal::NativeArray<RawElement> type; 871 // NativeArray<T> can represent a native array either by value or by 872 // reference (selected by a constructor argument), so 'const type' 873 // can be used to reference a const native array. We cannot 874 // 'typedef const type& const_reference' here, as that would mean 875 // ConstReference() has to return a reference to a local variable. 876 typedef const type const_reference; 877 878 static const_reference ConstReference(const Element (&array)[N]) { 879 // Ensures that Element is not a const type. 880 testing::StaticAssertTypeEq<Element, RawElement>(); 881 #if GTEST_OS_SYMBIAN 882 // The Nokia Symbian compiler confuses itself in template instantiation 883 // for this call without the cast to Element*: 884 // function call '[testing::internal::NativeArray<char *>].NativeArray( 885 // {lval} const char *[4], long, testing::internal::RelationToSource)' 886 // does not match 887 // 'testing::internal::NativeArray<char *>::NativeArray( 888 // char *const *, unsigned int, testing::internal::RelationToSource)' 889 // (instantiating: 'testing::internal::ContainsMatcherImpl 890 // <const char * (&)[4]>::Matches(const char * (&)[4]) const') 891 // (instantiating: 'testing::internal::StlContainerView<char *[4]>:: 892 // ConstReference(const char * (&)[4])') 893 // (and though the N parameter type is mismatched in the above explicit 894 // conversion of it doesn't help - only the conversion of the array). 895 return type(const_cast<Element*>(&array[0]), N, kReference); 896 #else 897 return type(array, N, kReference); 898 #endif // GTEST_OS_SYMBIAN 899 } 900 static type Copy(const Element (&array)[N]) { 901 #if GTEST_OS_SYMBIAN 902 return type(const_cast<Element*>(&array[0]), N, kCopy); 903 #else 904 return type(array, N, kCopy); 905 #endif // GTEST_OS_SYMBIAN 906 } 907 }; 908 909 // This specialization is used when RawContainer is a native array 910 // represented as a (pointer, size) tuple. 911 template <typename ElementPointer, typename Size> 912 class StlContainerView< ::std::tr1::tuple<ElementPointer, Size> > { 913 public: 914 typedef GTEST_REMOVE_CONST_( 915 typename internal::PointeeOf<ElementPointer>::type) RawElement; 916 typedef internal::NativeArray<RawElement> type; 917 typedef const type const_reference; 918 919 static const_reference ConstReference( 920 const ::std::tr1::tuple<ElementPointer, Size>& array) { 921 using ::std::tr1::get; 922 return type(get<0>(array), get<1>(array), kReference); 923 } 924 static type Copy(const ::std::tr1::tuple<ElementPointer, Size>& array) { 925 using ::std::tr1::get; 926 return type(get<0>(array), get<1>(array), kCopy); 927 } 928 }; 929 930 // The following specialization prevents the user from instantiating 931 // StlContainer with a reference type. 932 template <typename T> class StlContainerView<T&>; 933 934 // A type transform to remove constness from the first part of a pair. 935 // Pairs like that are used as the value_type of associative containers, 936 // and this transform produces a similar but assignable pair. 937 template <typename T> 938 struct RemoveConstFromKey { 939 typedef T type; 940 }; 941 942 // Partially specialized to remove constness from std::pair<const K, V>. 943 template <typename K, typename V> 944 struct RemoveConstFromKey<std::pair<const K, V> > { 945 typedef std::pair<K, V> type; 946 }; 947 948 // Mapping from booleans to types. Similar to boost::bool_<kValue> and 949 // std::integral_constant<bool, kValue>. 950 template <bool kValue> 951 struct BooleanConstant {}; 952 953 } // namespace internal 954 } // namespace testing 955 956 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ 957 958 namespace testing { 959 960 // To implement an action Foo, define: 961 // 1. a class FooAction that implements the ActionInterface interface, and 962 // 2. a factory function that creates an Action object from a 963 // const FooAction*. 964 // 965 // The two-level delegation design follows that of Matcher, providing 966 // consistency for extension developers. It also eases ownership 967 // management as Action objects can now be copied like plain values. 968 969 namespace internal { 970 971 template <typename F1, typename F2> 972 class ActionAdaptor; 973 974 // BuiltInDefaultValue<T>::Get() returns the "built-in" default 975 // value for type T, which is NULL when T is a pointer type, 0 when T 976 // is a numeric type, false when T is bool, or "" when T is string or 977 // std::string. For any other type T, this value is undefined and the 978 // function will abort the process. 979 template <typename T> 980 class BuiltInDefaultValue { 981 public: 982 // This function returns true iff type T has a built-in default value. 983 static bool Exists() { return false; } 984 static T Get() { 985 Assert(false, __FILE__, __LINE__, 986 "Default action undefined for the function return type."); 987 return internal::Invalid<T>(); 988 // The above statement will never be reached, but is required in 989 // order for this function to compile. 990 } 991 }; 992 993 // This partial specialization says that we use the same built-in 994 // default value for T and const T. 995 template <typename T> 996 class BuiltInDefaultValue<const T> { 997 public: 998 static bool Exists() { return BuiltInDefaultValue<T>::Exists(); } 999 static T Get() { return BuiltInDefaultValue<T>::Get(); } 1000 }; 1001 1002 // This partial specialization defines the default values for pointer 1003 // types. 1004 template <typename T> 1005 class BuiltInDefaultValue<T*> { 1006 public: 1007 static bool Exists() { return true; } 1008 static T* Get() { return NULL; } 1009 }; 1010 1011 // The following specializations define the default values for 1012 // specific types we care about. 1013 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \ 1014 template <> \ 1015 class BuiltInDefaultValue<type> { \ 1016 public: \ 1017 static bool Exists() { return true; } \ 1018 static type Get() { return value; } \ 1019 } 1020 1021 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT 1022 #if GTEST_HAS_GLOBAL_STRING 1023 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, ""); 1024 #endif // GTEST_HAS_GLOBAL_STRING 1025 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, ""); 1026 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false); 1027 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0'); 1028 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0'); 1029 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0'); 1030 1031 // There's no need for a default action for signed wchar_t, as that 1032 // type is the same as wchar_t for gcc, and invalid for MSVC. 1033 // 1034 // There's also no need for a default action for unsigned wchar_t, as 1035 // that type is the same as unsigned int for gcc, and invalid for 1036 // MSVC. 1037 #if GMOCK_WCHAR_T_IS_NATIVE_ 1038 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT 1039 #endif 1040 1041 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT 1042 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT 1043 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U); 1044 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0); 1045 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT 1046 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT 1047 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0); 1048 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0); 1049 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0); 1050 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0); 1051 1052 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_ 1053 1054 } // namespace internal 1055 1056 // When an unexpected function call is encountered, Google Mock will 1057 // let it return a default value if the user has specified one for its 1058 // return type, or if the return type has a built-in default value; 1059 // otherwise Google Mock won't know what value to return and will have 1060 // to abort the process. 1061 // 1062 // The DefaultValue<T> class allows a user to specify the 1063 // default value for a type T that is both copyable and publicly 1064 // destructible (i.e. anything that can be used as a function return 1065 // type). The usage is: 1066 // 1067 // // Sets the default value for type T to be foo. 1068 // DefaultValue<T>::Set(foo); 1069 template <typename T> 1070 class DefaultValue { 1071 public: 1072 // Sets the default value for type T; requires T to be 1073 // copy-constructable and have a public destructor. 1074 static void Set(T x) { 1075 delete value_; 1076 value_ = new T(x); 1077 } 1078 1079 // Unsets the default value for type T. 1080 static void Clear() { 1081 delete value_; 1082 value_ = NULL; 1083 } 1084 1085 // Returns true iff the user has set the default value for type T. 1086 static bool IsSet() { return value_ != NULL; } 1087 1088 // Returns true if T has a default return value set by the user or there 1089 // exists a built-in default value. 1090 static bool Exists() { 1091 return IsSet() || internal::BuiltInDefaultValue<T>::Exists(); 1092 } 1093 1094 // Returns the default value for type T if the user has set one; 1095 // otherwise returns the built-in default value if there is one; 1096 // otherwise aborts the process. 1097 static T Get() { 1098 return value_ == NULL ? 1099 internal::BuiltInDefaultValue<T>::Get() : *value_; 1100 } 1101 1102 private: 1103 static const T* value_; 1104 }; 1105 1106 // This partial specialization allows a user to set default values for 1107 // reference types. 1108 template <typename T> 1109 class DefaultValue<T&> { 1110 public: 1111 // Sets the default value for type T&. 1112 static void Set(T& x) { // NOLINT 1113 address_ = &x; 1114 } 1115 1116 // Unsets the default value for type T&. 1117 static void Clear() { 1118 address_ = NULL; 1119 } 1120 1121 // Returns true iff the user has set the default value for type T&. 1122 static bool IsSet() { return address_ != NULL; } 1123 1124 // Returns true if T has a default return value set by the user or there 1125 // exists a built-in default value. 1126 static bool Exists() { 1127 return IsSet() || internal::BuiltInDefaultValue<T&>::Exists(); 1128 } 1129 1130 // Returns the default value for type T& if the user has set one; 1131 // otherwise returns the built-in default value if there is one; 1132 // otherwise aborts the process. 1133 static T& Get() { 1134 return address_ == NULL ? 1135 internal::BuiltInDefaultValue<T&>::Get() : *address_; 1136 } 1137 1138 private: 1139 static T* address_; 1140 }; 1141 1142 // This specialization allows DefaultValue<void>::Get() to 1143 // compile. 1144 template <> 1145 class DefaultValue<void> { 1146 public: 1147 static bool Exists() { return true; } 1148 static void Get() {} 1149 }; 1150 1151 // Points to the user-set default value for type T. 1152 template <typename T> 1153 const T* DefaultValue<T>::value_ = NULL; 1154 1155 // Points to the user-set default value for type T&. 1156 template <typename T> 1157 T* DefaultValue<T&>::address_ = NULL; 1158 1159 // Implement this interface to define an action for function type F. 1160 template <typename F> 1161 class ActionInterface { 1162 public: 1163 typedef typename internal::Function<F>::Result Result; 1164 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 1165 1166 ActionInterface() {} 1167 virtual ~ActionInterface() {} 1168 1169 // Performs the action. This method is not const, as in general an 1170 // action can have side effects and be stateful. For example, a 1171 // get-the-next-element-from-the-collection action will need to 1172 // remember the current element. 1173 virtual Result Perform(const ArgumentTuple& args) = 0; 1174 1175 private: 1176 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface); 1177 }; 1178 1179 // An Action<F> is a copyable and IMMUTABLE (except by assignment) 1180 // object that represents an action to be taken when a mock function 1181 // of type F is called. The implementation of Action<T> is just a 1182 // linked_ptr to const ActionInterface<T>, so copying is fairly cheap. 1183 // Don't inherit from Action! 1184 // 1185 // You can view an object implementing ActionInterface<F> as a 1186 // concrete action (including its current state), and an Action<F> 1187 // object as a handle to it. 1188 template <typename F> 1189 class Action { 1190 public: 1191 typedef typename internal::Function<F>::Result Result; 1192 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 1193 1194 // Constructs a null Action. Needed for storing Action objects in 1195 // STL containers. 1196 Action() : impl_(NULL) {} 1197 1198 // Constructs an Action from its implementation. A NULL impl is 1199 // used to represent the "do-default" action. 1200 explicit Action(ActionInterface<F>* impl) : impl_(impl) {} 1201 1202 // Copy constructor. 1203 Action(const Action& action) : impl_(action.impl_) {} 1204 1205 // This constructor allows us to turn an Action<Func> object into an 1206 // Action<F>, as long as F's arguments can be implicitly converted 1207 // to Func's and Func's return type can be implicitly converted to 1208 // F's. 1209 template <typename Func> 1210 explicit Action(const Action<Func>& action); 1211 1212 // Returns true iff this is the DoDefault() action. 1213 bool IsDoDefault() const { return impl_.get() == NULL; } 1214 1215 // Performs the action. Note that this method is const even though 1216 // the corresponding method in ActionInterface is not. The reason 1217 // is that a const Action<F> means that it cannot be re-bound to 1218 // another concrete action, not that the concrete action it binds to 1219 // cannot change state. (Think of the difference between a const 1220 // pointer and a pointer to const.) 1221 Result Perform(const ArgumentTuple& args) const { 1222 internal::Assert( 1223 !IsDoDefault(), __FILE__, __LINE__, 1224 "You are using DoDefault() inside a composite action like " 1225 "DoAll() or WithArgs(). This is not supported for technical " 1226 "reasons. Please instead spell out the default action, or " 1227 "assign the default action to an Action variable and use " 1228 "the variable in various places."); 1229 return impl_->Perform(args); 1230 } 1231 1232 private: 1233 template <typename F1, typename F2> 1234 friend class internal::ActionAdaptor; 1235 1236 internal::linked_ptr<ActionInterface<F> > impl_; 1237 }; 1238 1239 // The PolymorphicAction class template makes it easy to implement a 1240 // polymorphic action (i.e. an action that can be used in mock 1241 // functions of than one type, e.g. Return()). 1242 // 1243 // To define a polymorphic action, a user first provides a COPYABLE 1244 // implementation class that has a Perform() method template: 1245 // 1246 // class FooAction { 1247 // public: 1248 // template <typename Result, typename ArgumentTuple> 1249 // Result Perform(const ArgumentTuple& args) const { 1250 // // Processes the arguments and returns a result, using 1251 // // tr1::get<N>(args) to get the N-th (0-based) argument in the tuple. 1252 // } 1253 // ... 1254 // }; 1255 // 1256 // Then the user creates the polymorphic action using 1257 // MakePolymorphicAction(object) where object has type FooAction. See 1258 // the definition of Return(void) and SetArgumentPointee<N>(value) for 1259 // complete examples. 1260 template <typename Impl> 1261 class PolymorphicAction { 1262 public: 1263 explicit PolymorphicAction(const Impl& impl) : impl_(impl) {} 1264 1265 template <typename F> 1266 operator Action<F>() const { 1267 return Action<F>(new MonomorphicImpl<F>(impl_)); 1268 } 1269 1270 private: 1271 template <typename F> 1272 class MonomorphicImpl : public ActionInterface<F> { 1273 public: 1274 typedef typename internal::Function<F>::Result Result; 1275 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 1276 1277 explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} 1278 1279 virtual Result Perform(const ArgumentTuple& args) { 1280 return impl_.template Perform<Result>(args); 1281 } 1282 1283 private: 1284 Impl impl_; 1285 1286 GTEST_DISALLOW_ASSIGN_(MonomorphicImpl); 1287 }; 1288 1289 Impl impl_; 1290 1291 GTEST_DISALLOW_ASSIGN_(PolymorphicAction); 1292 }; 1293 1294 // Creates an Action from its implementation and returns it. The 1295 // created Action object owns the implementation. 1296 template <typename F> 1297 Action<F> MakeAction(ActionInterface<F>* impl) { 1298 return Action<F>(impl); 1299 } 1300 1301 // Creates a polymorphic action from its implementation. This is 1302 // easier to use than the PolymorphicAction<Impl> constructor as it 1303 // doesn't require you to explicitly write the template argument, e.g. 1304 // 1305 // MakePolymorphicAction(foo); 1306 // vs 1307 // PolymorphicAction<TypeOfFoo>(foo); 1308 template <typename Impl> 1309 inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) { 1310 return PolymorphicAction<Impl>(impl); 1311 } 1312 1313 namespace internal { 1314 1315 // Allows an Action<F2> object to pose as an Action<F1>, as long as F2 1316 // and F1 are compatible. 1317 template <typename F1, typename F2> 1318 class ActionAdaptor : public ActionInterface<F1> { 1319 public: 1320 typedef typename internal::Function<F1>::Result Result; 1321 typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple; 1322 1323 explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {} 1324 1325 virtual Result Perform(const ArgumentTuple& args) { 1326 return impl_->Perform(args); 1327 } 1328 1329 private: 1330 const internal::linked_ptr<ActionInterface<F2> > impl_; 1331 1332 GTEST_DISALLOW_ASSIGN_(ActionAdaptor); 1333 }; 1334 1335 // Implements the polymorphic Return(x) action, which can be used in 1336 // any function that returns the type of x, regardless of the argument 1337 // types. 1338 // 1339 // Note: The value passed into Return must be converted into 1340 // Function<F>::Result when this action is cast to Action<F> rather than 1341 // when that action is performed. This is important in scenarios like 1342 // 1343 // MOCK_METHOD1(Method, T(U)); 1344 // ... 1345 // { 1346 // Foo foo; 1347 // X x(&foo); 1348 // EXPECT_CALL(mock, Method(_)).WillOnce(Return(x)); 1349 // } 1350 // 1351 // In the example above the variable x holds reference to foo which leaves 1352 // scope and gets destroyed. If copying X just copies a reference to foo, 1353 // that copy will be left with a hanging reference. If conversion to T 1354 // makes a copy of foo, the above code is safe. To support that scenario, we 1355 // need to make sure that the type conversion happens inside the EXPECT_CALL 1356 // statement, and conversion of the result of Return to Action<T(U)> is a 1357 // good place for that. 1358 // 1359 template <typename R> 1360 class ReturnAction { 1361 public: 1362 // Constructs a ReturnAction object from the value to be returned. 1363 // 'value' is passed by value instead of by const reference in order 1364 // to allow Return("string literal") to compile. 1365 explicit ReturnAction(R value) : value_(value) {} 1366 1367 // This template type conversion operator allows Return(x) to be 1368 // used in ANY function that returns x's type. 1369 template <typename F> 1370 operator Action<F>() const { 1371 // Assert statement belongs here because this is the best place to verify 1372 // conditions on F. It produces the clearest error messages 1373 // in most compilers. 1374 // Impl really belongs in this scope as a local class but can't 1375 // because MSVC produces duplicate symbols in different translation units 1376 // in this case. Until MS fixes that bug we put Impl into the class scope 1377 // and put the typedef both here (for use in assert statement) and 1378 // in the Impl class. But both definitions must be the same. 1379 typedef typename Function<F>::Result Result; 1380 GTEST_COMPILE_ASSERT_( 1381 !internal::is_reference<Result>::value, 1382 use_ReturnRef_instead_of_Return_to_return_a_reference); 1383 return Action<F>(new Impl<F>(value_)); 1384 } 1385 1386 private: 1387 // Implements the Return(x) action for a particular function type F. 1388 template <typename F> 1389 class Impl : public ActionInterface<F> { 1390 public: 1391 typedef typename Function<F>::Result Result; 1392 typedef typename Function<F>::ArgumentTuple ArgumentTuple; 1393 1394 // The implicit cast is necessary when Result has more than one 1395 // single-argument constructor (e.g. Result is std::vector<int>) and R 1396 // has a type conversion operator template. In that case, value_(value) 1397 // won't compile as the compiler doesn't known which constructor of 1398 // Result to call. ImplicitCast_ forces the compiler to convert R to 1399 // Result without considering explicit constructors, thus resolving the 1400 // ambiguity. value_ is then initialized using its copy constructor. 1401 explicit Impl(R value) 1402 : value_(::testing::internal::ImplicitCast_<Result>(value)) {} 1403 1404 virtual Result Perform(const ArgumentTuple&) { return value_; } 1405 1406 private: 1407 GTEST_COMPILE_ASSERT_(!internal::is_reference<Result>::value, 1408 Result_cannot_be_a_reference_type); 1409 Result value_; 1410 1411 GTEST_DISALLOW_ASSIGN_(Impl); 1412 }; 1413 1414 R value_; 1415 1416 GTEST_DISALLOW_ASSIGN_(ReturnAction); 1417 }; 1418 1419 // Implements the ReturnNull() action. 1420 class ReturnNullAction { 1421 public: 1422 // Allows ReturnNull() to be used in any pointer-returning function. 1423 template <typename Result, typename ArgumentTuple> 1424 static Result Perform(const ArgumentTuple&) { 1425 GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value, 1426 ReturnNull_can_be_used_to_return_a_pointer_only); 1427 return NULL; 1428 } 1429 }; 1430 1431 // Implements the Return() action. 1432 class ReturnVoidAction { 1433 public: 1434 // Allows Return() to be used in any void-returning function. 1435 template <typename Result, typename ArgumentTuple> 1436 static void Perform(const ArgumentTuple&) { 1437 CompileAssertTypesEqual<void, Result>(); 1438 } 1439 }; 1440 1441 // Implements the polymorphic ReturnRef(x) action, which can be used 1442 // in any function that returns a reference to the type of x, 1443 // regardless of the argument types. 1444 template <typename T> 1445 class ReturnRefAction { 1446 public: 1447 // Constructs a ReturnRefAction object from the reference to be returned. 1448 explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT 1449 1450 // This template type conversion operator allows ReturnRef(x) to be 1451 // used in ANY function that returns a reference to x's type. 1452 template <typename F> 1453 operator Action<F>() const { 1454 typedef typename Function<F>::Result Result; 1455 // Asserts that the function return type is a reference. This 1456 // catches the user error of using ReturnRef(x) when Return(x) 1457 // should be used, and generates some helpful error message. 1458 GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value, 1459 use_Return_instead_of_ReturnRef_to_return_a_value); 1460 return Action<F>(new Impl<F>(ref_)); 1461 } 1462 1463 private: 1464 // Implements the ReturnRef(x) action for a particular function type F. 1465 template <typename F> 1466 class Impl : public ActionInterface<F> { 1467 public: 1468 typedef typename Function<F>::Result Result; 1469 typedef typename Function<F>::ArgumentTuple ArgumentTuple; 1470 1471 explicit Impl(T& ref) : ref_(ref) {} // NOLINT 1472 1473 virtual Result Perform(const ArgumentTuple&) { 1474 return ref_; 1475 } 1476 1477 private: 1478 T& ref_; 1479 1480 GTEST_DISALLOW_ASSIGN_(Impl); 1481 }; 1482 1483 T& ref_; 1484 1485 GTEST_DISALLOW_ASSIGN_(ReturnRefAction); 1486 }; 1487 1488 // Implements the polymorphic ReturnRefOfCopy(x) action, which can be 1489 // used in any function that returns a reference to the type of x, 1490 // regardless of the argument types. 1491 template <typename T> 1492 class ReturnRefOfCopyAction { 1493 public: 1494 // Constructs a ReturnRefOfCopyAction object from the reference to 1495 // be returned. 1496 explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT 1497 1498 // This template type conversion operator allows ReturnRefOfCopy(x) to be 1499 // used in ANY function that returns a reference to x's type. 1500 template <typename F> 1501 operator Action<F>() const { 1502 typedef typename Function<F>::Result Result; 1503 // Asserts that the function return type is a reference. This 1504 // catches the user error of using ReturnRefOfCopy(x) when Return(x) 1505 // should be used, and generates some helpful error message. 1506 GTEST_COMPILE_ASSERT_( 1507 internal::is_reference<Result>::value, 1508 use_Return_instead_of_ReturnRefOfCopy_to_return_a_value); 1509 return Action<F>(new Impl<F>(value_)); 1510 } 1511 1512 private: 1513 // Implements the ReturnRefOfCopy(x) action for a particular function type F. 1514 template <typename F> 1515 class Impl : public ActionInterface<F> { 1516 public: 1517 typedef typename Function<F>::Result Result; 1518 typedef typename Function<F>::ArgumentTuple ArgumentTuple; 1519 1520 explicit Impl(const T& value) : value_(value) {} // NOLINT 1521 1522 virtual Result Perform(const ArgumentTuple&) { 1523 return value_; 1524 } 1525 1526 private: 1527 T value_; 1528 1529 GTEST_DISALLOW_ASSIGN_(Impl); 1530 }; 1531 1532 const T value_; 1533 1534 GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction); 1535 }; 1536 1537 // Implements the polymorphic DoDefault() action. 1538 class DoDefaultAction { 1539 public: 1540 // This template type conversion operator allows DoDefault() to be 1541 // used in any function. 1542 template <typename F> 1543 operator Action<F>() const { return Action<F>(NULL); } 1544 }; 1545 1546 // Implements the Assign action to set a given pointer referent to a 1547 // particular value. 1548 template <typename T1, typename T2> 1549 class AssignAction { 1550 public: 1551 AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {} 1552 1553 template <typename Result, typename ArgumentTuple> 1554 void Perform(const ArgumentTuple& /* args */) const { 1555 *ptr_ = value_; 1556 } 1557 1558 private: 1559 T1* const ptr_; 1560 const T2 value_; 1561 1562 GTEST_DISALLOW_ASSIGN_(AssignAction); 1563 }; 1564 1565 #if !GTEST_OS_WINDOWS_MOBILE 1566 1567 // Implements the SetErrnoAndReturn action to simulate return from 1568 // various system calls and libc functions. 1569 template <typename T> 1570 class SetErrnoAndReturnAction { 1571 public: 1572 SetErrnoAndReturnAction(int errno_value, T result) 1573 : errno_(errno_value), 1574 result_(result) {} 1575 template <typename Result, typename ArgumentTuple> 1576 Result Perform(const ArgumentTuple& /* args */) const { 1577 errno = errno_; 1578 return result_; 1579 } 1580 1581 private: 1582 const int errno_; 1583 const T result_; 1584 1585 GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction); 1586 }; 1587 1588 #endif // !GTEST_OS_WINDOWS_MOBILE 1589 1590 // Implements the SetArgumentPointee<N>(x) action for any function 1591 // whose N-th argument (0-based) is a pointer to x's type. The 1592 // template parameter kIsProto is true iff type A is ProtocolMessage, 1593 // proto2::Message, or a sub-class of those. 1594 template <size_t N, typename A, bool kIsProto> 1595 class SetArgumentPointeeAction { 1596 public: 1597 // Constructs an action that sets the variable pointed to by the 1598 // N-th function argument to 'value'. 1599 explicit SetArgumentPointeeAction(const A& value) : value_(value) {} 1600 1601 template <typename Result, typename ArgumentTuple> 1602 void Perform(const ArgumentTuple& args) const { 1603 CompileAssertTypesEqual<void, Result>(); 1604 *::std::tr1::get<N>(args) = value_; 1605 } 1606 1607 private: 1608 const A value_; 1609 1610 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction); 1611 }; 1612 1613 template <size_t N, typename Proto> 1614 class SetArgumentPointeeAction<N, Proto, true> { 1615 public: 1616 // Constructs an action that sets the variable pointed to by the 1617 // N-th function argument to 'proto'. Both ProtocolMessage and 1618 // proto2::Message have the CopyFrom() method, so the same 1619 // implementation works for both. 1620 explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) { 1621 proto_->CopyFrom(proto); 1622 } 1623 1624 template <typename Result, typename ArgumentTuple> 1625 void Perform(const ArgumentTuple& args) const { 1626 CompileAssertTypesEqual<void, Result>(); 1627 ::std::tr1::get<N>(args)->CopyFrom(*proto_); 1628 } 1629 1630 private: 1631 const internal::linked_ptr<Proto> proto_; 1632 1633 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction); 1634 }; 1635 1636 // Implements the InvokeWithoutArgs(f) action. The template argument 1637 // FunctionImpl is the implementation type of f, which can be either a 1638 // function pointer or a functor. InvokeWithoutArgs(f) can be used as an 1639 // Action<F> as long as f's type is compatible with F (i.e. f can be 1640 // assigned to a tr1::function<F>). 1641 template <typename FunctionImpl> 1642 class InvokeWithoutArgsAction { 1643 public: 1644 // The c'tor makes a copy of function_impl (either a function 1645 // pointer or a functor). 1646 explicit InvokeWithoutArgsAction(FunctionImpl function_impl) 1647 : function_impl_(function_impl) {} 1648 1649 // Allows InvokeWithoutArgs(f) to be used as any action whose type is 1650 // compatible with f. 1651 template <typename Result, typename ArgumentTuple> 1652 Result Perform(const ArgumentTuple&) { return function_impl_(); } 1653 1654 private: 1655 FunctionImpl function_impl_; 1656 1657 GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction); 1658 }; 1659 1660 // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action. 1661 template <class Class, typename MethodPtr> 1662 class InvokeMethodWithoutArgsAction { 1663 public: 1664 InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr) 1665 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} 1666 1667 template <typename Result, typename ArgumentTuple> 1668 Result Perform(const ArgumentTuple&) const { 1669 return (obj_ptr_->*method_ptr_)(); 1670 } 1671 1672 private: 1673 Class* const obj_ptr_; 1674 const MethodPtr method_ptr_; 1675 1676 GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction); 1677 }; 1678 1679 // Implements the IgnoreResult(action) action. 1680 template <typename A> 1681 class IgnoreResultAction { 1682 public: 1683 explicit IgnoreResultAction(const A& action) : action_(action) {} 1684 1685 template <typename F> 1686 operator Action<F>() const { 1687 // Assert statement belongs here because this is the best place to verify 1688 // conditions on F. It produces the clearest error messages 1689 // in most compilers. 1690 // Impl really belongs in this scope as a local class but can't 1691 // because MSVC produces duplicate symbols in different translation units 1692 // in this case. Until MS fixes that bug we put Impl into the class scope 1693 // and put the typedef both here (for use in assert statement) and 1694 // in the Impl class. But both definitions must be the same. 1695 typedef typename internal::Function<F>::Result Result; 1696 1697 // Asserts at compile time that F returns void. 1698 CompileAssertTypesEqual<void, Result>(); 1699 1700 return Action<F>(new Impl<F>(action_)); 1701 } 1702 1703 private: 1704 template <typename F> 1705 class Impl : public ActionInterface<F> { 1706 public: 1707 typedef typename internal::Function<F>::Result Result; 1708 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 1709 1710 explicit Impl(const A& action) : action_(action) {} 1711 1712 virtual void Perform(const ArgumentTuple& args) { 1713 // Performs the action and ignores its result. 1714 action_.Perform(args); 1715 } 1716 1717 private: 1718 // Type OriginalFunction is the same as F except that its return 1719 // type is IgnoredValue. 1720 typedef typename internal::Function<F>::MakeResultIgnoredValue 1721 OriginalFunction; 1722 1723 const Action<OriginalFunction> action_; 1724 1725 GTEST_DISALLOW_ASSIGN_(Impl); 1726 }; 1727 1728 const A action_; 1729 1730 GTEST_DISALLOW_ASSIGN_(IgnoreResultAction); 1731 }; 1732 1733 // A ReferenceWrapper<T> object represents a reference to type T, 1734 // which can be either const or not. It can be explicitly converted 1735 // from, and implicitly converted to, a T&. Unlike a reference, 1736 // ReferenceWrapper<T> can be copied and can survive template type 1737 // inference. This is used to support by-reference arguments in the 1738 // InvokeArgument<N>(...) action. The idea was from "reference 1739 // wrappers" in tr1, which we don't have in our source tree yet. 1740 template <typename T> 1741 class ReferenceWrapper { 1742 public: 1743 // Constructs a ReferenceWrapper<T> object from a T&. 1744 explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT 1745 1746 // Allows a ReferenceWrapper<T> object to be implicitly converted to 1747 // a T&. 1748 operator T&() const { return *pointer_; } 1749 private: 1750 T* pointer_; 1751 }; 1752 1753 // Allows the expression ByRef(x) to be printed as a reference to x. 1754 template <typename T> 1755 void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) { 1756 T& value = ref; 1757 UniversalPrinter<T&>::Print(value, os); 1758 } 1759 1760 // Does two actions sequentially. Used for implementing the DoAll(a1, 1761 // a2, ...) action. 1762 template <typename Action1, typename Action2> 1763 class DoBothAction { 1764 public: 1765 DoBothAction(Action1 action1, Action2 action2) 1766 : action1_(action1), action2_(action2) {} 1767 1768 // This template type conversion operator allows DoAll(a1, ..., a_n) 1769 // to be used in ANY function of compatible type. 1770 template <typename F> 1771 operator Action<F>() const { 1772 return Action<F>(new Impl<F>(action1_, action2_)); 1773 } 1774 1775 private: 1776 // Implements the DoAll(...) action for a particular function type F. 1777 template <typename F> 1778 class Impl : public ActionInterface<F> { 1779 public: 1780 typedef typename Function<F>::Result Result; 1781 typedef typename Function<F>::ArgumentTuple ArgumentTuple; 1782 typedef typename Function<F>::MakeResultVoid VoidResult; 1783 1784 Impl(const Action<VoidResult>& action1, const Action<F>& action2) 1785 : action1_(action1), action2_(action2) {} 1786 1787 virtual Result Perform(const ArgumentTuple& args) { 1788 action1_.Perform(args); 1789 return action2_.Perform(args); 1790 } 1791 1792 private: 1793 const Action<VoidResult> action1_; 1794 const Action<F> action2_; 1795 1796 GTEST_DISALLOW_ASSIGN_(Impl); 1797 }; 1798 1799 Action1 action1_; 1800 Action2 action2_; 1801 1802 GTEST_DISALLOW_ASSIGN_(DoBothAction); 1803 }; 1804 1805 } // namespace internal 1806 1807 // An Unused object can be implicitly constructed from ANY value. 1808 // This is handy when defining actions that ignore some or all of the 1809 // mock function arguments. For example, given 1810 // 1811 // MOCK_METHOD3(Foo, double(const string& label, double x, double y)); 1812 // MOCK_METHOD3(Bar, double(int index, double x, double y)); 1813 // 1814 // instead of 1815 // 1816 // double DistanceToOriginWithLabel(const string& label, double x, double y) { 1817 // return sqrt(x*x + y*y); 1818 // } 1819 // double DistanceToOriginWithIndex(int index, double x, double y) { 1820 // return sqrt(x*x + y*y); 1821 // } 1822 // ... 1823 // EXEPCT_CALL(mock, Foo("abc", _, _)) 1824 // .WillOnce(Invoke(DistanceToOriginWithLabel)); 1825 // EXEPCT_CALL(mock, Bar(5, _, _)) 1826 // .WillOnce(Invoke(DistanceToOriginWithIndex)); 1827 // 1828 // you could write 1829 // 1830 // // We can declare any uninteresting argument as Unused. 1831 // double DistanceToOrigin(Unused, double x, double y) { 1832 // return sqrt(x*x + y*y); 1833 // } 1834 // ... 1835 // EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin)); 1836 // EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin)); 1837 typedef internal::IgnoredValue Unused; 1838 1839 // This constructor allows us to turn an Action<From> object into an 1840 // Action<To>, as long as To's arguments can be implicitly converted 1841 // to From's and From's return type cann be implicitly converted to 1842 // To's. 1843 template <typename To> 1844 template <typename From> 1845 Action<To>::Action(const Action<From>& from) 1846 : impl_(new internal::ActionAdaptor<To, From>(from)) {} 1847 1848 // Creates an action that returns 'value'. 'value' is passed by value 1849 // instead of const reference - otherwise Return("string literal") 1850 // will trigger a compiler error about using array as initializer. 1851 template <typename R> 1852 internal::ReturnAction<R> Return(R value) { 1853 return internal::ReturnAction<R>(value); 1854 } 1855 1856 // Creates an action that returns NULL. 1857 inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() { 1858 return MakePolymorphicAction(internal::ReturnNullAction()); 1859 } 1860 1861 // Creates an action that returns from a void function. 1862 inline PolymorphicAction<internal::ReturnVoidAction> Return() { 1863 return MakePolymorphicAction(internal::ReturnVoidAction()); 1864 } 1865 1866 // Creates an action that returns the reference to a variable. 1867 template <typename R> 1868 inline internal::ReturnRefAction<R> ReturnRef(R& x) { // NOLINT 1869 return internal::ReturnRefAction<R>(x); 1870 } 1871 1872 // Creates an action that returns the reference to a copy of the 1873 // argument. The copy is created when the action is constructed and 1874 // lives as long as the action. 1875 template <typename R> 1876 inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) { 1877 return internal::ReturnRefOfCopyAction<R>(x); 1878 } 1879 1880 // Creates an action that does the default action for the give mock function. 1881 inline internal::DoDefaultAction DoDefault() { 1882 return internal::DoDefaultAction(); 1883 } 1884 1885 // Creates an action that sets the variable pointed by the N-th 1886 // (0-based) function argument to 'value'. 1887 template <size_t N, typename T> 1888 PolymorphicAction< 1889 internal::SetArgumentPointeeAction< 1890 N, T, internal::IsAProtocolMessage<T>::value> > 1891 SetArgPointee(const T& x) { 1892 return MakePolymorphicAction(internal::SetArgumentPointeeAction< 1893 N, T, internal::IsAProtocolMessage<T>::value>(x)); 1894 } 1895 1896 #if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) 1897 // This overload allows SetArgPointee() to accept a string literal. 1898 // GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish 1899 // this overload from the templated version and emit a compile error. 1900 template <size_t N> 1901 PolymorphicAction< 1902 internal::SetArgumentPointeeAction<N, const char*, false> > 1903 SetArgPointee(const char* p) { 1904 return MakePolymorphicAction(internal::SetArgumentPointeeAction< 1905 N, const char*, false>(p)); 1906 } 1907 1908 template <size_t N> 1909 PolymorphicAction< 1910 internal::SetArgumentPointeeAction<N, const wchar_t*, false> > 1911 SetArgPointee(const wchar_t* p) { 1912 return MakePolymorphicAction(internal::SetArgumentPointeeAction< 1913 N, const wchar_t*, false>(p)); 1914 } 1915 #endif 1916 1917 // The following version is DEPRECATED. 1918 template <size_t N, typename T> 1919 PolymorphicAction< 1920 internal::SetArgumentPointeeAction< 1921 N, T, internal::IsAProtocolMessage<T>::value> > 1922 SetArgumentPointee(const T& x) { 1923 return MakePolymorphicAction(internal::SetArgumentPointeeAction< 1924 N, T, internal::IsAProtocolMessage<T>::value>(x)); 1925 } 1926 1927 // Creates an action that sets a pointer referent to a given value. 1928 template <typename T1, typename T2> 1929 PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) { 1930 return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val)); 1931 } 1932 1933 #if !GTEST_OS_WINDOWS_MOBILE 1934 1935 // Creates an action that sets errno and returns the appropriate error. 1936 template <typename T> 1937 PolymorphicAction<internal::SetErrnoAndReturnAction<T> > 1938 SetErrnoAndReturn(int errval, T result) { 1939 return MakePolymorphicAction( 1940 internal::SetErrnoAndReturnAction<T>(errval, result)); 1941 } 1942 1943 #endif // !GTEST_OS_WINDOWS_MOBILE 1944 1945 // Various overloads for InvokeWithoutArgs(). 1946 1947 // Creates an action that invokes 'function_impl' with no argument. 1948 template <typename FunctionImpl> 1949 PolymorphicAction<internal::InvokeWithoutArgsAction<FunctionImpl> > 1950 InvokeWithoutArgs(FunctionImpl function_impl) { 1951 return MakePolymorphicAction( 1952 internal::InvokeWithoutArgsAction<FunctionImpl>(function_impl)); 1953 } 1954 1955 // Creates an action that invokes the given method on the given object 1956 // with no argument. 1957 template <class Class, typename MethodPtr> 1958 PolymorphicAction<internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> > 1959 InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) { 1960 return MakePolymorphicAction( 1961 internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>( 1962 obj_ptr, method_ptr)); 1963 } 1964 1965 // Creates an action that performs an_action and throws away its 1966 // result. In other words, it changes the return type of an_action to 1967 // void. an_action MUST NOT return void, or the code won't compile. 1968 template <typename A> 1969 inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) { 1970 return internal::IgnoreResultAction<A>(an_action); 1971 } 1972 1973 // Creates a reference wrapper for the given L-value. If necessary, 1974 // you can explicitly specify the type of the reference. For example, 1975 // suppose 'derived' is an object of type Derived, ByRef(derived) 1976 // would wrap a Derived&. If you want to wrap a const Base& instead, 1977 // where Base is a base class of Derived, just write: 1978 // 1979 // ByRef<const Base>(derived) 1980 template <typename T> 1981 inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT 1982 return internal::ReferenceWrapper<T>(l_value); 1983 } 1984 1985 } // namespace testing 1986 1987 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 1988 // Copyright 2007, Google Inc. 1989 // All rights reserved. 1990 // 1991 // Redistribution and use in source and binary forms, with or without 1992 // modification, are permitted provided that the following conditions are 1993 // met: 1994 // 1995 // * Redistributions of source code must retain the above copyright 1996 // notice, this list of conditions and the following disclaimer. 1997 // * Redistributions in binary form must reproduce the above 1998 // copyright notice, this list of conditions and the following disclaimer 1999 // in the documentation and/or other materials provided with the 2000 // distribution. 2001 // * Neither the name of Google Inc. nor the names of its 2002 // contributors may be used to endorse or promote products derived from 2003 // this software without specific prior written permission. 2004 // 2005 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2006 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2007 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2008 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2009 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2010 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2011 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2012 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2013 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2014 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2015 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2016 // 2017 // Author: wan@google.com (Zhanyong Wan) 2018 2019 // Google Mock - a framework for writing C++ mock classes. 2020 // 2021 // This file implements some commonly used cardinalities. More 2022 // cardinalities can be defined by the user implementing the 2023 // CardinalityInterface interface if necessary. 2024 2025 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 2026 #define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 2027 2028 #include <limits.h> 2029 #include <ostream> // NOLINT 2030 2031 namespace testing { 2032 2033 // To implement a cardinality Foo, define: 2034 // 1. a class FooCardinality that implements the 2035 // CardinalityInterface interface, and 2036 // 2. a factory function that creates a Cardinality object from a 2037 // const FooCardinality*. 2038 // 2039 // The two-level delegation design follows that of Matcher, providing 2040 // consistency for extension developers. It also eases ownership 2041 // management as Cardinality objects can now be copied like plain values. 2042 2043 // The implementation of a cardinality. 2044 class CardinalityInterface { 2045 public: 2046 virtual ~CardinalityInterface() {} 2047 2048 // Conservative estimate on the lower/upper bound of the number of 2049 // calls allowed. 2050 virtual int ConservativeLowerBound() const { return 0; } 2051 virtual int ConservativeUpperBound() const { return INT_MAX; } 2052 2053 // Returns true iff call_count calls will satisfy this cardinality. 2054 virtual bool IsSatisfiedByCallCount(int call_count) const = 0; 2055 2056 // Returns true iff call_count calls will saturate this cardinality. 2057 virtual bool IsSaturatedByCallCount(int call_count) const = 0; 2058 2059 // Describes self to an ostream. 2060 virtual void DescribeTo(::std::ostream* os) const = 0; 2061 }; 2062 2063 // A Cardinality is a copyable and IMMUTABLE (except by assignment) 2064 // object that specifies how many times a mock function is expected to 2065 // be called. The implementation of Cardinality is just a linked_ptr 2066 // to const CardinalityInterface, so copying is fairly cheap. 2067 // Don't inherit from Cardinality! 2068 class GTEST_API_ Cardinality { 2069 public: 2070 // Constructs a null cardinality. Needed for storing Cardinality 2071 // objects in STL containers. 2072 Cardinality() {} 2073 2074 // Constructs a Cardinality from its implementation. 2075 explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {} 2076 2077 // Conservative estimate on the lower/upper bound of the number of 2078 // calls allowed. 2079 int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); } 2080 int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); } 2081 2082 // Returns true iff call_count calls will satisfy this cardinality. 2083 bool IsSatisfiedByCallCount(int call_count) const { 2084 return impl_->IsSatisfiedByCallCount(call_count); 2085 } 2086 2087 // Returns true iff call_count calls will saturate this cardinality. 2088 bool IsSaturatedByCallCount(int call_count) const { 2089 return impl_->IsSaturatedByCallCount(call_count); 2090 } 2091 2092 // Returns true iff call_count calls will over-saturate this 2093 // cardinality, i.e. exceed the maximum number of allowed calls. 2094 bool IsOverSaturatedByCallCount(int call_count) const { 2095 return impl_->IsSaturatedByCallCount(call_count) && 2096 !impl_->IsSatisfiedByCallCount(call_count); 2097 } 2098 2099 // Describes self to an ostream 2100 void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } 2101 2102 // Describes the given actual call count to an ostream. 2103 static void DescribeActualCallCountTo(int actual_call_count, 2104 ::std::ostream* os); 2105 2106 private: 2107 internal::linked_ptr<const CardinalityInterface> impl_; 2108 }; 2109 2110 // Creates a cardinality that allows at least n calls. 2111 GTEST_API_ Cardinality AtLeast(int n); 2112 2113 // Creates a cardinality that allows at most n calls. 2114 GTEST_API_ Cardinality AtMost(int n); 2115 2116 // Creates a cardinality that allows any number of calls. 2117 GTEST_API_ Cardinality AnyNumber(); 2118 2119 // Creates a cardinality that allows between min and max calls. 2120 GTEST_API_ Cardinality Between(int min, int max); 2121 2122 // Creates a cardinality that allows exactly n calls. 2123 GTEST_API_ Cardinality Exactly(int n); 2124 2125 // Creates a cardinality from its implementation. 2126 inline Cardinality MakeCardinality(const CardinalityInterface* c) { 2127 return Cardinality(c); 2128 } 2129 2130 } // namespace testing 2131 2132 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 2133 // This file was GENERATED by a script. DO NOT EDIT BY HAND!!! 2134 2135 // Copyright 2007, Google Inc. 2136 // All rights reserved. 2137 // 2138 // Redistribution and use in source and binary forms, with or without 2139 // modification, are permitted provided that the following conditions are 2140 // met: 2141 // 2142 // * Redistributions of source code must retain the above copyright 2143 // notice, this list of conditions and the following disclaimer. 2144 // * Redistributions in binary form must reproduce the above 2145 // copyright notice, this list of conditions and the following disclaimer 2146 // in the documentation and/or other materials provided with the 2147 // distribution. 2148 // * Neither the name of Google Inc. nor the names of its 2149 // contributors may be used to endorse or promote products derived from 2150 // this software without specific prior written permission. 2151 // 2152 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2153 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2154 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2155 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2156 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2157 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2158 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2159 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2160 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2161 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2162 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2163 // 2164 // Author: wan@google.com (Zhanyong Wan) 2165 2166 // Google Mock - a framework for writing C++ mock classes. 2167 // 2168 // This file implements some commonly used variadic actions. 2169 2170 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ 2171 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ 2172 2173 2174 namespace testing { 2175 namespace internal { 2176 2177 // InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary 2178 // function or method with the unpacked values, where F is a function 2179 // type that takes N arguments. 2180 template <typename Result, typename ArgumentTuple> 2181 class InvokeHelper; 2182 2183 template <typename R> 2184 class InvokeHelper<R, ::std::tr1::tuple<> > { 2185 public: 2186 template <typename Function> 2187 static R Invoke(Function function, const ::std::tr1::tuple<>&) { 2188 return function(); 2189 } 2190 2191 template <class Class, typename MethodPtr> 2192 static R InvokeMethod(Class* obj_ptr, 2193 MethodPtr method_ptr, 2194 const ::std::tr1::tuple<>&) { 2195 return (obj_ptr->*method_ptr)(); 2196 } 2197 }; 2198 2199 template <typename R, typename A1> 2200 class InvokeHelper<R, ::std::tr1::tuple<A1> > { 2201 public: 2202 template <typename Function> 2203 static R Invoke(Function function, const ::std::tr1::tuple<A1>& args) { 2204 using ::std::tr1::get; 2205 return function(get<0>(args)); 2206 } 2207 2208 template <class Class, typename MethodPtr> 2209 static R InvokeMethod(Class* obj_ptr, 2210 MethodPtr method_ptr, 2211 const ::std::tr1::tuple<A1>& args) { 2212 using ::std::tr1::get; 2213 return (obj_ptr->*method_ptr)(get<0>(args)); 2214 } 2215 }; 2216 2217 template <typename R, typename A1, typename A2> 2218 class InvokeHelper<R, ::std::tr1::tuple<A1, A2> > { 2219 public: 2220 template <typename Function> 2221 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2>& args) { 2222 using ::std::tr1::get; 2223 return function(get<0>(args), get<1>(args)); 2224 } 2225 2226 template <class Class, typename MethodPtr> 2227 static R InvokeMethod(Class* obj_ptr, 2228 MethodPtr method_ptr, 2229 const ::std::tr1::tuple<A1, A2>& args) { 2230 using ::std::tr1::get; 2231 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args)); 2232 } 2233 }; 2234 2235 template <typename R, typename A1, typename A2, typename A3> 2236 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3> > { 2237 public: 2238 template <typename Function> 2239 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, 2240 A3>& args) { 2241 using ::std::tr1::get; 2242 return function(get<0>(args), get<1>(args), get<2>(args)); 2243 } 2244 2245 template <class Class, typename MethodPtr> 2246 static R InvokeMethod(Class* obj_ptr, 2247 MethodPtr method_ptr, 2248 const ::std::tr1::tuple<A1, A2, A3>& args) { 2249 using ::std::tr1::get; 2250 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args)); 2251 } 2252 }; 2253 2254 template <typename R, typename A1, typename A2, typename A3, typename A4> 2255 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4> > { 2256 public: 2257 template <typename Function> 2258 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, 2259 A4>& args) { 2260 using ::std::tr1::get; 2261 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args)); 2262 } 2263 2264 template <class Class, typename MethodPtr> 2265 static R InvokeMethod(Class* obj_ptr, 2266 MethodPtr method_ptr, 2267 const ::std::tr1::tuple<A1, A2, A3, A4>& args) { 2268 using ::std::tr1::get; 2269 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), 2270 get<3>(args)); 2271 } 2272 }; 2273 2274 template <typename R, typename A1, typename A2, typename A3, typename A4, 2275 typename A5> 2276 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5> > { 2277 public: 2278 template <typename Function> 2279 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, 2280 A5>& args) { 2281 using ::std::tr1::get; 2282 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), 2283 get<4>(args)); 2284 } 2285 2286 template <class Class, typename MethodPtr> 2287 static R InvokeMethod(Class* obj_ptr, 2288 MethodPtr method_ptr, 2289 const ::std::tr1::tuple<A1, A2, A3, A4, A5>& args) { 2290 using ::std::tr1::get; 2291 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), 2292 get<3>(args), get<4>(args)); 2293 } 2294 }; 2295 2296 template <typename R, typename A1, typename A2, typename A3, typename A4, 2297 typename A5, typename A6> 2298 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > { 2299 public: 2300 template <typename Function> 2301 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, 2302 A5, A6>& args) { 2303 using ::std::tr1::get; 2304 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), 2305 get<4>(args), get<5>(args)); 2306 } 2307 2308 template <class Class, typename MethodPtr> 2309 static R InvokeMethod(Class* obj_ptr, 2310 MethodPtr method_ptr, 2311 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6>& args) { 2312 using ::std::tr1::get; 2313 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), 2314 get<3>(args), get<4>(args), get<5>(args)); 2315 } 2316 }; 2317 2318 template <typename R, typename A1, typename A2, typename A3, typename A4, 2319 typename A5, typename A6, typename A7> 2320 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > { 2321 public: 2322 template <typename Function> 2323 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, 2324 A5, A6, A7>& args) { 2325 using ::std::tr1::get; 2326 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), 2327 get<4>(args), get<5>(args), get<6>(args)); 2328 } 2329 2330 template <class Class, typename MethodPtr> 2331 static R InvokeMethod(Class* obj_ptr, 2332 MethodPtr method_ptr, 2333 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, 2334 A7>& args) { 2335 using ::std::tr1::get; 2336 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), 2337 get<3>(args), get<4>(args), get<5>(args), get<6>(args)); 2338 } 2339 }; 2340 2341 template <typename R, typename A1, typename A2, typename A3, typename A4, 2342 typename A5, typename A6, typename A7, typename A8> 2343 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > { 2344 public: 2345 template <typename Function> 2346 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, 2347 A5, A6, A7, A8>& args) { 2348 using ::std::tr1::get; 2349 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), 2350 get<4>(args), get<5>(args), get<6>(args), get<7>(args)); 2351 } 2352 2353 template <class Class, typename MethodPtr> 2354 static R InvokeMethod(Class* obj_ptr, 2355 MethodPtr method_ptr, 2356 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, 2357 A8>& args) { 2358 using ::std::tr1::get; 2359 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), 2360 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args)); 2361 } 2362 }; 2363 2364 template <typename R, typename A1, typename A2, typename A3, typename A4, 2365 typename A5, typename A6, typename A7, typename A8, typename A9> 2366 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > { 2367 public: 2368 template <typename Function> 2369 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, 2370 A5, A6, A7, A8, A9>& args) { 2371 using ::std::tr1::get; 2372 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), 2373 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args)); 2374 } 2375 2376 template <class Class, typename MethodPtr> 2377 static R InvokeMethod(Class* obj_ptr, 2378 MethodPtr method_ptr, 2379 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, 2380 A9>& args) { 2381 using ::std::tr1::get; 2382 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), 2383 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), 2384 get<8>(args)); 2385 } 2386 }; 2387 2388 template <typename R, typename A1, typename A2, typename A3, typename A4, 2389 typename A5, typename A6, typename A7, typename A8, typename A9, 2390 typename A10> 2391 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, 2392 A10> > { 2393 public: 2394 template <typename Function> 2395 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, 2396 A5, A6, A7, A8, A9, A10>& args) { 2397 using ::std::tr1::get; 2398 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), 2399 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), 2400 get<9>(args)); 2401 } 2402 2403 template <class Class, typename MethodPtr> 2404 static R InvokeMethod(Class* obj_ptr, 2405 MethodPtr method_ptr, 2406 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, 2407 A9, A10>& args) { 2408 using ::std::tr1::get; 2409 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), 2410 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), 2411 get<8>(args), get<9>(args)); 2412 } 2413 }; 2414 2415 // CallableHelper has static methods for invoking "callables", 2416 // i.e. function pointers and functors. It uses overloading to 2417 // provide a uniform interface for invoking different kinds of 2418 // callables. In particular, you can use: 2419 // 2420 // CallableHelper<R>::Call(callable, a1, a2, ..., an) 2421 // 2422 // to invoke an n-ary callable, where R is its return type. If an 2423 // argument, say a2, needs to be passed by reference, you should write 2424 // ByRef(a2) instead of a2 in the above expression. 2425 template <typename R> 2426 class CallableHelper { 2427 public: 2428 // Calls a nullary callable. 2429 template <typename Function> 2430 static R Call(Function function) { return function(); } 2431 2432 // Calls a unary callable. 2433 2434 // We deliberately pass a1 by value instead of const reference here 2435 // in case it is a C-string literal. If we had declared the 2436 // parameter as 'const A1& a1' and write Call(function, "Hi"), the 2437 // compiler would've thought A1 is 'char[3]', which causes trouble 2438 // when you need to copy a value of type A1. By declaring the 2439 // parameter as 'A1 a1', the compiler will correctly infer that A1 2440 // is 'const char*' when it sees Call(function, "Hi"). 2441 // 2442 // Since this function is defined inline, the compiler can get rid 2443 // of the copying of the arguments. Therefore the performance won't 2444 // be hurt. 2445 template <typename Function, typename A1> 2446 static R Call(Function function, A1 a1) { return function(a1); } 2447 2448 // Calls a binary callable. 2449 template <typename Function, typename A1, typename A2> 2450 static R Call(Function function, A1 a1, A2 a2) { 2451 return function(a1, a2); 2452 } 2453 2454 // Calls a ternary callable. 2455 template <typename Function, typename A1, typename A2, typename A3> 2456 static R Call(Function function, A1 a1, A2 a2, A3 a3) { 2457 return function(a1, a2, a3); 2458 } 2459 2460 // Calls a 4-ary callable. 2461 template <typename Function, typename A1, typename A2, typename A3, 2462 typename A4> 2463 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4) { 2464 return function(a1, a2, a3, a4); 2465 } 2466 2467 // Calls a 5-ary callable. 2468 template <typename Function, typename A1, typename A2, typename A3, 2469 typename A4, typename A5> 2470 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { 2471 return function(a1, a2, a3, a4, a5); 2472 } 2473 2474 // Calls a 6-ary callable. 2475 template <typename Function, typename A1, typename A2, typename A3, 2476 typename A4, typename A5, typename A6> 2477 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { 2478 return function(a1, a2, a3, a4, a5, a6); 2479 } 2480 2481 // Calls a 7-ary callable. 2482 template <typename Function, typename A1, typename A2, typename A3, 2483 typename A4, typename A5, typename A6, typename A7> 2484 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, 2485 A7 a7) { 2486 return function(a1, a2, a3, a4, a5, a6, a7); 2487 } 2488 2489 // Calls a 8-ary callable. 2490 template <typename Function, typename A1, typename A2, typename A3, 2491 typename A4, typename A5, typename A6, typename A7, typename A8> 2492 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, 2493 A7 a7, A8 a8) { 2494 return function(a1, a2, a3, a4, a5, a6, a7, a8); 2495 } 2496 2497 // Calls a 9-ary callable. 2498 template <typename Function, typename A1, typename A2, typename A3, 2499 typename A4, typename A5, typename A6, typename A7, typename A8, 2500 typename A9> 2501 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, 2502 A7 a7, A8 a8, A9 a9) { 2503 return function(a1, a2, a3, a4, a5, a6, a7, a8, a9); 2504 } 2505 2506 // Calls a 10-ary callable. 2507 template <typename Function, typename A1, typename A2, typename A3, 2508 typename A4, typename A5, typename A6, typename A7, typename A8, 2509 typename A9, typename A10> 2510 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, 2511 A7 a7, A8 a8, A9 a9, A10 a10) { 2512 return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); 2513 } 2514 }; // class CallableHelper 2515 2516 // An INTERNAL macro for extracting the type of a tuple field. It's 2517 // subject to change without notice - DO NOT USE IN USER CODE! 2518 #define GMOCK_FIELD_(Tuple, N) \ 2519 typename ::std::tr1::tuple_element<N, Tuple>::type 2520 2521 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the 2522 // type of an n-ary function whose i-th (1-based) argument type is the 2523 // k{i}-th (0-based) field of ArgumentTuple, which must be a tuple 2524 // type, and whose return type is Result. For example, 2525 // SelectArgs<int, ::std::tr1::tuple<bool, char, double, long>, 0, 3>::type 2526 // is int(bool, long). 2527 // 2528 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args) 2529 // returns the selected fields (k1, k2, ..., k_n) of args as a tuple. 2530 // For example, 2531 // SelectArgs<int, ::std::tr1::tuple<bool, char, double>, 2, 0>::Select( 2532 // ::std::tr1::make_tuple(true, 'a', 2.5)) 2533 // returns ::std::tr1::tuple (2.5, true). 2534 // 2535 // The numbers in list k1, k2, ..., k_n must be >= 0, where n can be 2536 // in the range [0, 10]. Duplicates are allowed and they don't have 2537 // to be in an ascending or descending order. 2538 2539 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, 2540 int k4, int k5, int k6, int k7, int k8, int k9, int k10> 2541 class SelectArgs { 2542 public: 2543 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), 2544 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), 2545 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), 2546 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), 2547 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9), 2548 GMOCK_FIELD_(ArgumentTuple, k10)); 2549 typedef typename Function<type>::ArgumentTuple SelectedArgs; 2550 static SelectedArgs Select(const ArgumentTuple& args) { 2551 using ::std::tr1::get; 2552 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), 2553 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args), 2554 get<k8>(args), get<k9>(args), get<k10>(args)); 2555 } 2556 }; 2557 2558 template <typename Result, typename ArgumentTuple> 2559 class SelectArgs<Result, ArgumentTuple, 2560 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { 2561 public: 2562 typedef Result type(); 2563 typedef typename Function<type>::ArgumentTuple SelectedArgs; 2564 static SelectedArgs Select(const ArgumentTuple& /* args */) { 2565 using ::std::tr1::get; 2566 return SelectedArgs(); 2567 } 2568 }; 2569 2570 template <typename Result, typename ArgumentTuple, int k1> 2571 class SelectArgs<Result, ArgumentTuple, 2572 k1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { 2573 public: 2574 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1)); 2575 typedef typename Function<type>::ArgumentTuple SelectedArgs; 2576 static SelectedArgs Select(const ArgumentTuple& args) { 2577 using ::std::tr1::get; 2578 return SelectedArgs(get<k1>(args)); 2579 } 2580 }; 2581 2582 template <typename Result, typename ArgumentTuple, int k1, int k2> 2583 class SelectArgs<Result, ArgumentTuple, 2584 k1, k2, -1, -1, -1, -1, -1, -1, -1, -1> { 2585 public: 2586 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), 2587 GMOCK_FIELD_(ArgumentTuple, k2)); 2588 typedef typename Function<type>::ArgumentTuple SelectedArgs; 2589 static SelectedArgs Select(const ArgumentTuple& args) { 2590 using ::std::tr1::get; 2591 return SelectedArgs(get<k1>(args), get<k2>(args)); 2592 } 2593 }; 2594 2595 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3> 2596 class SelectArgs<Result, ArgumentTuple, 2597 k1, k2, k3, -1, -1, -1, -1, -1, -1, -1> { 2598 public: 2599 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), 2600 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3)); 2601 typedef typename Function<type>::ArgumentTuple SelectedArgs; 2602 static SelectedArgs Select(const ArgumentTuple& args) { 2603 using ::std::tr1::get; 2604 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args)); 2605 } 2606 }; 2607 2608 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, 2609 int k4> 2610 class SelectArgs<Result, ArgumentTuple, 2611 k1, k2, k3, k4, -1, -1, -1, -1, -1, -1> { 2612 public: 2613 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), 2614 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), 2615 GMOCK_FIELD_(ArgumentTuple, k4)); 2616 typedef typename Function<type>::ArgumentTuple SelectedArgs; 2617 static SelectedArgs Select(const ArgumentTuple& args) { 2618 using ::std::tr1::get; 2619 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), 2620 get<k4>(args)); 2621 } 2622 }; 2623 2624 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, 2625 int k4, int k5> 2626 class SelectArgs<Result, ArgumentTuple, 2627 k1, k2, k3, k4, k5, -1, -1, -1, -1, -1> { 2628 public: 2629 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), 2630 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), 2631 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5)); 2632 typedef typename Function<type>::ArgumentTuple SelectedArgs; 2633 static SelectedArgs Select(const ArgumentTuple& args) { 2634 using ::std::tr1::get; 2635 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), 2636 get<k4>(args), get<k5>(args)); 2637 } 2638 }; 2639 2640 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, 2641 int k4, int k5, int k6> 2642 class SelectArgs<Result, ArgumentTuple, 2643 k1, k2, k3, k4, k5, k6, -1, -1, -1, -1> { 2644 public: 2645 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), 2646 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), 2647 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), 2648 GMOCK_FIELD_(ArgumentTuple, k6)); 2649 typedef typename Function<type>::ArgumentTuple SelectedArgs; 2650 static SelectedArgs Select(const ArgumentTuple& args) { 2651 using ::std::tr1::get; 2652 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), 2653 get<k4>(args), get<k5>(args), get<k6>(args)); 2654 } 2655 }; 2656 2657 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, 2658 int k4, int k5, int k6, int k7> 2659 class SelectArgs<Result, ArgumentTuple, 2660 k1, k2, k3, k4, k5, k6, k7, -1, -1, -1> { 2661 public: 2662 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), 2663 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), 2664 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), 2665 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7)); 2666 typedef typename Function<type>::ArgumentTuple SelectedArgs; 2667 static SelectedArgs Select(const ArgumentTuple& args) { 2668 using ::std::tr1::get; 2669 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), 2670 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args)); 2671 } 2672 }; 2673 2674 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, 2675 int k4, int k5, int k6, int k7, int k8> 2676 class SelectArgs<Result, ArgumentTuple, 2677 k1, k2, k3, k4, k5, k6, k7, k8, -1, -1> { 2678 public: 2679 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), 2680 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), 2681 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), 2682 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), 2683 GMOCK_FIELD_(ArgumentTuple, k8)); 2684 typedef typename Function<type>::ArgumentTuple SelectedArgs; 2685 static SelectedArgs Select(const ArgumentTuple& args) { 2686 using ::std::tr1::get; 2687 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), 2688 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args), 2689 get<k8>(args)); 2690 } 2691 }; 2692 2693 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, 2694 int k4, int k5, int k6, int k7, int k8, int k9> 2695 class SelectArgs<Result, ArgumentTuple, 2696 k1, k2, k3, k4, k5, k6, k7, k8, k9, -1> { 2697 public: 2698 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), 2699 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), 2700 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), 2701 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), 2702 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9)); 2703 typedef typename Function<type>::ArgumentTuple SelectedArgs; 2704 static SelectedArgs Select(const ArgumentTuple& args) { 2705 using ::std::tr1::get; 2706 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), 2707 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args), 2708 get<k8>(args), get<k9>(args)); 2709 } 2710 }; 2711 2712 #undef GMOCK_FIELD_ 2713 2714 // Implements the WithArgs action. 2715 template <typename InnerAction, int k1 = -1, int k2 = -1, int k3 = -1, 2716 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1, 2717 int k9 = -1, int k10 = -1> 2718 class WithArgsAction { 2719 public: 2720 explicit WithArgsAction(const InnerAction& action) : action_(action) {} 2721 2722 template <typename F> 2723 operator Action<F>() const { return MakeAction(new Impl<F>(action_)); } 2724 2725 private: 2726 template <typename F> 2727 class Impl : public ActionInterface<F> { 2728 public: 2729 typedef typename Function<F>::Result Result; 2730 typedef typename Function<F>::ArgumentTuple ArgumentTuple; 2731 2732 explicit Impl(const InnerAction& action) : action_(action) {} 2733 2734 virtual Result Perform(const ArgumentTuple& args) { 2735 return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, k4, 2736 k5, k6, k7, k8, k9, k10>::Select(args)); 2737 } 2738 2739 private: 2740 typedef typename SelectArgs<Result, ArgumentTuple, 2741 k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType; 2742 2743 Action<InnerFunctionType> action_; 2744 }; 2745 2746 const InnerAction action_; 2747 2748 GTEST_DISALLOW_ASSIGN_(WithArgsAction); 2749 }; 2750 2751 // A macro from the ACTION* family (defined later in this file) 2752 // defines an action that can be used in a mock function. Typically, 2753 // these actions only care about a subset of the arguments of the mock 2754 // function. For example, if such an action only uses the second 2755 // argument, it can be used in any mock function that takes >= 2 2756 // arguments where the type of the second argument is compatible. 2757 // 2758 // Therefore, the action implementation must be prepared to take more 2759 // arguments than it needs. The ExcessiveArg type is used to 2760 // represent those excessive arguments. In order to keep the compiler 2761 // error messages tractable, we define it in the testing namespace 2762 // instead of testing::internal. However, this is an INTERNAL TYPE 2763 // and subject to change without notice, so a user MUST NOT USE THIS 2764 // TYPE DIRECTLY. 2765 struct ExcessiveArg {}; 2766 2767 // A helper class needed for implementing the ACTION* macros. 2768 template <typename Result, class Impl> 2769 class ActionHelper { 2770 public: 2771 static Result Perform(Impl* impl, const ::std::tr1::tuple<>& args) { 2772 using ::std::tr1::get; 2773 return impl->template gmock_PerformImpl<>(args, ExcessiveArg(), 2774 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), 2775 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), 2776 ExcessiveArg()); 2777 } 2778 2779 template <typename A0> 2780 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0>& args) { 2781 using ::std::tr1::get; 2782 return impl->template gmock_PerformImpl<A0>(args, get<0>(args), 2783 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), 2784 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), 2785 ExcessiveArg()); 2786 } 2787 2788 template <typename A0, typename A1> 2789 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1>& args) { 2790 using ::std::tr1::get; 2791 return impl->template gmock_PerformImpl<A0, A1>(args, get<0>(args), 2792 get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), 2793 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), 2794 ExcessiveArg()); 2795 } 2796 2797 template <typename A0, typename A1, typename A2> 2798 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2>& args) { 2799 using ::std::tr1::get; 2800 return impl->template gmock_PerformImpl<A0, A1, A2>(args, get<0>(args), 2801 get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(), 2802 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), 2803 ExcessiveArg()); 2804 } 2805 2806 template <typename A0, typename A1, typename A2, typename A3> 2807 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, 2808 A3>& args) { 2809 using ::std::tr1::get; 2810 return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args, get<0>(args), 2811 get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(), 2812 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), 2813 ExcessiveArg()); 2814 } 2815 2816 template <typename A0, typename A1, typename A2, typename A3, typename A4> 2817 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, 2818 A4>& args) { 2819 using ::std::tr1::get; 2820 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args, 2821 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), 2822 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), 2823 ExcessiveArg()); 2824 } 2825 2826 template <typename A0, typename A1, typename A2, typename A3, typename A4, 2827 typename A5> 2828 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, 2829 A5>& args) { 2830 using ::std::tr1::get; 2831 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args, 2832 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), 2833 get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), 2834 ExcessiveArg()); 2835 } 2836 2837 template <typename A0, typename A1, typename A2, typename A3, typename A4, 2838 typename A5, typename A6> 2839 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, 2840 A5, A6>& args) { 2841 using ::std::tr1::get; 2842 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args, 2843 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), 2844 get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(), 2845 ExcessiveArg()); 2846 } 2847 2848 template <typename A0, typename A1, typename A2, typename A3, typename A4, 2849 typename A5, typename A6, typename A7> 2850 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, 2851 A5, A6, A7>& args) { 2852 using ::std::tr1::get; 2853 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, 2854 A7>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), 2855 get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(), 2856 ExcessiveArg()); 2857 } 2858 2859 template <typename A0, typename A1, typename A2, typename A3, typename A4, 2860 typename A5, typename A6, typename A7, typename A8> 2861 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, 2862 A5, A6, A7, A8>& args) { 2863 using ::std::tr1::get; 2864 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, 2865 A8>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), 2866 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), 2867 ExcessiveArg()); 2868 } 2869 2870 template <typename A0, typename A1, typename A2, typename A3, typename A4, 2871 typename A5, typename A6, typename A7, typename A8, typename A9> 2872 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, 2873 A5, A6, A7, A8, A9>& args) { 2874 using ::std::tr1::get; 2875 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8, 2876 A9>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), 2877 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), 2878 get<9>(args)); 2879 } 2880 }; 2881 2882 } // namespace internal 2883 2884 // Various overloads for Invoke(). 2885 2886 // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes 2887 // the selected arguments of the mock function to an_action and 2888 // performs it. It serves as an adaptor between actions with 2889 // different argument lists. C++ doesn't support default arguments for 2890 // function templates, so we have to overload it. 2891 template <int k1, typename InnerAction> 2892 inline internal::WithArgsAction<InnerAction, k1> 2893 WithArgs(const InnerAction& action) { 2894 return internal::WithArgsAction<InnerAction, k1>(action); 2895 } 2896 2897 template <int k1, int k2, typename InnerAction> 2898 inline internal::WithArgsAction<InnerAction, k1, k2> 2899 WithArgs(const InnerAction& action) { 2900 return internal::WithArgsAction<InnerAction, k1, k2>(action); 2901 } 2902 2903 template <int k1, int k2, int k3, typename InnerAction> 2904 inline internal::WithArgsAction<InnerAction, k1, k2, k3> 2905 WithArgs(const InnerAction& action) { 2906 return internal::WithArgsAction<InnerAction, k1, k2, k3>(action); 2907 } 2908 2909 template <int k1, int k2, int k3, int k4, typename InnerAction> 2910 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4> 2911 WithArgs(const InnerAction& action) { 2912 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action); 2913 } 2914 2915 template <int k1, int k2, int k3, int k4, int k5, typename InnerAction> 2916 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5> 2917 WithArgs(const InnerAction& action) { 2918 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action); 2919 } 2920 2921 template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction> 2922 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6> 2923 WithArgs(const InnerAction& action) { 2924 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action); 2925 } 2926 2927 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, 2928 typename InnerAction> 2929 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7> 2930 WithArgs(const InnerAction& action) { 2931 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, 2932 k7>(action); 2933 } 2934 2935 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, 2936 typename InnerAction> 2937 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8> 2938 WithArgs(const InnerAction& action) { 2939 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, 2940 k8>(action); 2941 } 2942 2943 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, 2944 int k9, typename InnerAction> 2945 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9> 2946 WithArgs(const InnerAction& action) { 2947 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, 2948 k9>(action); 2949 } 2950 2951 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, 2952 int k9, int k10, typename InnerAction> 2953 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, 2954 k9, k10> 2955 WithArgs(const InnerAction& action) { 2956 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, 2957 k9, k10>(action); 2958 } 2959 2960 // Creates an action that does actions a1, a2, ..., sequentially in 2961 // each invocation. 2962 template <typename Action1, typename Action2> 2963 inline internal::DoBothAction<Action1, Action2> 2964 DoAll(Action1 a1, Action2 a2) { 2965 return internal::DoBothAction<Action1, Action2>(a1, a2); 2966 } 2967 2968 template <typename Action1, typename Action2, typename Action3> 2969 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, 2970 Action3> > 2971 DoAll(Action1 a1, Action2 a2, Action3 a3) { 2972 return DoAll(a1, DoAll(a2, a3)); 2973 } 2974 2975 template <typename Action1, typename Action2, typename Action3, 2976 typename Action4> 2977 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, 2978 internal::DoBothAction<Action3, Action4> > > 2979 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) { 2980 return DoAll(a1, DoAll(a2, a3, a4)); 2981 } 2982 2983 template <typename Action1, typename Action2, typename Action3, 2984 typename Action4, typename Action5> 2985 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, 2986 internal::DoBothAction<Action3, internal::DoBothAction<Action4, 2987 Action5> > > > 2988 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) { 2989 return DoAll(a1, DoAll(a2, a3, a4, a5)); 2990 } 2991 2992 template <typename Action1, typename Action2, typename Action3, 2993 typename Action4, typename Action5, typename Action6> 2994 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, 2995 internal::DoBothAction<Action3, internal::DoBothAction<Action4, 2996 internal::DoBothAction<Action5, Action6> > > > > 2997 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) { 2998 return DoAll(a1, DoAll(a2, a3, a4, a5, a6)); 2999 } 3000 3001 template <typename Action1, typename Action2, typename Action3, 3002 typename Action4, typename Action5, typename Action6, typename Action7> 3003 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, 3004 internal::DoBothAction<Action3, internal::DoBothAction<Action4, 3005 internal::DoBothAction<Action5, internal::DoBothAction<Action6, 3006 Action7> > > > > > 3007 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 3008 Action7 a7) { 3009 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7)); 3010 } 3011 3012 template <typename Action1, typename Action2, typename Action3, 3013 typename Action4, typename Action5, typename Action6, typename Action7, 3014 typename Action8> 3015 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, 3016 internal::DoBothAction<Action3, internal::DoBothAction<Action4, 3017 internal::DoBothAction<Action5, internal::DoBothAction<Action6, 3018 internal::DoBothAction<Action7, Action8> > > > > > > 3019 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 3020 Action7 a7, Action8 a8) { 3021 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8)); 3022 } 3023 3024 template <typename Action1, typename Action2, typename Action3, 3025 typename Action4, typename Action5, typename Action6, typename Action7, 3026 typename Action8, typename Action9> 3027 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, 3028 internal::DoBothAction<Action3, internal::DoBothAction<Action4, 3029 internal::DoBothAction<Action5, internal::DoBothAction<Action6, 3030 internal::DoBothAction<Action7, internal::DoBothAction<Action8, 3031 Action9> > > > > > > > 3032 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 3033 Action7 a7, Action8 a8, Action9 a9) { 3034 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9)); 3035 } 3036 3037 template <typename Action1, typename Action2, typename Action3, 3038 typename Action4, typename Action5, typename Action6, typename Action7, 3039 typename Action8, typename Action9, typename Action10> 3040 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, 3041 internal::DoBothAction<Action3, internal::DoBothAction<Action4, 3042 internal::DoBothAction<Action5, internal::DoBothAction<Action6, 3043 internal::DoBothAction<Action7, internal::DoBothAction<Action8, 3044 internal::DoBothAction<Action9, Action10> > > > > > > > > 3045 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 3046 Action7 a7, Action8 a8, Action9 a9, Action10 a10) { 3047 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10)); 3048 } 3049 3050 } // namespace testing 3051 3052 // The ACTION* family of macros can be used in a namespace scope to 3053 // define custom actions easily. The syntax: 3054 // 3055 // ACTION(name) { statements; } 3056 // 3057 // will define an action with the given name that executes the 3058 // statements. The value returned by the statements will be used as 3059 // the return value of the action. Inside the statements, you can 3060 // refer to the K-th (0-based) argument of the mock function by 3061 // 'argK', and refer to its type by 'argK_type'. For example: 3062 // 3063 // ACTION(IncrementArg1) { 3064 // arg1_type temp = arg1; 3065 // return ++(*temp); 3066 // } 3067 // 3068 // allows you to write 3069 // 3070 // ...WillOnce(IncrementArg1()); 3071 // 3072 // You can also refer to the entire argument tuple and its type by 3073 // 'args' and 'args_type', and refer to the mock function type and its 3074 // return type by 'function_type' and 'return_type'. 3075 // 3076 // Note that you don't need to specify the types of the mock function 3077 // arguments. However rest assured that your code is still type-safe: 3078 // you'll get a compiler error if *arg1 doesn't support the ++ 3079 // operator, or if the type of ++(*arg1) isn't compatible with the 3080 // mock function's return type, for example. 3081 // 3082 // Sometimes you'll want to parameterize the action. For that you can use 3083 // another macro: 3084 // 3085 // ACTION_P(name, param_name) { statements; } 3086 // 3087 // For example: 3088 // 3089 // ACTION_P(Add, n) { return arg0 + n; } 3090 // 3091 // will allow you to write: 3092 // 3093 // ...WillOnce(Add(5)); 3094 // 3095 // Note that you don't need to provide the type of the parameter 3096 // either. If you need to reference the type of a parameter named 3097 // 'foo', you can write 'foo_type'. For example, in the body of 3098 // ACTION_P(Add, n) above, you can write 'n_type' to refer to the type 3099 // of 'n'. 3100 // 3101 // We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support 3102 // multi-parameter actions. 3103 // 3104 // For the purpose of typing, you can view 3105 // 3106 // ACTION_Pk(Foo, p1, ..., pk) { ... } 3107 // 3108 // as shorthand for 3109 // 3110 // template <typename p1_type, ..., typename pk_type> 3111 // FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... } 3112 // 3113 // In particular, you can provide the template type arguments 3114 // explicitly when invoking Foo(), as in Foo<long, bool>(5, false); 3115 // although usually you can rely on the compiler to infer the types 3116 // for you automatically. You can assign the result of expression 3117 // Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ..., 3118 // pk_type>. This can be useful when composing actions. 3119 // 3120 // You can also overload actions with different numbers of parameters: 3121 // 3122 // ACTION_P(Plus, a) { ... } 3123 // ACTION_P2(Plus, a, b) { ... } 3124 // 3125 // While it's tempting to always use the ACTION* macros when defining 3126 // a new action, you should also consider implementing ActionInterface 3127 // or using MakePolymorphicAction() instead, especially if you need to 3128 // use the action a lot. While these approaches require more work, 3129 // they give you more control on the types of the mock function 3130 // arguments and the action parameters, which in general leads to 3131 // better compiler error messages that pay off in the long run. They 3132 // also allow overloading actions based on parameter types (as opposed 3133 // to just based on the number of parameters). 3134 // 3135 // CAVEAT: 3136 // 3137 // ACTION*() can only be used in a namespace scope. The reason is 3138 // that C++ doesn't yet allow function-local types to be used to 3139 // instantiate templates. The up-coming C++0x standard will fix this. 3140 // Once that's done, we'll consider supporting using ACTION*() inside 3141 // a function. 3142 // 3143 // MORE INFORMATION: 3144 // 3145 // To learn more about using these macros, please search for 'ACTION' 3146 // on http://code.google.com/p/googlemock/wiki/CookBook. 3147 3148 // An internal macro needed for implementing ACTION*(). 3149 #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\ 3150 const args_type& args GTEST_ATTRIBUTE_UNUSED_, \ 3151 arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_, \ 3152 arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_, \ 3153 arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_, \ 3154 arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_, \ 3155 arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_, \ 3156 arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_, \ 3157 arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_, \ 3158 arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_, \ 3159 arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_, \ 3160 arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_ 3161 3162 // Sometimes you want to give an action explicit template parameters 3163 // that cannot be inferred from its value parameters. ACTION() and 3164 // ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that 3165 // and can be viewed as an extension to ACTION() and ACTION_P*(). 3166 // 3167 // The syntax: 3168 // 3169 // ACTION_TEMPLATE(ActionName, 3170 // HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m), 3171 // AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; } 3172 // 3173 // defines an action template that takes m explicit template 3174 // parameters and n value parameters. name_i is the name of the i-th 3175 // template parameter, and kind_i specifies whether it's a typename, 3176 // an integral constant, or a template. p_i is the name of the i-th 3177 // value parameter. 3178 // 3179 // Example: 3180 // 3181 // // DuplicateArg<k, T>(output) converts the k-th argument of the mock 3182 // // function to type T and copies it to *output. 3183 // ACTION_TEMPLATE(DuplicateArg, 3184 // HAS_2_TEMPLATE_PARAMS(int, k, typename, T), 3185 // AND_1_VALUE_PARAMS(output)) { 3186 // *output = T(std::tr1::get<k>(args)); 3187 // } 3188 // ... 3189 // int n; 3190 // EXPECT_CALL(mock, Foo(_, _)) 3191 // .WillOnce(DuplicateArg<1, unsigned char>(&n)); 3192 // 3193 // To create an instance of an action template, write: 3194 // 3195 // ActionName<t1, ..., t_m>(v1, ..., v_n) 3196 // 3197 // where the ts are the template arguments and the vs are the value 3198 // arguments. The value argument types are inferred by the compiler. 3199 // If you want to explicitly specify the value argument types, you can 3200 // provide additional template arguments: 3201 // 3202 // ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n) 3203 // 3204 // where u_i is the desired type of v_i. 3205 // 3206 // ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the 3207 // number of value parameters, but not on the number of template 3208 // parameters. Without the restriction, the meaning of the following 3209 // is unclear: 3210 // 3211 // OverloadedAction<int, bool>(x); 3212 // 3213 // Are we using a single-template-parameter action where 'bool' refers 3214 // to the type of x, or are we using a two-template-parameter action 3215 // where the compiler is asked to infer the type of x? 3216 // 3217 // Implementation notes: 3218 // 3219 // GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and 3220 // GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for 3221 // implementing ACTION_TEMPLATE. The main trick we use is to create 3222 // new macro invocations when expanding a macro. For example, we have 3223 // 3224 // #define ACTION_TEMPLATE(name, template_params, value_params) 3225 // ... GMOCK_INTERNAL_DECL_##template_params ... 3226 // 3227 // which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...) 3228 // to expand to 3229 // 3230 // ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ... 3231 // 3232 // Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the 3233 // preprocessor will continue to expand it to 3234 // 3235 // ... typename T ... 3236 // 3237 // This technique conforms to the C++ standard and is portable. It 3238 // allows us to implement action templates using O(N) code, where N is 3239 // the maximum number of template/value parameters supported. Without 3240 // using it, we'd have to devote O(N^2) amount of code to implement all 3241 // combinations of m and n. 3242 3243 // Declares the template parameters. 3244 #define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0 3245 #define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ 3246 name1) kind0 name0, kind1 name1 3247 #define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3248 kind2, name2) kind0 name0, kind1 name1, kind2 name2 3249 #define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3250 kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \ 3251 kind3 name3 3252 #define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3253 kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \ 3254 kind2 name2, kind3 name3, kind4 name4 3255 #define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3256 kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \ 3257 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5 3258 #define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3259 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ 3260 name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \ 3261 kind5 name5, kind6 name6 3262 #define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3263 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ 3264 kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \ 3265 kind4 name4, kind5 name5, kind6 name6, kind7 name7 3266 #define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3267 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ 3268 kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \ 3269 kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \ 3270 kind8 name8 3271 #define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ 3272 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ 3273 name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \ 3274 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \ 3275 kind6 name6, kind7 name7, kind8 name8, kind9 name9 3276 3277 // Lists the template parameters. 3278 #define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0 3279 #define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ 3280 name1) name0, name1 3281 #define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3282 kind2, name2) name0, name1, name2 3283 #define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3284 kind2, name2, kind3, name3) name0, name1, name2, name3 3285 #define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3286 kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \ 3287 name4 3288 #define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3289 kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \ 3290 name2, name3, name4, name5 3291 #define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3292 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ 3293 name6) name0, name1, name2, name3, name4, name5, name6 3294 #define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3295 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ 3296 kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7 3297 #define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 3298 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ 3299 kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \ 3300 name6, name7, name8 3301 #define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ 3302 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ 3303 name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \ 3304 name3, name4, name5, name6, name7, name8, name9 3305 3306 // Declares the types of value parameters. 3307 #define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS() 3308 #define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type 3309 #define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \ 3310 typename p0##_type, typename p1##_type 3311 #define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \ 3312 typename p0##_type, typename p1##_type, typename p2##_type 3313 #define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ 3314 typename p0##_type, typename p1##_type, typename p2##_type, \ 3315 typename p3##_type 3316 #define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ 3317 typename p0##_type, typename p1##_type, typename p2##_type, \ 3318 typename p3##_type, typename p4##_type 3319 #define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ 3320 typename p0##_type, typename p1##_type, typename p2##_type, \ 3321 typename p3##_type, typename p4##_type, typename p5##_type 3322 #define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 3323 p6) , typename p0##_type, typename p1##_type, typename p2##_type, \ 3324 typename p3##_type, typename p4##_type, typename p5##_type, \ 3325 typename p6##_type 3326 #define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 3327 p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \ 3328 typename p3##_type, typename p4##_type, typename p5##_type, \ 3329 typename p6##_type, typename p7##_type 3330 #define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 3331 p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \ 3332 typename p3##_type, typename p4##_type, typename p5##_type, \ 3333 typename p6##_type, typename p7##_type, typename p8##_type 3334 #define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 3335 p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \ 3336 typename p2##_type, typename p3##_type, typename p4##_type, \ 3337 typename p5##_type, typename p6##_type, typename p7##_type, \ 3338 typename p8##_type, typename p9##_type 3339 3340 // Initializes the value parameters. 3341 #define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\ 3342 () 3343 #define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\ 3344 (p0##_type gmock_p0) : p0(gmock_p0) 3345 #define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\ 3346 (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1) 3347 #define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\ 3348 (p0##_type gmock_p0, p1##_type gmock_p1, \ 3349 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) 3350 #define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\ 3351 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 3352 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 3353 p3(gmock_p3) 3354 #define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\ 3355 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 3356 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \ 3357 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) 3358 #define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\ 3359 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 3360 p3##_type gmock_p3, p4##_type gmock_p4, \ 3361 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 3362 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) 3363 #define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\ 3364 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 3365 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 3366 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 3367 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) 3368 #define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\ 3369 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 3370 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 3371 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), \ 3372 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ 3373 p7(gmock_p7) 3374 #define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3375 p7, p8)\ 3376 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 3377 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 3378 p6##_type gmock_p6, p7##_type gmock_p7, \ 3379 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 3380 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ 3381 p8(gmock_p8) 3382 #define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3383 p7, p8, p9)\ 3384 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 3385 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 3386 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ 3387 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 3388 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ 3389 p8(gmock_p8), p9(gmock_p9) 3390 3391 // Declares the fields for storing the value parameters. 3392 #define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS() 3393 #define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0; 3394 #define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \ 3395 p1##_type p1; 3396 #define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \ 3397 p1##_type p1; p2##_type p2; 3398 #define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \ 3399 p1##_type p1; p2##_type p2; p3##_type p3; 3400 #define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ 3401 p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; 3402 #define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ 3403 p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ 3404 p5##_type p5; 3405 #define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 3406 p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ 3407 p5##_type p5; p6##_type p6; 3408 #define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3409 p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ 3410 p5##_type p5; p6##_type p6; p7##_type p7; 3411 #define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3412 p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ 3413 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; 3414 #define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3415 p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ 3416 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \ 3417 p9##_type p9; 3418 3419 // Lists the value parameters. 3420 #define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS() 3421 #define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0 3422 #define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1 3423 #define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2 3424 #define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3 3425 #define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \ 3426 p2, p3, p4 3427 #define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \ 3428 p1, p2, p3, p4, p5 3429 #define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 3430 p6) p0, p1, p2, p3, p4, p5, p6 3431 #define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3432 p7) p0, p1, p2, p3, p4, p5, p6, p7 3433 #define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3434 p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8 3435 #define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3436 p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 3437 3438 // Lists the value parameter types. 3439 #define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS() 3440 #define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type 3441 #define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \ 3442 p1##_type 3443 #define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \ 3444 p1##_type, p2##_type 3445 #define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ 3446 p0##_type, p1##_type, p2##_type, p3##_type 3447 #define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ 3448 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type 3449 #define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ 3450 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type 3451 #define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 3452 p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \ 3453 p6##_type 3454 #define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 3455 p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 3456 p5##_type, p6##_type, p7##_type 3457 #define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 3458 p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 3459 p5##_type, p6##_type, p7##_type, p8##_type 3460 #define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 3461 p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 3462 p5##_type, p6##_type, p7##_type, p8##_type, p9##_type 3463 3464 // Declares the value parameters. 3465 #define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS() 3466 #define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0 3467 #define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \ 3468 p1##_type p1 3469 #define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \ 3470 p1##_type p1, p2##_type p2 3471 #define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \ 3472 p1##_type p1, p2##_type p2, p3##_type p3 3473 #define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ 3474 p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4 3475 #define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ 3476 p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ 3477 p5##_type p5 3478 #define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 3479 p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ 3480 p5##_type p5, p6##_type p6 3481 #define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3482 p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ 3483 p5##_type p5, p6##_type p6, p7##_type p7 3484 #define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3485 p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ 3486 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8 3487 #define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3488 p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ 3489 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ 3490 p9##_type p9 3491 3492 // The suffix of the class template implementing the action template. 3493 #define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS() 3494 #define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P 3495 #define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2 3496 #define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3 3497 #define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4 3498 #define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5 3499 #define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6 3500 #define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7 3501 #define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3502 p7) P8 3503 #define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3504 p7, p8) P9 3505 #define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 3506 p7, p8, p9) P10 3507 3508 // The name of the class template implementing the action template. 3509 #define GMOCK_ACTION_CLASS_(name, value_params)\ 3510 GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params) 3511 3512 #define ACTION_TEMPLATE(name, template_params, value_params)\ 3513 template <GMOCK_INTERNAL_DECL_##template_params\ 3514 GMOCK_INTERNAL_DECL_TYPE_##value_params>\ 3515 class GMOCK_ACTION_CLASS_(name, value_params) {\ 3516 public:\ 3517 GMOCK_ACTION_CLASS_(name, value_params)\ 3518 GMOCK_INTERNAL_INIT_##value_params {}\ 3519 template <typename F>\ 3520 class gmock_Impl : public ::testing::ActionInterface<F> {\ 3521 public:\ 3522 typedef F function_type;\ 3523 typedef typename ::testing::internal::Function<F>::Result return_type;\ 3524 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 3525 args_type;\ 3526 explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\ 3527 virtual return_type Perform(const args_type& args) {\ 3528 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 3529 Perform(this, args);\ 3530 }\ 3531 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3532 typename arg3_type, typename arg4_type, typename arg5_type, \ 3533 typename arg6_type, typename arg7_type, typename arg8_type, \ 3534 typename arg9_type>\ 3535 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 3536 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 3537 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 3538 arg9_type arg9) const;\ 3539 GMOCK_INTERNAL_DEFN_##value_params\ 3540 private:\ 3541 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 3542 };\ 3543 template <typename F> operator ::testing::Action<F>() const {\ 3544 return ::testing::Action<F>(\ 3545 new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\ 3546 }\ 3547 GMOCK_INTERNAL_DEFN_##value_params\ 3548 private:\ 3549 GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\ 3550 };\ 3551 template <GMOCK_INTERNAL_DECL_##template_params\ 3552 GMOCK_INTERNAL_DECL_TYPE_##value_params>\ 3553 inline GMOCK_ACTION_CLASS_(name, value_params)<\ 3554 GMOCK_INTERNAL_LIST_##template_params\ 3555 GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\ 3556 GMOCK_INTERNAL_DECL_##value_params) {\ 3557 return GMOCK_ACTION_CLASS_(name, value_params)<\ 3558 GMOCK_INTERNAL_LIST_##template_params\ 3559 GMOCK_INTERNAL_LIST_TYPE_##value_params>(\ 3560 GMOCK_INTERNAL_LIST_##value_params);\ 3561 }\ 3562 template <GMOCK_INTERNAL_DECL_##template_params\ 3563 GMOCK_INTERNAL_DECL_TYPE_##value_params>\ 3564 template <typename F>\ 3565 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3566 typename arg3_type, typename arg4_type, typename arg5_type, \ 3567 typename arg6_type, typename arg7_type, typename arg8_type, \ 3568 typename arg9_type>\ 3569 typename ::testing::internal::Function<F>::Result\ 3570 GMOCK_ACTION_CLASS_(name, value_params)<\ 3571 GMOCK_INTERNAL_LIST_##template_params\ 3572 GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\ 3573 gmock_PerformImpl(\ 3574 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 3575 3576 #define ACTION(name)\ 3577 class name##Action {\ 3578 public:\ 3579 name##Action() {}\ 3580 template <typename F>\ 3581 class gmock_Impl : public ::testing::ActionInterface<F> {\ 3582 public:\ 3583 typedef F function_type;\ 3584 typedef typename ::testing::internal::Function<F>::Result return_type;\ 3585 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 3586 args_type;\ 3587 gmock_Impl() {}\ 3588 virtual return_type Perform(const args_type& args) {\ 3589 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 3590 Perform(this, args);\ 3591 }\ 3592 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3593 typename arg3_type, typename arg4_type, typename arg5_type, \ 3594 typename arg6_type, typename arg7_type, typename arg8_type, \ 3595 typename arg9_type>\ 3596 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 3597 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 3598 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 3599 arg9_type arg9) const;\ 3600 private:\ 3601 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 3602 };\ 3603 template <typename F> operator ::testing::Action<F>() const {\ 3604 return ::testing::Action<F>(new gmock_Impl<F>());\ 3605 }\ 3606 private:\ 3607 GTEST_DISALLOW_ASSIGN_(name##Action);\ 3608 };\ 3609 inline name##Action name() {\ 3610 return name##Action();\ 3611 }\ 3612 template <typename F>\ 3613 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3614 typename arg3_type, typename arg4_type, typename arg5_type, \ 3615 typename arg6_type, typename arg7_type, typename arg8_type, \ 3616 typename arg9_type>\ 3617 typename ::testing::internal::Function<F>::Result\ 3618 name##Action::gmock_Impl<F>::gmock_PerformImpl(\ 3619 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 3620 3621 #define ACTION_P(name, p0)\ 3622 template <typename p0##_type>\ 3623 class name##ActionP {\ 3624 public:\ 3625 name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\ 3626 template <typename F>\ 3627 class gmock_Impl : public ::testing::ActionInterface<F> {\ 3628 public:\ 3629 typedef F function_type;\ 3630 typedef typename ::testing::internal::Function<F>::Result return_type;\ 3631 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 3632 args_type;\ 3633 explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\ 3634 virtual return_type Perform(const args_type& args) {\ 3635 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 3636 Perform(this, args);\ 3637 }\ 3638 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3639 typename arg3_type, typename arg4_type, typename arg5_type, \ 3640 typename arg6_type, typename arg7_type, typename arg8_type, \ 3641 typename arg9_type>\ 3642 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 3643 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 3644 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 3645 arg9_type arg9) const;\ 3646 p0##_type p0;\ 3647 private:\ 3648 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 3649 };\ 3650 template <typename F> operator ::testing::Action<F>() const {\ 3651 return ::testing::Action<F>(new gmock_Impl<F>(p0));\ 3652 }\ 3653 p0##_type p0;\ 3654 private:\ 3655 GTEST_DISALLOW_ASSIGN_(name##ActionP);\ 3656 };\ 3657 template <typename p0##_type>\ 3658 inline name##ActionP<p0##_type> name(p0##_type p0) {\ 3659 return name##ActionP<p0##_type>(p0);\ 3660 }\ 3661 template <typename p0##_type>\ 3662 template <typename F>\ 3663 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3664 typename arg3_type, typename arg4_type, typename arg5_type, \ 3665 typename arg6_type, typename arg7_type, typename arg8_type, \ 3666 typename arg9_type>\ 3667 typename ::testing::internal::Function<F>::Result\ 3668 name##ActionP<p0##_type>::gmock_Impl<F>::gmock_PerformImpl(\ 3669 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 3670 3671 #define ACTION_P2(name, p0, p1)\ 3672 template <typename p0##_type, typename p1##_type>\ 3673 class name##ActionP2 {\ 3674 public:\ 3675 name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ 3676 p1(gmock_p1) {}\ 3677 template <typename F>\ 3678 class gmock_Impl : public ::testing::ActionInterface<F> {\ 3679 public:\ 3680 typedef F function_type;\ 3681 typedef typename ::testing::internal::Function<F>::Result return_type;\ 3682 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 3683 args_type;\ 3684 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ 3685 p1(gmock_p1) {}\ 3686 virtual return_type Perform(const args_type& args) {\ 3687 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 3688 Perform(this, args);\ 3689 }\ 3690 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3691 typename arg3_type, typename arg4_type, typename arg5_type, \ 3692 typename arg6_type, typename arg7_type, typename arg8_type, \ 3693 typename arg9_type>\ 3694 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 3695 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 3696 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 3697 arg9_type arg9) const;\ 3698 p0##_type p0;\ 3699 p1##_type p1;\ 3700 private:\ 3701 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 3702 };\ 3703 template <typename F> operator ::testing::Action<F>() const {\ 3704 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\ 3705 }\ 3706 p0##_type p0;\ 3707 p1##_type p1;\ 3708 private:\ 3709 GTEST_DISALLOW_ASSIGN_(name##ActionP2);\ 3710 };\ 3711 template <typename p0##_type, typename p1##_type>\ 3712 inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \ 3713 p1##_type p1) {\ 3714 return name##ActionP2<p0##_type, p1##_type>(p0, p1);\ 3715 }\ 3716 template <typename p0##_type, typename p1##_type>\ 3717 template <typename F>\ 3718 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3719 typename arg3_type, typename arg4_type, typename arg5_type, \ 3720 typename arg6_type, typename arg7_type, typename arg8_type, \ 3721 typename arg9_type>\ 3722 typename ::testing::internal::Function<F>::Result\ 3723 name##ActionP2<p0##_type, p1##_type>::gmock_Impl<F>::gmock_PerformImpl(\ 3724 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 3725 3726 #define ACTION_P3(name, p0, p1, p2)\ 3727 template <typename p0##_type, typename p1##_type, typename p2##_type>\ 3728 class name##ActionP3 {\ 3729 public:\ 3730 name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \ 3731 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ 3732 template <typename F>\ 3733 class gmock_Impl : public ::testing::ActionInterface<F> {\ 3734 public:\ 3735 typedef F function_type;\ 3736 typedef typename ::testing::internal::Function<F>::Result return_type;\ 3737 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 3738 args_type;\ 3739 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \ 3740 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ 3741 virtual return_type Perform(const args_type& args) {\ 3742 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 3743 Perform(this, args);\ 3744 }\ 3745 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3746 typename arg3_type, typename arg4_type, typename arg5_type, \ 3747 typename arg6_type, typename arg7_type, typename arg8_type, \ 3748 typename arg9_type>\ 3749 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 3750 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 3751 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 3752 arg9_type arg9) const;\ 3753 p0##_type p0;\ 3754 p1##_type p1;\ 3755 p2##_type p2;\ 3756 private:\ 3757 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 3758 };\ 3759 template <typename F> operator ::testing::Action<F>() const {\ 3760 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\ 3761 }\ 3762 p0##_type p0;\ 3763 p1##_type p1;\ 3764 p2##_type p2;\ 3765 private:\ 3766 GTEST_DISALLOW_ASSIGN_(name##ActionP3);\ 3767 };\ 3768 template <typename p0##_type, typename p1##_type, typename p2##_type>\ 3769 inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \ 3770 p1##_type p1, p2##_type p2) {\ 3771 return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\ 3772 }\ 3773 template <typename p0##_type, typename p1##_type, typename p2##_type>\ 3774 template <typename F>\ 3775 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3776 typename arg3_type, typename arg4_type, typename arg5_type, \ 3777 typename arg6_type, typename arg7_type, typename arg8_type, \ 3778 typename arg9_type>\ 3779 typename ::testing::internal::Function<F>::Result\ 3780 name##ActionP3<p0##_type, p1##_type, \ 3781 p2##_type>::gmock_Impl<F>::gmock_PerformImpl(\ 3782 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 3783 3784 #define ACTION_P4(name, p0, p1, p2, p3)\ 3785 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 3786 typename p3##_type>\ 3787 class name##ActionP4 {\ 3788 public:\ 3789 name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \ 3790 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ 3791 p2(gmock_p2), p3(gmock_p3) {}\ 3792 template <typename F>\ 3793 class gmock_Impl : public ::testing::ActionInterface<F> {\ 3794 public:\ 3795 typedef F function_type;\ 3796 typedef typename ::testing::internal::Function<F>::Result return_type;\ 3797 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 3798 args_type;\ 3799 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 3800 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 3801 p3(gmock_p3) {}\ 3802 virtual return_type Perform(const args_type& args) {\ 3803 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 3804 Perform(this, args);\ 3805 }\ 3806 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3807 typename arg3_type, typename arg4_type, typename arg5_type, \ 3808 typename arg6_type, typename arg7_type, typename arg8_type, \ 3809 typename arg9_type>\ 3810 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 3811 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 3812 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 3813 arg9_type arg9) const;\ 3814 p0##_type p0;\ 3815 p1##_type p1;\ 3816 p2##_type p2;\ 3817 p3##_type p3;\ 3818 private:\ 3819 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 3820 };\ 3821 template <typename F> operator ::testing::Action<F>() const {\ 3822 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\ 3823 }\ 3824 p0##_type p0;\ 3825 p1##_type p1;\ 3826 p2##_type p2;\ 3827 p3##_type p3;\ 3828 private:\ 3829 GTEST_DISALLOW_ASSIGN_(name##ActionP4);\ 3830 };\ 3831 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 3832 typename p3##_type>\ 3833 inline name##ActionP4<p0##_type, p1##_type, p2##_type, \ 3834 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ 3835 p3##_type p3) {\ 3836 return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \ 3837 p2, p3);\ 3838 }\ 3839 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 3840 typename p3##_type>\ 3841 template <typename F>\ 3842 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3843 typename arg3_type, typename arg4_type, typename arg5_type, \ 3844 typename arg6_type, typename arg7_type, typename arg8_type, \ 3845 typename arg9_type>\ 3846 typename ::testing::internal::Function<F>::Result\ 3847 name##ActionP4<p0##_type, p1##_type, p2##_type, \ 3848 p3##_type>::gmock_Impl<F>::gmock_PerformImpl(\ 3849 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 3850 3851 #define ACTION_P5(name, p0, p1, p2, p3, p4)\ 3852 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 3853 typename p3##_type, typename p4##_type>\ 3854 class name##ActionP5 {\ 3855 public:\ 3856 name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \ 3857 p2##_type gmock_p2, p3##_type gmock_p3, \ 3858 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 3859 p3(gmock_p3), p4(gmock_p4) {}\ 3860 template <typename F>\ 3861 class gmock_Impl : public ::testing::ActionInterface<F> {\ 3862 public:\ 3863 typedef F function_type;\ 3864 typedef typename ::testing::internal::Function<F>::Result return_type;\ 3865 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 3866 args_type;\ 3867 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 3868 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \ 3869 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\ 3870 virtual return_type Perform(const args_type& args) {\ 3871 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 3872 Perform(this, args);\ 3873 }\ 3874 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3875 typename arg3_type, typename arg4_type, typename arg5_type, \ 3876 typename arg6_type, typename arg7_type, typename arg8_type, \ 3877 typename arg9_type>\ 3878 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 3879 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 3880 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 3881 arg9_type arg9) const;\ 3882 p0##_type p0;\ 3883 p1##_type p1;\ 3884 p2##_type p2;\ 3885 p3##_type p3;\ 3886 p4##_type p4;\ 3887 private:\ 3888 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 3889 };\ 3890 template <typename F> operator ::testing::Action<F>() const {\ 3891 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\ 3892 }\ 3893 p0##_type p0;\ 3894 p1##_type p1;\ 3895 p2##_type p2;\ 3896 p3##_type p3;\ 3897 p4##_type p4;\ 3898 private:\ 3899 GTEST_DISALLOW_ASSIGN_(name##ActionP5);\ 3900 };\ 3901 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 3902 typename p3##_type, typename p4##_type>\ 3903 inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \ 3904 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ 3905 p4##_type p4) {\ 3906 return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \ 3907 p4##_type>(p0, p1, p2, p3, p4);\ 3908 }\ 3909 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 3910 typename p3##_type, typename p4##_type>\ 3911 template <typename F>\ 3912 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3913 typename arg3_type, typename arg4_type, typename arg5_type, \ 3914 typename arg6_type, typename arg7_type, typename arg8_type, \ 3915 typename arg9_type>\ 3916 typename ::testing::internal::Function<F>::Result\ 3917 name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \ 3918 p4##_type>::gmock_Impl<F>::gmock_PerformImpl(\ 3919 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 3920 3921 #define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\ 3922 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 3923 typename p3##_type, typename p4##_type, typename p5##_type>\ 3924 class name##ActionP6 {\ 3925 public:\ 3926 name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \ 3927 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ 3928 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 3929 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ 3930 template <typename F>\ 3931 class gmock_Impl : public ::testing::ActionInterface<F> {\ 3932 public:\ 3933 typedef F function_type;\ 3934 typedef typename ::testing::internal::Function<F>::Result return_type;\ 3935 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 3936 args_type;\ 3937 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 3938 p3##_type gmock_p3, p4##_type gmock_p4, \ 3939 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 3940 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ 3941 virtual return_type Perform(const args_type& args) {\ 3942 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 3943 Perform(this, args);\ 3944 }\ 3945 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3946 typename arg3_type, typename arg4_type, typename arg5_type, \ 3947 typename arg6_type, typename arg7_type, typename arg8_type, \ 3948 typename arg9_type>\ 3949 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 3950 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 3951 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 3952 arg9_type arg9) const;\ 3953 p0##_type p0;\ 3954 p1##_type p1;\ 3955 p2##_type p2;\ 3956 p3##_type p3;\ 3957 p4##_type p4;\ 3958 p5##_type p5;\ 3959 private:\ 3960 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 3961 };\ 3962 template <typename F> operator ::testing::Action<F>() const {\ 3963 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\ 3964 }\ 3965 p0##_type p0;\ 3966 p1##_type p1;\ 3967 p2##_type p2;\ 3968 p3##_type p3;\ 3969 p4##_type p4;\ 3970 p5##_type p5;\ 3971 private:\ 3972 GTEST_DISALLOW_ASSIGN_(name##ActionP6);\ 3973 };\ 3974 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 3975 typename p3##_type, typename p4##_type, typename p5##_type>\ 3976 inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \ 3977 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ 3978 p3##_type p3, p4##_type p4, p5##_type p5) {\ 3979 return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \ 3980 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\ 3981 }\ 3982 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 3983 typename p3##_type, typename p4##_type, typename p5##_type>\ 3984 template <typename F>\ 3985 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 3986 typename arg3_type, typename arg4_type, typename arg5_type, \ 3987 typename arg6_type, typename arg7_type, typename arg8_type, \ 3988 typename arg9_type>\ 3989 typename ::testing::internal::Function<F>::Result\ 3990 name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 3991 p5##_type>::gmock_Impl<F>::gmock_PerformImpl(\ 3992 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 3993 3994 #define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\ 3995 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 3996 typename p3##_type, typename p4##_type, typename p5##_type, \ 3997 typename p6##_type>\ 3998 class name##ActionP7 {\ 3999 public:\ 4000 name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \ 4001 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ 4002 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \ 4003 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ 4004 p6(gmock_p6) {}\ 4005 template <typename F>\ 4006 class gmock_Impl : public ::testing::ActionInterface<F> {\ 4007 public:\ 4008 typedef F function_type;\ 4009 typedef typename ::testing::internal::Function<F>::Result return_type;\ 4010 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 4011 args_type;\ 4012 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 4013 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 4014 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 4015 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ 4016 virtual return_type Perform(const args_type& args) {\ 4017 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 4018 Perform(this, args);\ 4019 }\ 4020 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 4021 typename arg3_type, typename arg4_type, typename arg5_type, \ 4022 typename arg6_type, typename arg7_type, typename arg8_type, \ 4023 typename arg9_type>\ 4024 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 4025 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 4026 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 4027 arg9_type arg9) const;\ 4028 p0##_type p0;\ 4029 p1##_type p1;\ 4030 p2##_type p2;\ 4031 p3##_type p3;\ 4032 p4##_type p4;\ 4033 p5##_type p5;\ 4034 p6##_type p6;\ 4035 private:\ 4036 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 4037 };\ 4038 template <typename F> operator ::testing::Action<F>() const {\ 4039 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ 4040 p6));\ 4041 }\ 4042 p0##_type p0;\ 4043 p1##_type p1;\ 4044 p2##_type p2;\ 4045 p3##_type p3;\ 4046 p4##_type p4;\ 4047 p5##_type p5;\ 4048 p6##_type p6;\ 4049 private:\ 4050 GTEST_DISALLOW_ASSIGN_(name##ActionP7);\ 4051 };\ 4052 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 4053 typename p3##_type, typename p4##_type, typename p5##_type, \ 4054 typename p6##_type>\ 4055 inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \ 4056 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \ 4057 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ 4058 p6##_type p6) {\ 4059 return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \ 4060 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\ 4061 }\ 4062 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 4063 typename p3##_type, typename p4##_type, typename p5##_type, \ 4064 typename p6##_type>\ 4065 template <typename F>\ 4066 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 4067 typename arg3_type, typename arg4_type, typename arg5_type, \ 4068 typename arg6_type, typename arg7_type, typename arg8_type, \ 4069 typename arg9_type>\ 4070 typename ::testing::internal::Function<F>::Result\ 4071 name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 4072 p5##_type, p6##_type>::gmock_Impl<F>::gmock_PerformImpl(\ 4073 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 4074 4075 #define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\ 4076 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 4077 typename p3##_type, typename p4##_type, typename p5##_type, \ 4078 typename p6##_type, typename p7##_type>\ 4079 class name##ActionP8 {\ 4080 public:\ 4081 name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \ 4082 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ 4083 p5##_type gmock_p5, p6##_type gmock_p6, \ 4084 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 4085 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ 4086 p7(gmock_p7) {}\ 4087 template <typename F>\ 4088 class gmock_Impl : public ::testing::ActionInterface<F> {\ 4089 public:\ 4090 typedef F function_type;\ 4091 typedef typename ::testing::internal::Function<F>::Result return_type;\ 4092 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 4093 args_type;\ 4094 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 4095 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 4096 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \ 4097 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \ 4098 p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\ 4099 virtual return_type Perform(const args_type& args) {\ 4100 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 4101 Perform(this, args);\ 4102 }\ 4103 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 4104 typename arg3_type, typename arg4_type, typename arg5_type, \ 4105 typename arg6_type, typename arg7_type, typename arg8_type, \ 4106 typename arg9_type>\ 4107 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 4108 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 4109 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 4110 arg9_type arg9) const;\ 4111 p0##_type p0;\ 4112 p1##_type p1;\ 4113 p2##_type p2;\ 4114 p3##_type p3;\ 4115 p4##_type p4;\ 4116 p5##_type p5;\ 4117 p6##_type p6;\ 4118 p7##_type p7;\ 4119 private:\ 4120 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 4121 };\ 4122 template <typename F> operator ::testing::Action<F>() const {\ 4123 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ 4124 p6, p7));\ 4125 }\ 4126 p0##_type p0;\ 4127 p1##_type p1;\ 4128 p2##_type p2;\ 4129 p3##_type p3;\ 4130 p4##_type p4;\ 4131 p5##_type p5;\ 4132 p6##_type p6;\ 4133 p7##_type p7;\ 4134 private:\ 4135 GTEST_DISALLOW_ASSIGN_(name##ActionP8);\ 4136 };\ 4137 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 4138 typename p3##_type, typename p4##_type, typename p5##_type, \ 4139 typename p6##_type, typename p7##_type>\ 4140 inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \ 4141 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \ 4142 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ 4143 p6##_type p6, p7##_type p7) {\ 4144 return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \ 4145 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \ 4146 p6, p7);\ 4147 }\ 4148 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 4149 typename p3##_type, typename p4##_type, typename p5##_type, \ 4150 typename p6##_type, typename p7##_type>\ 4151 template <typename F>\ 4152 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 4153 typename arg3_type, typename arg4_type, typename arg5_type, \ 4154 typename arg6_type, typename arg7_type, typename arg8_type, \ 4155 typename arg9_type>\ 4156 typename ::testing::internal::Function<F>::Result\ 4157 name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 4158 p5##_type, p6##_type, \ 4159 p7##_type>::gmock_Impl<F>::gmock_PerformImpl(\ 4160 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 4161 4162 #define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\ 4163 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 4164 typename p3##_type, typename p4##_type, typename p5##_type, \ 4165 typename p6##_type, typename p7##_type, typename p8##_type>\ 4166 class name##ActionP9 {\ 4167 public:\ 4168 name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \ 4169 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ 4170 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ 4171 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 4172 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ 4173 p8(gmock_p8) {}\ 4174 template <typename F>\ 4175 class gmock_Impl : public ::testing::ActionInterface<F> {\ 4176 public:\ 4177 typedef F function_type;\ 4178 typedef typename ::testing::internal::Function<F>::Result return_type;\ 4179 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 4180 args_type;\ 4181 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 4182 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 4183 p6##_type gmock_p6, p7##_type gmock_p7, \ 4184 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 4185 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ 4186 p7(gmock_p7), p8(gmock_p8) {}\ 4187 virtual return_type Perform(const args_type& args) {\ 4188 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 4189 Perform(this, args);\ 4190 }\ 4191 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 4192 typename arg3_type, typename arg4_type, typename arg5_type, \ 4193 typename arg6_type, typename arg7_type, typename arg8_type, \ 4194 typename arg9_type>\ 4195 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 4196 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 4197 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 4198 arg9_type arg9) const;\ 4199 p0##_type p0;\ 4200 p1##_type p1;\ 4201 p2##_type p2;\ 4202 p3##_type p3;\ 4203 p4##_type p4;\ 4204 p5##_type p5;\ 4205 p6##_type p6;\ 4206 p7##_type p7;\ 4207 p8##_type p8;\ 4208 private:\ 4209 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 4210 };\ 4211 template <typename F> operator ::testing::Action<F>() const {\ 4212 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ 4213 p6, p7, p8));\ 4214 }\ 4215 p0##_type p0;\ 4216 p1##_type p1;\ 4217 p2##_type p2;\ 4218 p3##_type p3;\ 4219 p4##_type p4;\ 4220 p5##_type p5;\ 4221 p6##_type p6;\ 4222 p7##_type p7;\ 4223 p8##_type p8;\ 4224 private:\ 4225 GTEST_DISALLOW_ASSIGN_(name##ActionP9);\ 4226 };\ 4227 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 4228 typename p3##_type, typename p4##_type, typename p5##_type, \ 4229 typename p6##_type, typename p7##_type, typename p8##_type>\ 4230 inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \ 4231 p4##_type, p5##_type, p6##_type, p7##_type, \ 4232 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ 4233 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ 4234 p8##_type p8) {\ 4235 return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \ 4236 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \ 4237 p3, p4, p5, p6, p7, p8);\ 4238 }\ 4239 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 4240 typename p3##_type, typename p4##_type, typename p5##_type, \ 4241 typename p6##_type, typename p7##_type, typename p8##_type>\ 4242 template <typename F>\ 4243 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 4244 typename arg3_type, typename arg4_type, typename arg5_type, \ 4245 typename arg6_type, typename arg7_type, typename arg8_type, \ 4246 typename arg9_type>\ 4247 typename ::testing::internal::Function<F>::Result\ 4248 name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 4249 p5##_type, p6##_type, p7##_type, \ 4250 p8##_type>::gmock_Impl<F>::gmock_PerformImpl(\ 4251 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 4252 4253 #define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\ 4254 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 4255 typename p3##_type, typename p4##_type, typename p5##_type, \ 4256 typename p6##_type, typename p7##_type, typename p8##_type, \ 4257 typename p9##_type>\ 4258 class name##ActionP10 {\ 4259 public:\ 4260 name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \ 4261 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ 4262 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ 4263 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \ 4264 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ 4265 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ 4266 template <typename F>\ 4267 class gmock_Impl : public ::testing::ActionInterface<F> {\ 4268 public:\ 4269 typedef F function_type;\ 4270 typedef typename ::testing::internal::Function<F>::Result return_type;\ 4271 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ 4272 args_type;\ 4273 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 4274 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 4275 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ 4276 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 4277 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ 4278 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ 4279 virtual return_type Perform(const args_type& args) {\ 4280 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ 4281 Perform(this, args);\ 4282 }\ 4283 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 4284 typename arg3_type, typename arg4_type, typename arg5_type, \ 4285 typename arg6_type, typename arg7_type, typename arg8_type, \ 4286 typename arg9_type>\ 4287 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ 4288 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ 4289 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ 4290 arg9_type arg9) const;\ 4291 p0##_type p0;\ 4292 p1##_type p1;\ 4293 p2##_type p2;\ 4294 p3##_type p3;\ 4295 p4##_type p4;\ 4296 p5##_type p5;\ 4297 p6##_type p6;\ 4298 p7##_type p7;\ 4299 p8##_type p8;\ 4300 p9##_type p9;\ 4301 private:\ 4302 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 4303 };\ 4304 template <typename F> operator ::testing::Action<F>() const {\ 4305 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ 4306 p6, p7, p8, p9));\ 4307 }\ 4308 p0##_type p0;\ 4309 p1##_type p1;\ 4310 p2##_type p2;\ 4311 p3##_type p3;\ 4312 p4##_type p4;\ 4313 p5##_type p5;\ 4314 p6##_type p6;\ 4315 p7##_type p7;\ 4316 p8##_type p8;\ 4317 p9##_type p9;\ 4318 private:\ 4319 GTEST_DISALLOW_ASSIGN_(name##ActionP10);\ 4320 };\ 4321 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 4322 typename p3##_type, typename p4##_type, typename p5##_type, \ 4323 typename p6##_type, typename p7##_type, typename p8##_type, \ 4324 typename p9##_type>\ 4325 inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \ 4326 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ 4327 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ 4328 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ 4329 p9##_type p9) {\ 4330 return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \ 4331 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \ 4332 p1, p2, p3, p4, p5, p6, p7, p8, p9);\ 4333 }\ 4334 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 4335 typename p3##_type, typename p4##_type, typename p5##_type, \ 4336 typename p6##_type, typename p7##_type, typename p8##_type, \ 4337 typename p9##_type>\ 4338 template <typename F>\ 4339 template <typename arg0_type, typename arg1_type, typename arg2_type, \ 4340 typename arg3_type, typename arg4_type, typename arg5_type, \ 4341 typename arg6_type, typename arg7_type, typename arg8_type, \ 4342 typename arg9_type>\ 4343 typename ::testing::internal::Function<F>::Result\ 4344 name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 4345 p5##_type, p6##_type, p7##_type, p8##_type, \ 4346 p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\ 4347 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 4348 4349 namespace testing { 4350 4351 // The ACTION*() macros trigger warning C4100 (unreferenced formal 4352 // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in 4353 // the macro definition, as the warnings are generated when the macro 4354 // is expanded and macro expansion cannot contain #pragma. Therefore 4355 // we suppress them here. 4356 #ifdef _MSC_VER 4357 # pragma warning(push) 4358 # pragma warning(disable:4100) 4359 #endif 4360 4361 // Various overloads for InvokeArgument<N>(). 4362 // 4363 // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th 4364 // (0-based) argument, which must be a k-ary callable, of the mock 4365 // function, with arguments a1, a2, ..., a_k. 4366 // 4367 // Notes: 4368 // 4369 // 1. The arguments are passed by value by default. If you need to 4370 // pass an argument by reference, wrap it inside ByRef(). For 4371 // example, 4372 // 4373 // InvokeArgument<1>(5, string("Hello"), ByRef(foo)) 4374 // 4375 // passes 5 and string("Hello") by value, and passes foo by 4376 // reference. 4377 // 4378 // 2. If the callable takes an argument by reference but ByRef() is 4379 // not used, it will receive the reference to a copy of the value, 4380 // instead of the original value. For example, when the 0-th 4381 // argument of the mock function takes a const string&, the action 4382 // 4383 // InvokeArgument<0>(string("Hello")) 4384 // 4385 // makes a copy of the temporary string("Hello") object and passes a 4386 // reference of the copy, instead of the original temporary object, 4387 // to the callable. This makes it easy for a user to define an 4388 // InvokeArgument action from temporary values and have it performed 4389 // later. 4390 4391 ACTION_TEMPLATE(InvokeArgument, 4392 HAS_1_TEMPLATE_PARAMS(int, k), 4393 AND_0_VALUE_PARAMS()) { 4394 return internal::CallableHelper<return_type>::Call( 4395 ::std::tr1::get<k>(args)); 4396 } 4397 4398 ACTION_TEMPLATE(InvokeArgument, 4399 HAS_1_TEMPLATE_PARAMS(int, k), 4400 AND_1_VALUE_PARAMS(p0)) { 4401 return internal::CallableHelper<return_type>::Call( 4402 ::std::tr1::get<k>(args), p0); 4403 } 4404 4405 ACTION_TEMPLATE(InvokeArgument, 4406 HAS_1_TEMPLATE_PARAMS(int, k), 4407 AND_2_VALUE_PARAMS(p0, p1)) { 4408 return internal::CallableHelper<return_type>::Call( 4409 ::std::tr1::get<k>(args), p0, p1); 4410 } 4411 4412 ACTION_TEMPLATE(InvokeArgument, 4413 HAS_1_TEMPLATE_PARAMS(int, k), 4414 AND_3_VALUE_PARAMS(p0, p1, p2)) { 4415 return internal::CallableHelper<return_type>::Call( 4416 ::std::tr1::get<k>(args), p0, p1, p2); 4417 } 4418 4419 ACTION_TEMPLATE(InvokeArgument, 4420 HAS_1_TEMPLATE_PARAMS(int, k), 4421 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) { 4422 return internal::CallableHelper<return_type>::Call( 4423 ::std::tr1::get<k>(args), p0, p1, p2, p3); 4424 } 4425 4426 ACTION_TEMPLATE(InvokeArgument, 4427 HAS_1_TEMPLATE_PARAMS(int, k), 4428 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) { 4429 return internal::CallableHelper<return_type>::Call( 4430 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4); 4431 } 4432 4433 ACTION_TEMPLATE(InvokeArgument, 4434 HAS_1_TEMPLATE_PARAMS(int, k), 4435 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) { 4436 return internal::CallableHelper<return_type>::Call( 4437 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5); 4438 } 4439 4440 ACTION_TEMPLATE(InvokeArgument, 4441 HAS_1_TEMPLATE_PARAMS(int, k), 4442 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) { 4443 return internal::CallableHelper<return_type>::Call( 4444 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6); 4445 } 4446 4447 ACTION_TEMPLATE(InvokeArgument, 4448 HAS_1_TEMPLATE_PARAMS(int, k), 4449 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) { 4450 return internal::CallableHelper<return_type>::Call( 4451 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7); 4452 } 4453 4454 ACTION_TEMPLATE(InvokeArgument, 4455 HAS_1_TEMPLATE_PARAMS(int, k), 4456 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) { 4457 return internal::CallableHelper<return_type>::Call( 4458 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8); 4459 } 4460 4461 ACTION_TEMPLATE(InvokeArgument, 4462 HAS_1_TEMPLATE_PARAMS(int, k), 4463 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) { 4464 return internal::CallableHelper<return_type>::Call( 4465 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); 4466 } 4467 4468 // Various overloads for ReturnNew<T>(). 4469 // 4470 // The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new 4471 // instance of type T, constructed on the heap with constructor arguments 4472 // a1, a2, ..., and a_k. The caller assumes ownership of the returned value. 4473 ACTION_TEMPLATE(ReturnNew, 4474 HAS_1_TEMPLATE_PARAMS(typename, T), 4475 AND_0_VALUE_PARAMS()) { 4476 return new T(); 4477 } 4478 4479 ACTION_TEMPLATE(ReturnNew, 4480 HAS_1_TEMPLATE_PARAMS(typename, T), 4481 AND_1_VALUE_PARAMS(p0)) { 4482 return new T(p0); 4483 } 4484 4485 ACTION_TEMPLATE(ReturnNew, 4486 HAS_1_TEMPLATE_PARAMS(typename, T), 4487 AND_2_VALUE_PARAMS(p0, p1)) { 4488 return new T(p0, p1); 4489 } 4490 4491 ACTION_TEMPLATE(ReturnNew, 4492 HAS_1_TEMPLATE_PARAMS(typename, T), 4493 AND_3_VALUE_PARAMS(p0, p1, p2)) { 4494 return new T(p0, p1, p2); 4495 } 4496 4497 ACTION_TEMPLATE(ReturnNew, 4498 HAS_1_TEMPLATE_PARAMS(typename, T), 4499 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) { 4500 return new T(p0, p1, p2, p3); 4501 } 4502 4503 ACTION_TEMPLATE(ReturnNew, 4504 HAS_1_TEMPLATE_PARAMS(typename, T), 4505 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) { 4506 return new T(p0, p1, p2, p3, p4); 4507 } 4508 4509 ACTION_TEMPLATE(ReturnNew, 4510 HAS_1_TEMPLATE_PARAMS(typename, T), 4511 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) { 4512 return new T(p0, p1, p2, p3, p4, p5); 4513 } 4514 4515 ACTION_TEMPLATE(ReturnNew, 4516 HAS_1_TEMPLATE_PARAMS(typename, T), 4517 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) { 4518 return new T(p0, p1, p2, p3, p4, p5, p6); 4519 } 4520 4521 ACTION_TEMPLATE(ReturnNew, 4522 HAS_1_TEMPLATE_PARAMS(typename, T), 4523 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) { 4524 return new T(p0, p1, p2, p3, p4, p5, p6, p7); 4525 } 4526 4527 ACTION_TEMPLATE(ReturnNew, 4528 HAS_1_TEMPLATE_PARAMS(typename, T), 4529 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) { 4530 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8); 4531 } 4532 4533 ACTION_TEMPLATE(ReturnNew, 4534 HAS_1_TEMPLATE_PARAMS(typename, T), 4535 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) { 4536 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); 4537 } 4538 4539 #ifdef _MSC_VER 4540 # pragma warning(pop) 4541 #endif 4542 4543 } // namespace testing 4544 4545 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ 4546 // This file was GENERATED by command: 4547 // pump.py gmock-generated-function-mockers.h.pump 4548 // DO NOT EDIT BY HAND!!! 4549 4550 // Copyright 2007, Google Inc. 4551 // All rights reserved. 4552 // 4553 // Redistribution and use in source and binary forms, with or without 4554 // modification, are permitted provided that the following conditions are 4555 // met: 4556 // 4557 // * Redistributions of source code must retain the above copyright 4558 // notice, this list of conditions and the following disclaimer. 4559 // * Redistributions in binary form must reproduce the above 4560 // copyright notice, this list of conditions and the following disclaimer 4561 // in the documentation and/or other materials provided with the 4562 // distribution. 4563 // * Neither the name of Google Inc. nor the names of its 4564 // contributors may be used to endorse or promote products derived from 4565 // this software without specific prior written permission. 4566 // 4567 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4568 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 4569 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 4570 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 4571 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4572 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 4573 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 4574 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 4575 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 4576 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 4577 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4578 // 4579 // Author: wan@google.com (Zhanyong Wan) 4580 4581 // Google Mock - a framework for writing C++ mock classes. 4582 // 4583 // This file implements function mockers of various arities. 4584 4585 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ 4586 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ 4587 4588 // Copyright 2007, Google Inc. 4589 // All rights reserved. 4590 // 4591 // Redistribution and use in source and binary forms, with or without 4592 // modification, are permitted provided that the following conditions are 4593 // met: 4594 // 4595 // * Redistributions of source code must retain the above copyright 4596 // notice, this list of conditions and the following disclaimer. 4597 // * Redistributions in binary form must reproduce the above 4598 // copyright notice, this list of conditions and the following disclaimer 4599 // in the documentation and/or other materials provided with the 4600 // distribution. 4601 // * Neither the name of Google Inc. nor the names of its 4602 // contributors may be used to endorse or promote products derived from 4603 // this software without specific prior written permission. 4604 // 4605 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4606 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 4607 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 4608 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 4609 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4610 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 4611 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 4612 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 4613 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 4614 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 4615 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4616 // 4617 // Author: wan@google.com (Zhanyong Wan) 4618 4619 // Google Mock - a framework for writing C++ mock classes. 4620 // 4621 // This file implements the ON_CALL() and EXPECT_CALL() macros. 4622 // 4623 // A user can use the ON_CALL() macro to specify the default action of 4624 // a mock method. The syntax is: 4625 // 4626 // ON_CALL(mock_object, Method(argument-matchers)) 4627 // .With(multi-argument-matcher) 4628 // .WillByDefault(action); 4629 // 4630 // where the .With() clause is optional. 4631 // 4632 // A user can use the EXPECT_CALL() macro to specify an expectation on 4633 // a mock method. The syntax is: 4634 // 4635 // EXPECT_CALL(mock_object, Method(argument-matchers)) 4636 // .With(multi-argument-matchers) 4637 // .Times(cardinality) 4638 // .InSequence(sequences) 4639 // .After(expectations) 4640 // .WillOnce(action) 4641 // .WillRepeatedly(action) 4642 // .RetiresOnSaturation(); 4643 // 4644 // where all clauses are optional, and .InSequence()/.After()/ 4645 // .WillOnce() can appear any number of times. 4646 4647 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ 4648 #define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ 4649 4650 #include <map> 4651 #include <set> 4652 #include <sstream> 4653 #include <string> 4654 #include <vector> 4655 4656 #if GTEST_HAS_EXCEPTIONS 4657 # include <stdexcept> // NOLINT 4658 #endif 4659 4660 // Copyright 2007, Google Inc. 4661 // All rights reserved. 4662 // 4663 // Redistribution and use in source and binary forms, with or without 4664 // modification, are permitted provided that the following conditions are 4665 // met: 4666 // 4667 // * Redistributions of source code must retain the above copyright 4668 // notice, this list of conditions and the following disclaimer. 4669 // * Redistributions in binary form must reproduce the above 4670 // copyright notice, this list of conditions and the following disclaimer 4671 // in the documentation and/or other materials provided with the 4672 // distribution. 4673 // * Neither the name of Google Inc. nor the names of its 4674 // contributors may be used to endorse or promote products derived from 4675 // this software without specific prior written permission. 4676 // 4677 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4678 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 4679 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 4680 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 4681 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4682 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 4683 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 4684 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 4685 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 4686 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 4687 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4688 // 4689 // Author: wan@google.com (Zhanyong Wan) 4690 4691 // Google Mock - a framework for writing C++ mock classes. 4692 // 4693 // This file implements some commonly used argument matchers. More 4694 // matchers can be defined by the user implementing the 4695 // MatcherInterface<T> interface if necessary. 4696 4697 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ 4698 #define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ 4699 4700 #include <math.h> 4701 #include <algorithm> 4702 #include <iterator> 4703 #include <limits> 4704 #include <ostream> // NOLINT 4705 #include <sstream> 4706 #include <string> 4707 #include <utility> 4708 #include <vector> 4709 4710 4711 #if GTEST_LANG_CXX11 4712 #include <initializer_list> // NOLINT -- must be after gtest.h 4713 #endif 4714 4715 namespace testing { 4716 4717 // To implement a matcher Foo for type T, define: 4718 // 1. a class FooMatcherImpl that implements the 4719 // MatcherInterface<T> interface, and 4720 // 2. a factory function that creates a Matcher<T> object from a 4721 // FooMatcherImpl*. 4722 // 4723 // The two-level delegation design makes it possible to allow a user 4724 // to write "v" instead of "Eq(v)" where a Matcher is expected, which 4725 // is impossible if we pass matchers by pointers. It also eases 4726 // ownership management as Matcher objects can now be copied like 4727 // plain values. 4728 4729 // MatchResultListener is an abstract class. Its << operator can be 4730 // used by a matcher to explain why a value matches or doesn't match. 4731 // 4732 // TODO(wan@google.com): add method 4733 // bool InterestedInWhy(bool result) const; 4734 // to indicate whether the listener is interested in why the match 4735 // result is 'result'. 4736 class MatchResultListener { 4737 public: 4738 // Creates a listener object with the given underlying ostream. The 4739 // listener does not own the ostream, and does not dereference it 4740 // in the constructor or destructor. 4741 explicit MatchResultListener(::std::ostream* os) : stream_(os) {} 4742 virtual ~MatchResultListener() = 0; // Makes this class abstract. 4743 4744 // Streams x to the underlying ostream; does nothing if the ostream 4745 // is NULL. 4746 template <typename T> 4747 MatchResultListener& operator<<(const T& x) { 4748 if (stream_ != NULL) 4749 *stream_ << x; 4750 return *this; 4751 } 4752 4753 // Returns the underlying ostream. 4754 ::std::ostream* stream() { return stream_; } 4755 4756 // Returns true iff the listener is interested in an explanation of 4757 // the match result. A matcher's MatchAndExplain() method can use 4758 // this information to avoid generating the explanation when no one 4759 // intends to hear it. 4760 bool IsInterested() const { return stream_ != NULL; } 4761 4762 private: 4763 ::std::ostream* const stream_; 4764 4765 GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener); 4766 }; 4767 4768 inline MatchResultListener::~MatchResultListener() { 4769 } 4770 4771 // An instance of a subclass of this knows how to describe itself as a 4772 // matcher. 4773 class MatcherDescriberInterface { 4774 public: 4775 virtual ~MatcherDescriberInterface() {} 4776 4777 // Describes this matcher to an ostream. The function should print 4778 // a verb phrase that describes the property a value matching this 4779 // matcher should have. The subject of the verb phrase is the value 4780 // being matched. For example, the DescribeTo() method of the Gt(7) 4781 // matcher prints "is greater than 7". 4782 virtual void DescribeTo(::std::ostream* os) const = 0; 4783 4784 // Describes the negation of this matcher to an ostream. For 4785 // example, if the description of this matcher is "is greater than 4786 // 7", the negated description could be "is not greater than 7". 4787 // You are not required to override this when implementing 4788 // MatcherInterface, but it is highly advised so that your matcher 4789 // can produce good error messages. 4790 virtual void DescribeNegationTo(::std::ostream* os) const { 4791 *os << "not ("; 4792 DescribeTo(os); 4793 *os << ")"; 4794 } 4795 }; 4796 4797 // The implementation of a matcher. 4798 template <typename T> 4799 class MatcherInterface : public MatcherDescriberInterface { 4800 public: 4801 // Returns true iff the matcher matches x; also explains the match 4802 // result to 'listener' if necessary (see the next paragraph), in 4803 // the form of a non-restrictive relative clause ("which ...", 4804 // "whose ...", etc) that describes x. For example, the 4805 // MatchAndExplain() method of the Pointee(...) matcher should 4806 // generate an explanation like "which points to ...". 4807 // 4808 // Implementations of MatchAndExplain() should add an explanation of 4809 // the match result *if and only if* they can provide additional 4810 // information that's not already present (or not obvious) in the 4811 // print-out of x and the matcher's description. Whether the match 4812 // succeeds is not a factor in deciding whether an explanation is 4813 // needed, as sometimes the caller needs to print a failure message 4814 // when the match succeeds (e.g. when the matcher is used inside 4815 // Not()). 4816 // 4817 // For example, a "has at least 10 elements" matcher should explain 4818 // what the actual element count is, regardless of the match result, 4819 // as it is useful information to the reader; on the other hand, an 4820 // "is empty" matcher probably only needs to explain what the actual 4821 // size is when the match fails, as it's redundant to say that the 4822 // size is 0 when the value is already known to be empty. 4823 // 4824 // You should override this method when defining a new matcher. 4825 // 4826 // It's the responsibility of the caller (Google Mock) to guarantee 4827 // that 'listener' is not NULL. This helps to simplify a matcher's 4828 // implementation when it doesn't care about the performance, as it 4829 // can talk to 'listener' without checking its validity first. 4830 // However, in order to implement dummy listeners efficiently, 4831 // listener->stream() may be NULL. 4832 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0; 4833 4834 // Inherits these methods from MatcherDescriberInterface: 4835 // virtual void DescribeTo(::std::ostream* os) const = 0; 4836 // virtual void DescribeNegationTo(::std::ostream* os) const; 4837 }; 4838 4839 // A match result listener that stores the explanation in a string. 4840 class StringMatchResultListener : public MatchResultListener { 4841 public: 4842 StringMatchResultListener() : MatchResultListener(&ss_) {} 4843 4844 // Returns the explanation accumulated so far. 4845 internal::string str() const { return ss_.str(); } 4846 4847 // Clears the explanation accumulated so far. 4848 void Clear() { ss_.str(""); } 4849 4850 private: 4851 ::std::stringstream ss_; 4852 4853 GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener); 4854 }; 4855 4856 namespace internal { 4857 4858 // A match result listener that ignores the explanation. 4859 class DummyMatchResultListener : public MatchResultListener { 4860 public: 4861 DummyMatchResultListener() : MatchResultListener(NULL) {} 4862 4863 private: 4864 GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener); 4865 }; 4866 4867 // A match result listener that forwards the explanation to a given 4868 // ostream. The difference between this and MatchResultListener is 4869 // that the former is concrete. 4870 class StreamMatchResultListener : public MatchResultListener { 4871 public: 4872 explicit StreamMatchResultListener(::std::ostream* os) 4873 : MatchResultListener(os) {} 4874 4875 private: 4876 GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener); 4877 }; 4878 4879 // An internal class for implementing Matcher<T>, which will derive 4880 // from it. We put functionalities common to all Matcher<T> 4881 // specializations here to avoid code duplication. 4882 template <typename T> 4883 class MatcherBase { 4884 public: 4885 // Returns true iff the matcher matches x; also explains the match 4886 // result to 'listener'. 4887 bool MatchAndExplain(T x, MatchResultListener* listener) const { 4888 return impl_->MatchAndExplain(x, listener); 4889 } 4890 4891 // Returns true iff this matcher matches x. 4892 bool Matches(T x) const { 4893 DummyMatchResultListener dummy; 4894 return MatchAndExplain(x, &dummy); 4895 } 4896 4897 // Describes this matcher to an ostream. 4898 void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } 4899 4900 // Describes the negation of this matcher to an ostream. 4901 void DescribeNegationTo(::std::ostream* os) const { 4902 impl_->DescribeNegationTo(os); 4903 } 4904 4905 // Explains why x matches, or doesn't match, the matcher. 4906 void ExplainMatchResultTo(T x, ::std::ostream* os) const { 4907 StreamMatchResultListener listener(os); 4908 MatchAndExplain(x, &listener); 4909 } 4910 4911 // Returns the describer for this matcher object; retains ownership 4912 // of the describer, which is only guaranteed to be alive when 4913 // this matcher object is alive. 4914 const MatcherDescriberInterface* GetDescriber() const { 4915 return impl_.get(); 4916 } 4917 4918 protected: 4919 MatcherBase() {} 4920 4921 // Constructs a matcher from its implementation. 4922 explicit MatcherBase(const MatcherInterface<T>* impl) 4923 : impl_(impl) {} 4924 4925 virtual ~MatcherBase() {} 4926 4927 private: 4928 // shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar 4929 // interfaces. The former dynamically allocates a chunk of memory 4930 // to hold the reference count, while the latter tracks all 4931 // references using a circular linked list without allocating 4932 // memory. It has been observed that linked_ptr performs better in 4933 // typical scenarios. However, shared_ptr can out-perform 4934 // linked_ptr when there are many more uses of the copy constructor 4935 // than the default constructor. 4936 // 4937 // If performance becomes a problem, we should see if using 4938 // shared_ptr helps. 4939 ::testing::internal::linked_ptr<const MatcherInterface<T> > impl_; 4940 }; 4941 4942 } // namespace internal 4943 4944 // A Matcher<T> is a copyable and IMMUTABLE (except by assignment) 4945 // object that can check whether a value of type T matches. The 4946 // implementation of Matcher<T> is just a linked_ptr to const 4947 // MatcherInterface<T>, so copying is fairly cheap. Don't inherit 4948 // from Matcher! 4949 template <typename T> 4950 class Matcher : public internal::MatcherBase<T> { 4951 public: 4952 // Constructs a null matcher. Needed for storing Matcher objects in STL 4953 // containers. A default-constructed matcher is not yet initialized. You 4954 // cannot use it until a valid value has been assigned to it. 4955 Matcher() {} 4956 4957 // Constructs a matcher from its implementation. 4958 explicit Matcher(const MatcherInterface<T>* impl) 4959 : internal::MatcherBase<T>(impl) {} 4960 4961 // Implicit constructor here allows people to write 4962 // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes 4963 Matcher(T value); // NOLINT 4964 }; 4965 4966 // The following two specializations allow the user to write str 4967 // instead of Eq(str) and "foo" instead of Eq("foo") when a string 4968 // matcher is expected. 4969 template <> 4970 class GTEST_API_ Matcher<const internal::string&> 4971 : public internal::MatcherBase<const internal::string&> { 4972 public: 4973 Matcher() {} 4974 4975 explicit Matcher(const MatcherInterface<const internal::string&>* impl) 4976 : internal::MatcherBase<const internal::string&>(impl) {} 4977 4978 // Allows the user to write str instead of Eq(str) sometimes, where 4979 // str is a string object. 4980 Matcher(const internal::string& s); // NOLINT 4981 4982 // Allows the user to write "foo" instead of Eq("foo") sometimes. 4983 Matcher(const char* s); // NOLINT 4984 }; 4985 4986 template <> 4987 class GTEST_API_ Matcher<internal::string> 4988 : public internal::MatcherBase<internal::string> { 4989 public: 4990 Matcher() {} 4991 4992 explicit Matcher(const MatcherInterface<internal::string>* impl) 4993 : internal::MatcherBase<internal::string>(impl) {} 4994 4995 // Allows the user to write str instead of Eq(str) sometimes, where 4996 // str is a string object. 4997 Matcher(const internal::string& s); // NOLINT 4998 4999 // Allows the user to write "foo" instead of Eq("foo") sometimes. 5000 Matcher(const char* s); // NOLINT 5001 }; 5002 5003 #if GTEST_HAS_STRING_PIECE_ 5004 // The following two specializations allow the user to write str 5005 // instead of Eq(str) and "foo" instead of Eq("foo") when a StringPiece 5006 // matcher is expected. 5007 template <> 5008 class GTEST_API_ Matcher<const StringPiece&> 5009 : public internal::MatcherBase<const StringPiece&> { 5010 public: 5011 Matcher() {} 5012 5013 explicit Matcher(const MatcherInterface<const StringPiece&>* impl) 5014 : internal::MatcherBase<const StringPiece&>(impl) {} 5015 5016 // Allows the user to write str instead of Eq(str) sometimes, where 5017 // str is a string object. 5018 Matcher(const internal::string& s); // NOLINT 5019 5020 // Allows the user to write "foo" instead of Eq("foo") sometimes. 5021 Matcher(const char* s); // NOLINT 5022 5023 // Allows the user to pass StringPieces directly. 5024 Matcher(StringPiece s); // NOLINT 5025 }; 5026 5027 template <> 5028 class GTEST_API_ Matcher<StringPiece> 5029 : public internal::MatcherBase<StringPiece> { 5030 public: 5031 Matcher() {} 5032 5033 explicit Matcher(const MatcherInterface<StringPiece>* impl) 5034 : internal::MatcherBase<StringPiece>(impl) {} 5035 5036 // Allows the user to write str instead of Eq(str) sometimes, where 5037 // str is a string object. 5038 Matcher(const internal::string& s); // NOLINT 5039 5040 // Allows the user to write "foo" instead of Eq("foo") sometimes. 5041 Matcher(const char* s); // NOLINT 5042 5043 // Allows the user to pass StringPieces directly. 5044 Matcher(StringPiece s); // NOLINT 5045 }; 5046 #endif // GTEST_HAS_STRING_PIECE_ 5047 5048 // The PolymorphicMatcher class template makes it easy to implement a 5049 // polymorphic matcher (i.e. a matcher that can match values of more 5050 // than one type, e.g. Eq(n) and NotNull()). 5051 // 5052 // To define a polymorphic matcher, a user should provide an Impl 5053 // class that has a DescribeTo() method and a DescribeNegationTo() 5054 // method, and define a member function (or member function template) 5055 // 5056 // bool MatchAndExplain(const Value& value, 5057 // MatchResultListener* listener) const; 5058 // 5059 // See the definition of NotNull() for a complete example. 5060 template <class Impl> 5061 class PolymorphicMatcher { 5062 public: 5063 explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {} 5064 5065 // Returns a mutable reference to the underlying matcher 5066 // implementation object. 5067 Impl& mutable_impl() { return impl_; } 5068 5069 // Returns an immutable reference to the underlying matcher 5070 // implementation object. 5071 const Impl& impl() const { return impl_; } 5072 5073 template <typename T> 5074 operator Matcher<T>() const { 5075 return Matcher<T>(new MonomorphicImpl<T>(impl_)); 5076 } 5077 5078 private: 5079 template <typename T> 5080 class MonomorphicImpl : public MatcherInterface<T> { 5081 public: 5082 explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} 5083 5084 virtual void DescribeTo(::std::ostream* os) const { 5085 impl_.DescribeTo(os); 5086 } 5087 5088 virtual void DescribeNegationTo(::std::ostream* os) const { 5089 impl_.DescribeNegationTo(os); 5090 } 5091 5092 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { 5093 return impl_.MatchAndExplain(x, listener); 5094 } 5095 5096 private: 5097 const Impl impl_; 5098 5099 GTEST_DISALLOW_ASSIGN_(MonomorphicImpl); 5100 }; 5101 5102 Impl impl_; 5103 5104 GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher); 5105 }; 5106 5107 // Creates a matcher from its implementation. This is easier to use 5108 // than the Matcher<T> constructor as it doesn't require you to 5109 // explicitly write the template argument, e.g. 5110 // 5111 // MakeMatcher(foo); 5112 // vs 5113 // Matcher<const string&>(foo); 5114 template <typename T> 5115 inline Matcher<T> MakeMatcher(const MatcherInterface<T>* impl) { 5116 return Matcher<T>(impl); 5117 } 5118 5119 // Creates a polymorphic matcher from its implementation. This is 5120 // easier to use than the PolymorphicMatcher<Impl> constructor as it 5121 // doesn't require you to explicitly write the template argument, e.g. 5122 // 5123 // MakePolymorphicMatcher(foo); 5124 // vs 5125 // PolymorphicMatcher<TypeOfFoo>(foo); 5126 template <class Impl> 5127 inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) { 5128 return PolymorphicMatcher<Impl>(impl); 5129 } 5130 5131 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION 5132 // and MUST NOT BE USED IN USER CODE!!! 5133 namespace internal { 5134 5135 // The MatcherCastImpl class template is a helper for implementing 5136 // MatcherCast(). We need this helper in order to partially 5137 // specialize the implementation of MatcherCast() (C++ allows 5138 // class/struct templates to be partially specialized, but not 5139 // function templates.). 5140 5141 // This general version is used when MatcherCast()'s argument is a 5142 // polymorphic matcher (i.e. something that can be converted to a 5143 // Matcher but is not one yet; for example, Eq(value)) or a value (for 5144 // example, "hello"). 5145 template <typename T, typename M> 5146 class MatcherCastImpl { 5147 public: 5148 static Matcher<T> Cast(M polymorphic_matcher_or_value) { 5149 // M can be a polymorhic matcher, in which case we want to use 5150 // its conversion operator to create Matcher<T>. Or it can be a value 5151 // that should be passed to the Matcher<T>'s constructor. 5152 // 5153 // We can't call Matcher<T>(polymorphic_matcher_or_value) when M is a 5154 // polymorphic matcher because it'll be ambiguous if T has an implicit 5155 // constructor from M (this usually happens when T has an implicit 5156 // constructor from any type). 5157 // 5158 // It won't work to unconditionally implict_cast 5159 // polymorphic_matcher_or_value to Matcher<T> because it won't trigger 5160 // a user-defined conversion from M to T if one exists (assuming M is 5161 // a value). 5162 return CastImpl( 5163 polymorphic_matcher_or_value, 5164 BooleanConstant< 5165 internal::ImplicitlyConvertible<M, Matcher<T> >::value>()); 5166 } 5167 5168 private: 5169 static Matcher<T> CastImpl(M value, BooleanConstant<false>) { 5170 // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic 5171 // matcher. It must be a value then. Use direct initialization to create 5172 // a matcher. 5173 return Matcher<T>(ImplicitCast_<T>(value)); 5174 } 5175 5176 static Matcher<T> CastImpl(M polymorphic_matcher_or_value, 5177 BooleanConstant<true>) { 5178 // M is implicitly convertible to Matcher<T>, which means that either 5179 // M is a polymorhpic matcher or Matcher<T> has an implicit constructor 5180 // from M. In both cases using the implicit conversion will produce a 5181 // matcher. 5182 // 5183 // Even if T has an implicit constructor from M, it won't be called because 5184 // creating Matcher<T> would require a chain of two user-defined conversions 5185 // (first to create T from M and then to create Matcher<T> from T). 5186 return polymorphic_matcher_or_value; 5187 } 5188 }; 5189 5190 // This more specialized version is used when MatcherCast()'s argument 5191 // is already a Matcher. This only compiles when type T can be 5192 // statically converted to type U. 5193 template <typename T, typename U> 5194 class MatcherCastImpl<T, Matcher<U> > { 5195 public: 5196 static Matcher<T> Cast(const Matcher<U>& source_matcher) { 5197 return Matcher<T>(new Impl(source_matcher)); 5198 } 5199 5200 private: 5201 class Impl : public MatcherInterface<T> { 5202 public: 5203 explicit Impl(const Matcher<U>& source_matcher) 5204 : source_matcher_(source_matcher) {} 5205 5206 // We delegate the matching logic to the source matcher. 5207 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { 5208 return source_matcher_.MatchAndExplain(static_cast<U>(x), listener); 5209 } 5210 5211 virtual void DescribeTo(::std::ostream* os) const { 5212 source_matcher_.DescribeTo(os); 5213 } 5214 5215 virtual void DescribeNegationTo(::std::ostream* os) const { 5216 source_matcher_.DescribeNegationTo(os); 5217 } 5218 5219 private: 5220 const Matcher<U> source_matcher_; 5221 5222 GTEST_DISALLOW_ASSIGN_(Impl); 5223 }; 5224 }; 5225 5226 // This even more specialized version is used for efficiently casting 5227 // a matcher to its own type. 5228 template <typename T> 5229 class MatcherCastImpl<T, Matcher<T> > { 5230 public: 5231 static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; } 5232 }; 5233 5234 } // namespace internal 5235 5236 // In order to be safe and clear, casting between different matcher 5237 // types is done explicitly via MatcherCast<T>(m), which takes a 5238 // matcher m and returns a Matcher<T>. It compiles only when T can be 5239 // statically converted to the argument type of m. 5240 template <typename T, typename M> 5241 inline Matcher<T> MatcherCast(M matcher) { 5242 return internal::MatcherCastImpl<T, M>::Cast(matcher); 5243 } 5244 5245 // Implements SafeMatcherCast(). 5246 // 5247 // We use an intermediate class to do the actual safe casting as Nokia's 5248 // Symbian compiler cannot decide between 5249 // template <T, M> ... (M) and 5250 // template <T, U> ... (const Matcher<U>&) 5251 // for function templates but can for member function templates. 5252 template <typename T> 5253 class SafeMatcherCastImpl { 5254 public: 5255 // This overload handles polymorphic matchers and values only since 5256 // monomorphic matchers are handled by the next one. 5257 template <typename M> 5258 static inline Matcher<T> Cast(M polymorphic_matcher_or_value) { 5259 return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value); 5260 } 5261 5262 // This overload handles monomorphic matchers. 5263 // 5264 // In general, if type T can be implicitly converted to type U, we can 5265 // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is 5266 // contravariant): just keep a copy of the original Matcher<U>, convert the 5267 // argument from type T to U, and then pass it to the underlying Matcher<U>. 5268 // The only exception is when U is a reference and T is not, as the 5269 // underlying Matcher<U> may be interested in the argument's address, which 5270 // is not preserved in the conversion from T to U. 5271 template <typename U> 5272 static inline Matcher<T> Cast(const Matcher<U>& matcher) { 5273 // Enforce that T can be implicitly converted to U. 5274 GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible<T, U>::value), 5275 T_must_be_implicitly_convertible_to_U); 5276 // Enforce that we are not converting a non-reference type T to a reference 5277 // type U. 5278 GTEST_COMPILE_ASSERT_( 5279 internal::is_reference<T>::value || !internal::is_reference<U>::value, 5280 cannot_convert_non_referentce_arg_to_reference); 5281 // In case both T and U are arithmetic types, enforce that the 5282 // conversion is not lossy. 5283 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT; 5284 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU; 5285 const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther; 5286 const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther; 5287 GTEST_COMPILE_ASSERT_( 5288 kTIsOther || kUIsOther || 5289 (internal::LosslessArithmeticConvertible<RawT, RawU>::value), 5290 conversion_of_arithmetic_types_must_be_lossless); 5291 return MatcherCast<T>(matcher); 5292 } 5293 }; 5294 5295 template <typename T, typename M> 5296 inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) { 5297 return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher); 5298 } 5299 5300 // A<T>() returns a matcher that matches any value of type T. 5301 template <typename T> 5302 Matcher<T> A(); 5303 5304 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION 5305 // and MUST NOT BE USED IN USER CODE!!! 5306 namespace internal { 5307 5308 // If the explanation is not empty, prints it to the ostream. 5309 inline void PrintIfNotEmpty(const internal::string& explanation, 5310 ::std::ostream* os) { 5311 if (explanation != "" && os != NULL) { 5312 *os << ", " << explanation; 5313 } 5314 } 5315 5316 // Returns true if the given type name is easy to read by a human. 5317 // This is used to decide whether printing the type of a value might 5318 // be helpful. 5319 inline bool IsReadableTypeName(const string& type_name) { 5320 // We consider a type name readable if it's short or doesn't contain 5321 // a template or function type. 5322 return (type_name.length() <= 20 || 5323 type_name.find_first_of("<(") == string::npos); 5324 } 5325 5326 // Matches the value against the given matcher, prints the value and explains 5327 // the match result to the listener. Returns the match result. 5328 // 'listener' must not be NULL. 5329 // Value cannot be passed by const reference, because some matchers take a 5330 // non-const argument. 5331 template <typename Value, typename T> 5332 bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher, 5333 MatchResultListener* listener) { 5334 if (!listener->IsInterested()) { 5335 // If the listener is not interested, we do not need to construct the 5336 // inner explanation. 5337 return matcher.Matches(value); 5338 } 5339 5340 StringMatchResultListener inner_listener; 5341 const bool match = matcher.MatchAndExplain(value, &inner_listener); 5342 5343 UniversalPrint(value, listener->stream()); 5344 #if GTEST_HAS_RTTI 5345 const string& type_name = GetTypeName<Value>(); 5346 if (IsReadableTypeName(type_name)) 5347 *listener->stream() << " (of type " << type_name << ")"; 5348 #endif 5349 PrintIfNotEmpty(inner_listener.str(), listener->stream()); 5350 5351 return match; 5352 } 5353 5354 // An internal helper class for doing compile-time loop on a tuple's 5355 // fields. 5356 template <size_t N> 5357 class TuplePrefix { 5358 public: 5359 // TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true 5360 // iff the first N fields of matcher_tuple matches the first N 5361 // fields of value_tuple, respectively. 5362 template <typename MatcherTuple, typename ValueTuple> 5363 static bool Matches(const MatcherTuple& matcher_tuple, 5364 const ValueTuple& value_tuple) { 5365 using ::std::tr1::get; 5366 return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple) 5367 && get<N - 1>(matcher_tuple).Matches(get<N - 1>(value_tuple)); 5368 } 5369 5370 // TuplePrefix<N>::ExplainMatchFailuresTo(matchers, values, os) 5371 // describes failures in matching the first N fields of matchers 5372 // against the first N fields of values. If there is no failure, 5373 // nothing will be streamed to os. 5374 template <typename MatcherTuple, typename ValueTuple> 5375 static void ExplainMatchFailuresTo(const MatcherTuple& matchers, 5376 const ValueTuple& values, 5377 ::std::ostream* os) { 5378 using ::std::tr1::tuple_element; 5379 using ::std::tr1::get; 5380 5381 // First, describes failures in the first N - 1 fields. 5382 TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os); 5383 5384 // Then describes the failure (if any) in the (N - 1)-th (0-based) 5385 // field. 5386 typename tuple_element<N - 1, MatcherTuple>::type matcher = 5387 get<N - 1>(matchers); 5388 typedef typename tuple_element<N - 1, ValueTuple>::type Value; 5389 Value value = get<N - 1>(values); 5390 StringMatchResultListener listener; 5391 if (!matcher.MatchAndExplain(value, &listener)) { 5392 // TODO(wan): include in the message the name of the parameter 5393 // as used in MOCK_METHOD*() when possible. 5394 *os << " Expected arg #" << N - 1 << ": "; 5395 get<N - 1>(matchers).DescribeTo(os); 5396 *os << "\n Actual: "; 5397 // We remove the reference in type Value to prevent the 5398 // universal printer from printing the address of value, which 5399 // isn't interesting to the user most of the time. The 5400 // matcher's MatchAndExplain() method handles the case when 5401 // the address is interesting. 5402 internal::UniversalPrint(value, os); 5403 PrintIfNotEmpty(listener.str(), os); 5404 *os << "\n"; 5405 } 5406 } 5407 }; 5408 5409 // The base case. 5410 template <> 5411 class TuplePrefix<0> { 5412 public: 5413 template <typename MatcherTuple, typename ValueTuple> 5414 static bool Matches(const MatcherTuple& /* matcher_tuple */, 5415 const ValueTuple& /* value_tuple */) { 5416 return true; 5417 } 5418 5419 template <typename MatcherTuple, typename ValueTuple> 5420 static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */, 5421 const ValueTuple& /* values */, 5422 ::std::ostream* /* os */) {} 5423 }; 5424 5425 // TupleMatches(matcher_tuple, value_tuple) returns true iff all 5426 // matchers in matcher_tuple match the corresponding fields in 5427 // value_tuple. It is a compiler error if matcher_tuple and 5428 // value_tuple have different number of fields or incompatible field 5429 // types. 5430 template <typename MatcherTuple, typename ValueTuple> 5431 bool TupleMatches(const MatcherTuple& matcher_tuple, 5432 const ValueTuple& value_tuple) { 5433 using ::std::tr1::tuple_size; 5434 // Makes sure that matcher_tuple and value_tuple have the same 5435 // number of fields. 5436 GTEST_COMPILE_ASSERT_(tuple_size<MatcherTuple>::value == 5437 tuple_size<ValueTuple>::value, 5438 matcher_and_value_have_different_numbers_of_fields); 5439 return TuplePrefix<tuple_size<ValueTuple>::value>:: 5440 Matches(matcher_tuple, value_tuple); 5441 } 5442 5443 // Describes failures in matching matchers against values. If there 5444 // is no failure, nothing will be streamed to os. 5445 template <typename MatcherTuple, typename ValueTuple> 5446 void ExplainMatchFailureTupleTo(const MatcherTuple& matchers, 5447 const ValueTuple& values, 5448 ::std::ostream* os) { 5449 using ::std::tr1::tuple_size; 5450 TuplePrefix<tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo( 5451 matchers, values, os); 5452 } 5453 5454 // TransformTupleValues and its helper. 5455 // 5456 // TransformTupleValuesHelper hides the internal machinery that 5457 // TransformTupleValues uses to implement a tuple traversal. 5458 template <typename Tuple, typename Func, typename OutIter> 5459 class TransformTupleValuesHelper { 5460 private: 5461 typedef typename ::std::tr1::tuple_size<Tuple> TupleSize; 5462 5463 public: 5464 // For each member of tuple 't', taken in order, evaluates '*out++ = f(t)'. 5465 // Returns the final value of 'out' in case the caller needs it. 5466 static OutIter Run(Func f, const Tuple& t, OutIter out) { 5467 return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out); 5468 } 5469 5470 private: 5471 template <typename Tup, size_t kRemainingSize> 5472 struct IterateOverTuple { 5473 OutIter operator() (Func f, const Tup& t, OutIter out) const { 5474 *out++ = f(::std::tr1::get<TupleSize::value - kRemainingSize>(t)); 5475 return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out); 5476 } 5477 }; 5478 template <typename Tup> 5479 struct IterateOverTuple<Tup, 0> { 5480 OutIter operator() (Func /* f */, const Tup& /* t */, OutIter out) const { 5481 return out; 5482 } 5483 }; 5484 }; 5485 5486 // Successively invokes 'f(element)' on each element of the tuple 't', 5487 // appending each result to the 'out' iterator. Returns the final value 5488 // of 'out'. 5489 template <typename Tuple, typename Func, typename OutIter> 5490 OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) { 5491 return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out); 5492 } 5493 5494 // Implements A<T>(). 5495 template <typename T> 5496 class AnyMatcherImpl : public MatcherInterface<T> { 5497 public: 5498 virtual bool MatchAndExplain( 5499 T /* x */, MatchResultListener* /* listener */) const { return true; } 5500 virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; } 5501 virtual void DescribeNegationTo(::std::ostream* os) const { 5502 // This is mostly for completeness' safe, as it's not very useful 5503 // to write Not(A<bool>()). However we cannot completely rule out 5504 // such a possibility, and it doesn't hurt to be prepared. 5505 *os << "never matches"; 5506 } 5507 }; 5508 5509 // Implements _, a matcher that matches any value of any 5510 // type. This is a polymorphic matcher, so we need a template type 5511 // conversion operator to make it appearing as a Matcher<T> for any 5512 // type T. 5513 class AnythingMatcher { 5514 public: 5515 template <typename T> 5516 operator Matcher<T>() const { return A<T>(); } 5517 }; 5518 5519 // Implements a matcher that compares a given value with a 5520 // pre-supplied value using one of the ==, <=, <, etc, operators. The 5521 // two values being compared don't have to have the same type. 5522 // 5523 // The matcher defined here is polymorphic (for example, Eq(5) can be 5524 // used to match an int, a short, a double, etc). Therefore we use 5525 // a template type conversion operator in the implementation. 5526 // 5527 // We define this as a macro in order to eliminate duplicated source 5528 // code. 5529 // 5530 // The following template definition assumes that the Rhs parameter is 5531 // a "bare" type (i.e. neither 'const T' nor 'T&'). 5532 #define GMOCK_IMPLEMENT_COMPARISON_MATCHER_( \ 5533 name, op, relation, negated_relation) \ 5534 template <typename Rhs> class name##Matcher { \ 5535 public: \ 5536 explicit name##Matcher(const Rhs& rhs) : rhs_(rhs) {} \ 5537 template <typename Lhs> \ 5538 operator Matcher<Lhs>() const { \ 5539 return MakeMatcher(new Impl<Lhs>(rhs_)); \ 5540 } \ 5541 private: \ 5542 template <typename Lhs> \ 5543 class Impl : public MatcherInterface<Lhs> { \ 5544 public: \ 5545 explicit Impl(const Rhs& rhs) : rhs_(rhs) {} \ 5546 virtual bool MatchAndExplain(\ 5547 Lhs lhs, MatchResultListener* /* listener */) const { \ 5548 return lhs op rhs_; \ 5549 } \ 5550 virtual void DescribeTo(::std::ostream* os) const { \ 5551 *os << relation " "; \ 5552 UniversalPrint(rhs_, os); \ 5553 } \ 5554 virtual void DescribeNegationTo(::std::ostream* os) const { \ 5555 *os << negated_relation " "; \ 5556 UniversalPrint(rhs_, os); \ 5557 } \ 5558 private: \ 5559 Rhs rhs_; \ 5560 GTEST_DISALLOW_ASSIGN_(Impl); \ 5561 }; \ 5562 Rhs rhs_; \ 5563 GTEST_DISALLOW_ASSIGN_(name##Matcher); \ 5564 } 5565 5566 // Implements Eq(v), Ge(v), Gt(v), Le(v), Lt(v), and Ne(v) 5567 // respectively. 5568 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to"); 5569 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ge, >=, "is >=", "isn't >="); 5570 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Gt, >, "is >", "isn't >"); 5571 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Le, <=, "is <=", "isn't <="); 5572 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Lt, <, "is <", "isn't <"); 5573 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ne, !=, "isn't equal to", "is equal to"); 5574 5575 #undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_ 5576 5577 // Implements the polymorphic IsNull() matcher, which matches any raw or smart 5578 // pointer that is NULL. 5579 class IsNullMatcher { 5580 public: 5581 template <typename Pointer> 5582 bool MatchAndExplain(const Pointer& p, 5583 MatchResultListener* /* listener */) const { 5584 return GetRawPointer(p) == NULL; 5585 } 5586 5587 void DescribeTo(::std::ostream* os) const { *os << "is NULL"; } 5588 void DescribeNegationTo(::std::ostream* os) const { 5589 *os << "isn't NULL"; 5590 } 5591 }; 5592 5593 // Implements the polymorphic NotNull() matcher, which matches any raw or smart 5594 // pointer that is not NULL. 5595 class NotNullMatcher { 5596 public: 5597 template <typename Pointer> 5598 bool MatchAndExplain(const Pointer& p, 5599 MatchResultListener* /* listener */) const { 5600 return GetRawPointer(p) != NULL; 5601 } 5602 5603 void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; } 5604 void DescribeNegationTo(::std::ostream* os) const { 5605 *os << "is NULL"; 5606 } 5607 }; 5608 5609 // Ref(variable) matches any argument that is a reference to 5610 // 'variable'. This matcher is polymorphic as it can match any 5611 // super type of the type of 'variable'. 5612 // 5613 // The RefMatcher template class implements Ref(variable). It can 5614 // only be instantiated with a reference type. This prevents a user 5615 // from mistakenly using Ref(x) to match a non-reference function 5616 // argument. For example, the following will righteously cause a 5617 // compiler error: 5618 // 5619 // int n; 5620 // Matcher<int> m1 = Ref(n); // This won't compile. 5621 // Matcher<int&> m2 = Ref(n); // This will compile. 5622 template <typename T> 5623 class RefMatcher; 5624 5625 template <typename T> 5626 class RefMatcher<T&> { 5627 // Google Mock is a generic framework and thus needs to support 5628 // mocking any function types, including those that take non-const 5629 // reference arguments. Therefore the template parameter T (and 5630 // Super below) can be instantiated to either a const type or a 5631 // non-const type. 5632 public: 5633 // RefMatcher() takes a T& instead of const T&, as we want the 5634 // compiler to catch using Ref(const_value) as a matcher for a 5635 // non-const reference. 5636 explicit RefMatcher(T& x) : object_(x) {} // NOLINT 5637 5638 template <typename Super> 5639 operator Matcher<Super&>() const { 5640 // By passing object_ (type T&) to Impl(), which expects a Super&, 5641 // we make sure that Super is a super type of T. In particular, 5642 // this catches using Ref(const_value) as a matcher for a 5643 // non-const reference, as you cannot implicitly convert a const 5644 // reference to a non-const reference. 5645 return MakeMatcher(new Impl<Super>(object_)); 5646 } 5647 5648 private: 5649 template <typename Super> 5650 class Impl : public MatcherInterface<Super&> { 5651 public: 5652 explicit Impl(Super& x) : object_(x) {} // NOLINT 5653 5654 // MatchAndExplain() takes a Super& (as opposed to const Super&) 5655 // in order to match the interface MatcherInterface<Super&>. 5656 virtual bool MatchAndExplain( 5657 Super& x, MatchResultListener* listener) const { 5658 *listener << "which is located @" << static_cast<const void*>(&x); 5659 return &x == &object_; 5660 } 5661 5662 virtual void DescribeTo(::std::ostream* os) const { 5663 *os << "references the variable "; 5664 UniversalPrinter<Super&>::Print(object_, os); 5665 } 5666 5667 virtual void DescribeNegationTo(::std::ostream* os) const { 5668 *os << "does not reference the variable "; 5669 UniversalPrinter<Super&>::Print(object_, os); 5670 } 5671 5672 private: 5673 const Super& object_; 5674 5675 GTEST_DISALLOW_ASSIGN_(Impl); 5676 }; 5677 5678 T& object_; 5679 5680 GTEST_DISALLOW_ASSIGN_(RefMatcher); 5681 }; 5682 5683 // Polymorphic helper functions for narrow and wide string matchers. 5684 inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) { 5685 return String::CaseInsensitiveCStringEquals(lhs, rhs); 5686 } 5687 5688 inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs, 5689 const wchar_t* rhs) { 5690 return String::CaseInsensitiveWideCStringEquals(lhs, rhs); 5691 } 5692 5693 // String comparison for narrow or wide strings that can have embedded NUL 5694 // characters. 5695 template <typename StringType> 5696 bool CaseInsensitiveStringEquals(const StringType& s1, 5697 const StringType& s2) { 5698 // Are the heads equal? 5699 if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) { 5700 return false; 5701 } 5702 5703 // Skip the equal heads. 5704 const typename StringType::value_type nul = 0; 5705 const size_t i1 = s1.find(nul), i2 = s2.find(nul); 5706 5707 // Are we at the end of either s1 or s2? 5708 if (i1 == StringType::npos || i2 == StringType::npos) { 5709 return i1 == i2; 5710 } 5711 5712 // Are the tails equal? 5713 return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1)); 5714 } 5715 5716 // String matchers. 5717 5718 // Implements equality-based string matchers like StrEq, StrCaseNe, and etc. 5719 template <typename StringType> 5720 class StrEqualityMatcher { 5721 public: 5722 StrEqualityMatcher(const StringType& str, bool expect_eq, 5723 bool case_sensitive) 5724 : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {} 5725 5726 // Accepts pointer types, particularly: 5727 // const char* 5728 // char* 5729 // const wchar_t* 5730 // wchar_t* 5731 template <typename CharType> 5732 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { 5733 if (s == NULL) { 5734 return !expect_eq_; 5735 } 5736 return MatchAndExplain(StringType(s), listener); 5737 } 5738 5739 // Matches anything that can convert to StringType. 5740 // 5741 // This is a template, not just a plain function with const StringType&, 5742 // because StringPiece has some interfering non-explicit constructors. 5743 template <typename MatcheeStringType> 5744 bool MatchAndExplain(const MatcheeStringType& s, 5745 MatchResultListener* /* listener */) const { 5746 const StringType& s2(s); 5747 const bool eq = case_sensitive_ ? s2 == string_ : 5748 CaseInsensitiveStringEquals(s2, string_); 5749 return expect_eq_ == eq; 5750 } 5751 5752 void DescribeTo(::std::ostream* os) const { 5753 DescribeToHelper(expect_eq_, os); 5754 } 5755 5756 void DescribeNegationTo(::std::ostream* os) const { 5757 DescribeToHelper(!expect_eq_, os); 5758 } 5759 5760 private: 5761 void DescribeToHelper(bool expect_eq, ::std::ostream* os) const { 5762 *os << (expect_eq ? "is " : "isn't "); 5763 *os << "equal to "; 5764 if (!case_sensitive_) { 5765 *os << "(ignoring case) "; 5766 } 5767 UniversalPrint(string_, os); 5768 } 5769 5770 const StringType string_; 5771 const bool expect_eq_; 5772 const bool case_sensitive_; 5773 5774 GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher); 5775 }; 5776 5777 // Implements the polymorphic HasSubstr(substring) matcher, which 5778 // can be used as a Matcher<T> as long as T can be converted to a 5779 // string. 5780 template <typename StringType> 5781 class HasSubstrMatcher { 5782 public: 5783 explicit HasSubstrMatcher(const StringType& substring) 5784 : substring_(substring) {} 5785 5786 // Accepts pointer types, particularly: 5787 // const char* 5788 // char* 5789 // const wchar_t* 5790 // wchar_t* 5791 template <typename CharType> 5792 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { 5793 return s != NULL && MatchAndExplain(StringType(s), listener); 5794 } 5795 5796 // Matches anything that can convert to StringType. 5797 // 5798 // This is a template, not just a plain function with const StringType&, 5799 // because StringPiece has some interfering non-explicit constructors. 5800 template <typename MatcheeStringType> 5801 bool MatchAndExplain(const MatcheeStringType& s, 5802 MatchResultListener* /* listener */) const { 5803 const StringType& s2(s); 5804 return s2.find(substring_) != StringType::npos; 5805 } 5806 5807 // Describes what this matcher matches. 5808 void DescribeTo(::std::ostream* os) const { 5809 *os << "has substring "; 5810 UniversalPrint(substring_, os); 5811 } 5812 5813 void DescribeNegationTo(::std::ostream* os) const { 5814 *os << "has no substring "; 5815 UniversalPrint(substring_, os); 5816 } 5817 5818 private: 5819 const StringType substring_; 5820 5821 GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher); 5822 }; 5823 5824 // Implements the polymorphic StartsWith(substring) matcher, which 5825 // can be used as a Matcher<T> as long as T can be converted to a 5826 // string. 5827 template <typename StringType> 5828 class StartsWithMatcher { 5829 public: 5830 explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) { 5831 } 5832 5833 // Accepts pointer types, particularly: 5834 // const char* 5835 // char* 5836 // const wchar_t* 5837 // wchar_t* 5838 template <typename CharType> 5839 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { 5840 return s != NULL && MatchAndExplain(StringType(s), listener); 5841 } 5842 5843 // Matches anything that can convert to StringType. 5844 // 5845 // This is a template, not just a plain function with const StringType&, 5846 // because StringPiece has some interfering non-explicit constructors. 5847 template <typename MatcheeStringType> 5848 bool MatchAndExplain(const MatcheeStringType& s, 5849 MatchResultListener* /* listener */) const { 5850 const StringType& s2(s); 5851 return s2.length() >= prefix_.length() && 5852 s2.substr(0, prefix_.length()) == prefix_; 5853 } 5854 5855 void DescribeTo(::std::ostream* os) const { 5856 *os << "starts with "; 5857 UniversalPrint(prefix_, os); 5858 } 5859 5860 void DescribeNegationTo(::std::ostream* os) const { 5861 *os << "doesn't start with "; 5862 UniversalPrint(prefix_, os); 5863 } 5864 5865 private: 5866 const StringType prefix_; 5867 5868 GTEST_DISALLOW_ASSIGN_(StartsWithMatcher); 5869 }; 5870 5871 // Implements the polymorphic EndsWith(substring) matcher, which 5872 // can be used as a Matcher<T> as long as T can be converted to a 5873 // string. 5874 template <typename StringType> 5875 class EndsWithMatcher { 5876 public: 5877 explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {} 5878 5879 // Accepts pointer types, particularly: 5880 // const char* 5881 // char* 5882 // const wchar_t* 5883 // wchar_t* 5884 template <typename CharType> 5885 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { 5886 return s != NULL && MatchAndExplain(StringType(s), listener); 5887 } 5888 5889 // Matches anything that can convert to StringType. 5890 // 5891 // This is a template, not just a plain function with const StringType&, 5892 // because StringPiece has some interfering non-explicit constructors. 5893 template <typename MatcheeStringType> 5894 bool MatchAndExplain(const MatcheeStringType& s, 5895 MatchResultListener* /* listener */) const { 5896 const StringType& s2(s); 5897 return s2.length() >= suffix_.length() && 5898 s2.substr(s2.length() - suffix_.length()) == suffix_; 5899 } 5900 5901 void DescribeTo(::std::ostream* os) const { 5902 *os << "ends with "; 5903 UniversalPrint(suffix_, os); 5904 } 5905 5906 void DescribeNegationTo(::std::ostream* os) const { 5907 *os << "doesn't end with "; 5908 UniversalPrint(suffix_, os); 5909 } 5910 5911 private: 5912 const StringType suffix_; 5913 5914 GTEST_DISALLOW_ASSIGN_(EndsWithMatcher); 5915 }; 5916 5917 // Implements polymorphic matchers MatchesRegex(regex) and 5918 // ContainsRegex(regex), which can be used as a Matcher<T> as long as 5919 // T can be converted to a string. 5920 class MatchesRegexMatcher { 5921 public: 5922 MatchesRegexMatcher(const RE* regex, bool full_match) 5923 : regex_(regex), full_match_(full_match) {} 5924 5925 // Accepts pointer types, particularly: 5926 // const char* 5927 // char* 5928 // const wchar_t* 5929 // wchar_t* 5930 template <typename CharType> 5931 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { 5932 return s != NULL && MatchAndExplain(internal::string(s), listener); 5933 } 5934 5935 // Matches anything that can convert to internal::string. 5936 // 5937 // This is a template, not just a plain function with const internal::string&, 5938 // because StringPiece has some interfering non-explicit constructors. 5939 template <class MatcheeStringType> 5940 bool MatchAndExplain(const MatcheeStringType& s, 5941 MatchResultListener* /* listener */) const { 5942 const internal::string& s2(s); 5943 return full_match_ ? RE::FullMatch(s2, *regex_) : 5944 RE::PartialMatch(s2, *regex_); 5945 } 5946 5947 void DescribeTo(::std::ostream* os) const { 5948 *os << (full_match_ ? "matches" : "contains") 5949 << " regular expression "; 5950 UniversalPrinter<internal::string>::Print(regex_->pattern(), os); 5951 } 5952 5953 void DescribeNegationTo(::std::ostream* os) const { 5954 *os << "doesn't " << (full_match_ ? "match" : "contain") 5955 << " regular expression "; 5956 UniversalPrinter<internal::string>::Print(regex_->pattern(), os); 5957 } 5958 5959 private: 5960 const internal::linked_ptr<const RE> regex_; 5961 const bool full_match_; 5962 5963 GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher); 5964 }; 5965 5966 // Implements a matcher that compares the two fields of a 2-tuple 5967 // using one of the ==, <=, <, etc, operators. The two fields being 5968 // compared don't have to have the same type. 5969 // 5970 // The matcher defined here is polymorphic (for example, Eq() can be 5971 // used to match a tuple<int, short>, a tuple<const long&, double>, 5972 // etc). Therefore we use a template type conversion operator in the 5973 // implementation. 5974 // 5975 // We define this as a macro in order to eliminate duplicated source 5976 // code. 5977 #define GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(name, op, relation) \ 5978 class name##2Matcher { \ 5979 public: \ 5980 template <typename T1, typename T2> \ 5981 operator Matcher< ::std::tr1::tuple<T1, T2> >() const { \ 5982 return MakeMatcher(new Impl< ::std::tr1::tuple<T1, T2> >); \ 5983 } \ 5984 template <typename T1, typename T2> \ 5985 operator Matcher<const ::std::tr1::tuple<T1, T2>&>() const { \ 5986 return MakeMatcher(new Impl<const ::std::tr1::tuple<T1, T2>&>); \ 5987 } \ 5988 private: \ 5989 template <typename Tuple> \ 5990 class Impl : public MatcherInterface<Tuple> { \ 5991 public: \ 5992 virtual bool MatchAndExplain( \ 5993 Tuple args, \ 5994 MatchResultListener* /* listener */) const { \ 5995 return ::std::tr1::get<0>(args) op ::std::tr1::get<1>(args); \ 5996 } \ 5997 virtual void DescribeTo(::std::ostream* os) const { \ 5998 *os << "are " relation; \ 5999 } \ 6000 virtual void DescribeNegationTo(::std::ostream* os) const { \ 6001 *os << "aren't " relation; \ 6002 } \ 6003 }; \ 6004 } 6005 6006 // Implements Eq(), Ge(), Gt(), Le(), Lt(), and Ne() respectively. 6007 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Eq, ==, "an equal pair"); 6008 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( 6009 Ge, >=, "a pair where the first >= the second"); 6010 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( 6011 Gt, >, "a pair where the first > the second"); 6012 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( 6013 Le, <=, "a pair where the first <= the second"); 6014 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( 6015 Lt, <, "a pair where the first < the second"); 6016 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ne, !=, "an unequal pair"); 6017 6018 #undef GMOCK_IMPLEMENT_COMPARISON2_MATCHER_ 6019 6020 // Implements the Not(...) matcher for a particular argument type T. 6021 // We do not nest it inside the NotMatcher class template, as that 6022 // will prevent different instantiations of NotMatcher from sharing 6023 // the same NotMatcherImpl<T> class. 6024 template <typename T> 6025 class NotMatcherImpl : public MatcherInterface<T> { 6026 public: 6027 explicit NotMatcherImpl(const Matcher<T>& matcher) 6028 : matcher_(matcher) {} 6029 6030 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { 6031 return !matcher_.MatchAndExplain(x, listener); 6032 } 6033 6034 virtual void DescribeTo(::std::ostream* os) const { 6035 matcher_.DescribeNegationTo(os); 6036 } 6037 6038 virtual void DescribeNegationTo(::std::ostream* os) const { 6039 matcher_.DescribeTo(os); 6040 } 6041 6042 private: 6043 const Matcher<T> matcher_; 6044 6045 GTEST_DISALLOW_ASSIGN_(NotMatcherImpl); 6046 }; 6047 6048 // Implements the Not(m) matcher, which matches a value that doesn't 6049 // match matcher m. 6050 template <typename InnerMatcher> 6051 class NotMatcher { 6052 public: 6053 explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {} 6054 6055 // This template type conversion operator allows Not(m) to be used 6056 // to match any type m can match. 6057 template <typename T> 6058 operator Matcher<T>() const { 6059 return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_))); 6060 } 6061 6062 private: 6063 InnerMatcher matcher_; 6064 6065 GTEST_DISALLOW_ASSIGN_(NotMatcher); 6066 }; 6067 6068 // Implements the AllOf(m1, m2) matcher for a particular argument type 6069 // T. We do not nest it inside the BothOfMatcher class template, as 6070 // that will prevent different instantiations of BothOfMatcher from 6071 // sharing the same BothOfMatcherImpl<T> class. 6072 template <typename T> 6073 class BothOfMatcherImpl : public MatcherInterface<T> { 6074 public: 6075 BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2) 6076 : matcher1_(matcher1), matcher2_(matcher2) {} 6077 6078 virtual void DescribeTo(::std::ostream* os) const { 6079 *os << "("; 6080 matcher1_.DescribeTo(os); 6081 *os << ") and ("; 6082 matcher2_.DescribeTo(os); 6083 *os << ")"; 6084 } 6085 6086 virtual void DescribeNegationTo(::std::ostream* os) const { 6087 *os << "("; 6088 matcher1_.DescribeNegationTo(os); 6089 *os << ") or ("; 6090 matcher2_.DescribeNegationTo(os); 6091 *os << ")"; 6092 } 6093 6094 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { 6095 // If either matcher1_ or matcher2_ doesn't match x, we only need 6096 // to explain why one of them fails. 6097 StringMatchResultListener listener1; 6098 if (!matcher1_.MatchAndExplain(x, &listener1)) { 6099 *listener << listener1.str(); 6100 return false; 6101 } 6102 6103 StringMatchResultListener listener2; 6104 if (!matcher2_.MatchAndExplain(x, &listener2)) { 6105 *listener << listener2.str(); 6106 return false; 6107 } 6108 6109 // Otherwise we need to explain why *both* of them match. 6110 const internal::string s1 = listener1.str(); 6111 const internal::string s2 = listener2.str(); 6112 6113 if (s1 == "") { 6114 *listener << s2; 6115 } else { 6116 *listener << s1; 6117 if (s2 != "") { 6118 *listener << ", and " << s2; 6119 } 6120 } 6121 return true; 6122 } 6123 6124 private: 6125 const Matcher<T> matcher1_; 6126 const Matcher<T> matcher2_; 6127 6128 GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl); 6129 }; 6130 6131 #if GTEST_LANG_CXX11 6132 // MatcherList provides mechanisms for storing a variable number of matchers in 6133 // a list structure (ListType) and creating a combining matcher from such a 6134 // list. 6135 // The template is defined recursively using the following template paramters: 6136 // * kSize is the length of the MatcherList. 6137 // * Head is the type of the first matcher of the list. 6138 // * Tail denotes the types of the remaining matchers of the list. 6139 template <int kSize, typename Head, typename... Tail> 6140 struct MatcherList { 6141 typedef MatcherList<kSize - 1, Tail...> MatcherListTail; 6142 typedef ::std::pair<Head, typename MatcherListTail::ListType> ListType; 6143 6144 // BuildList stores variadic type values in a nested pair structure. 6145 // Example: 6146 // MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return 6147 // the corresponding result of type pair<int, pair<string, float>>. 6148 static ListType BuildList(const Head& matcher, const Tail&... tail) { 6149 return ListType(matcher, MatcherListTail::BuildList(tail...)); 6150 } 6151 6152 // CreateMatcher<T> creates a Matcher<T> from a given list of matchers (built 6153 // by BuildList()). CombiningMatcher<T> is used to combine the matchers of the 6154 // list. CombiningMatcher<T> must implement MatcherInterface<T> and have a 6155 // constructor taking two Matcher<T>s as input. 6156 template <typename T, template <typename /* T */> class CombiningMatcher> 6157 static Matcher<T> CreateMatcher(const ListType& matchers) { 6158 return Matcher<T>(new CombiningMatcher<T>( 6159 SafeMatcherCast<T>(matchers.first), 6160 MatcherListTail::template CreateMatcher<T, CombiningMatcher>( 6161 matchers.second))); 6162 } 6163 }; 6164 6165 // The following defines the base case for the recursive definition of 6166 // MatcherList. 6167 template <typename Matcher1, typename Matcher2> 6168 struct MatcherList<2, Matcher1, Matcher2> { 6169 typedef ::std::pair<Matcher1, Matcher2> ListType; 6170 6171 static ListType BuildList(const Matcher1& matcher1, 6172 const Matcher2& matcher2) { 6173 return ::std::pair<Matcher1, Matcher2>(matcher1, matcher2); 6174 } 6175 6176 template <typename T, template <typename /* T */> class CombiningMatcher> 6177 static Matcher<T> CreateMatcher(const ListType& matchers) { 6178 return Matcher<T>(new CombiningMatcher<T>( 6179 SafeMatcherCast<T>(matchers.first), 6180 SafeMatcherCast<T>(matchers.second))); 6181 } 6182 }; 6183 6184 // VariadicMatcher is used for the variadic implementation of 6185 // AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...). 6186 // CombiningMatcher<T> is used to recursively combine the provided matchers 6187 // (of type Args...). 6188 template <template <typename T> class CombiningMatcher, typename... Args> 6189 class VariadicMatcher { 6190 public: 6191 VariadicMatcher(const Args&... matchers) // NOLINT 6192 : matchers_(MatcherListType::BuildList(matchers...)) {} 6193 6194 // This template type conversion operator allows an 6195 // VariadicMatcher<Matcher1, Matcher2...> object to match any type that 6196 // all of the provided matchers (Matcher1, Matcher2, ...) can match. 6197 template <typename T> 6198 operator Matcher<T>() const { 6199 return MatcherListType::template CreateMatcher<T, CombiningMatcher>( 6200 matchers_); 6201 } 6202 6203 private: 6204 typedef MatcherList<sizeof...(Args), Args...> MatcherListType; 6205 6206 const typename MatcherListType::ListType matchers_; 6207 6208 GTEST_DISALLOW_ASSIGN_(VariadicMatcher); 6209 }; 6210 6211 template <typename... Args> 6212 using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl, Args...>; 6213 6214 #endif // GTEST_LANG_CXX11 6215 6216 // Used for implementing the AllOf(m_1, ..., m_n) matcher, which 6217 // matches a value that matches all of the matchers m_1, ..., and m_n. 6218 template <typename Matcher1, typename Matcher2> 6219 class BothOfMatcher { 6220 public: 6221 BothOfMatcher(Matcher1 matcher1, Matcher2 matcher2) 6222 : matcher1_(matcher1), matcher2_(matcher2) {} 6223 6224 // This template type conversion operator allows a 6225 // BothOfMatcher<Matcher1, Matcher2> object to match any type that 6226 // both Matcher1 and Matcher2 can match. 6227 template <typename T> 6228 operator Matcher<T>() const { 6229 return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_), 6230 SafeMatcherCast<T>(matcher2_))); 6231 } 6232 6233 private: 6234 Matcher1 matcher1_; 6235 Matcher2 matcher2_; 6236 6237 GTEST_DISALLOW_ASSIGN_(BothOfMatcher); 6238 }; 6239 6240 // Implements the AnyOf(m1, m2) matcher for a particular argument type 6241 // T. We do not nest it inside the AnyOfMatcher class template, as 6242 // that will prevent different instantiations of AnyOfMatcher from 6243 // sharing the same EitherOfMatcherImpl<T> class. 6244 template <typename T> 6245 class EitherOfMatcherImpl : public MatcherInterface<T> { 6246 public: 6247 EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2) 6248 : matcher1_(matcher1), matcher2_(matcher2) {} 6249 6250 virtual void DescribeTo(::std::ostream* os) const { 6251 *os << "("; 6252 matcher1_.DescribeTo(os); 6253 *os << ") or ("; 6254 matcher2_.DescribeTo(os); 6255 *os << ")"; 6256 } 6257 6258 virtual void DescribeNegationTo(::std::ostream* os) const { 6259 *os << "("; 6260 matcher1_.DescribeNegationTo(os); 6261 *os << ") and ("; 6262 matcher2_.DescribeNegationTo(os); 6263 *os << ")"; 6264 } 6265 6266 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { 6267 // If either matcher1_ or matcher2_ matches x, we just need to 6268 // explain why *one* of them matches. 6269 StringMatchResultListener listener1; 6270 if (matcher1_.MatchAndExplain(x, &listener1)) { 6271 *listener << listener1.str(); 6272 return true; 6273 } 6274 6275 StringMatchResultListener listener2; 6276 if (matcher2_.MatchAndExplain(x, &listener2)) { 6277 *listener << listener2.str(); 6278 return true; 6279 } 6280 6281 // Otherwise we need to explain why *both* of them fail. 6282 const internal::string s1 = listener1.str(); 6283 const internal::string s2 = listener2.str(); 6284 6285 if (s1 == "") { 6286 *listener << s2; 6287 } else { 6288 *listener << s1; 6289 if (s2 != "") { 6290 *listener << ", and " << s2; 6291 } 6292 } 6293 return false; 6294 } 6295 6296 private: 6297 const Matcher<T> matcher1_; 6298 const Matcher<T> matcher2_; 6299 6300 GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl); 6301 }; 6302 6303 #if GTEST_LANG_CXX11 6304 // AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...). 6305 template <typename... Args> 6306 using AnyOfMatcher = VariadicMatcher<EitherOfMatcherImpl, Args...>; 6307 6308 #endif // GTEST_LANG_CXX11 6309 6310 // Used for implementing the AnyOf(m_1, ..., m_n) matcher, which 6311 // matches a value that matches at least one of the matchers m_1, ..., 6312 // and m_n. 6313 template <typename Matcher1, typename Matcher2> 6314 class EitherOfMatcher { 6315 public: 6316 EitherOfMatcher(Matcher1 matcher1, Matcher2 matcher2) 6317 : matcher1_(matcher1), matcher2_(matcher2) {} 6318 6319 // This template type conversion operator allows a 6320 // EitherOfMatcher<Matcher1, Matcher2> object to match any type that 6321 // both Matcher1 and Matcher2 can match. 6322 template <typename T> 6323 operator Matcher<T>() const { 6324 return Matcher<T>(new EitherOfMatcherImpl<T>( 6325 SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_))); 6326 } 6327 6328 private: 6329 Matcher1 matcher1_; 6330 Matcher2 matcher2_; 6331 6332 GTEST_DISALLOW_ASSIGN_(EitherOfMatcher); 6333 }; 6334 6335 // Used for implementing Truly(pred), which turns a predicate into a 6336 // matcher. 6337 template <typename Predicate> 6338 class TrulyMatcher { 6339 public: 6340 explicit TrulyMatcher(Predicate pred) : predicate_(pred) {} 6341 6342 // This method template allows Truly(pred) to be used as a matcher 6343 // for type T where T is the argument type of predicate 'pred'. The 6344 // argument is passed by reference as the predicate may be 6345 // interested in the address of the argument. 6346 template <typename T> 6347 bool MatchAndExplain(T& x, // NOLINT 6348 MatchResultListener* /* listener */) const { 6349 // Without the if-statement, MSVC sometimes warns about converting 6350 // a value to bool (warning 4800). 6351 // 6352 // We cannot write 'return !!predicate_(x);' as that doesn't work 6353 // when predicate_(x) returns a class convertible to bool but 6354 // having no operator!(). 6355 if (predicate_(x)) 6356 return true; 6357 return false; 6358 } 6359 6360 void DescribeTo(::std::ostream* os) const { 6361 *os << "satisfies the given predicate"; 6362 } 6363 6364 void DescribeNegationTo(::std::ostream* os) const { 6365 *os << "doesn't satisfy the given predicate"; 6366 } 6367 6368 private: 6369 Predicate predicate_; 6370 6371 GTEST_DISALLOW_ASSIGN_(TrulyMatcher); 6372 }; 6373 6374 // Used for implementing Matches(matcher), which turns a matcher into 6375 // a predicate. 6376 template <typename M> 6377 class MatcherAsPredicate { 6378 public: 6379 explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {} 6380 6381 // This template operator() allows Matches(m) to be used as a 6382 // predicate on type T where m is a matcher on type T. 6383 // 6384 // The argument x is passed by reference instead of by value, as 6385 // some matcher may be interested in its address (e.g. as in 6386 // Matches(Ref(n))(x)). 6387 template <typename T> 6388 bool operator()(const T& x) const { 6389 // We let matcher_ commit to a particular type here instead of 6390 // when the MatcherAsPredicate object was constructed. This 6391 // allows us to write Matches(m) where m is a polymorphic matcher 6392 // (e.g. Eq(5)). 6393 // 6394 // If we write Matcher<T>(matcher_).Matches(x) here, it won't 6395 // compile when matcher_ has type Matcher<const T&>; if we write 6396 // Matcher<const T&>(matcher_).Matches(x) here, it won't compile 6397 // when matcher_ has type Matcher<T>; if we just write 6398 // matcher_.Matches(x), it won't compile when matcher_ is 6399 // polymorphic, e.g. Eq(5). 6400 // 6401 // MatcherCast<const T&>() is necessary for making the code work 6402 // in all of the above situations. 6403 return MatcherCast<const T&>(matcher_).Matches(x); 6404 } 6405 6406 private: 6407 M matcher_; 6408 6409 GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate); 6410 }; 6411 6412 // For implementing ASSERT_THAT() and EXPECT_THAT(). The template 6413 // argument M must be a type that can be converted to a matcher. 6414 template <typename M> 6415 class PredicateFormatterFromMatcher { 6416 public: 6417 explicit PredicateFormatterFromMatcher(const M& m) : matcher_(m) {} 6418 6419 // This template () operator allows a PredicateFormatterFromMatcher 6420 // object to act as a predicate-formatter suitable for using with 6421 // Google Test's EXPECT_PRED_FORMAT1() macro. 6422 template <typename T> 6423 AssertionResult operator()(const char* value_text, const T& x) const { 6424 // We convert matcher_ to a Matcher<const T&> *now* instead of 6425 // when the PredicateFormatterFromMatcher object was constructed, 6426 // as matcher_ may be polymorphic (e.g. NotNull()) and we won't 6427 // know which type to instantiate it to until we actually see the 6428 // type of x here. 6429 // 6430 // We write SafeMatcherCast<const T&>(matcher_) instead of 6431 // Matcher<const T&>(matcher_), as the latter won't compile when 6432 // matcher_ has type Matcher<T> (e.g. An<int>()). 6433 // We don't write MatcherCast<const T&> either, as that allows 6434 // potentially unsafe downcasting of the matcher argument. 6435 const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_); 6436 StringMatchResultListener listener; 6437 if (MatchPrintAndExplain(x, matcher, &listener)) 6438 return AssertionSuccess(); 6439 6440 ::std::stringstream ss; 6441 ss << "Value of: " << value_text << "\n" 6442 << "Expected: "; 6443 matcher.DescribeTo(&ss); 6444 ss << "\n Actual: " << listener.str(); 6445 return AssertionFailure() << ss.str(); 6446 } 6447 6448 private: 6449 const M matcher_; 6450 6451 GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher); 6452 }; 6453 6454 // A helper function for converting a matcher to a predicate-formatter 6455 // without the user needing to explicitly write the type. This is 6456 // used for implementing ASSERT_THAT() and EXPECT_THAT(). 6457 template <typename M> 6458 inline PredicateFormatterFromMatcher<M> 6459 MakePredicateFormatterFromMatcher(const M& matcher) { 6460 return PredicateFormatterFromMatcher<M>(matcher); 6461 } 6462 6463 // Implements the polymorphic floating point equality matcher, which matches 6464 // two float values using ULP-based approximation or, optionally, a 6465 // user-specified epsilon. The template is meant to be instantiated with 6466 // FloatType being either float or double. 6467 template <typename FloatType> 6468 class FloatingEqMatcher { 6469 public: 6470 // Constructor for FloatingEqMatcher. 6471 // The matcher's input will be compared with rhs. The matcher treats two 6472 // NANs as equal if nan_eq_nan is true. Otherwise, under IEEE standards, 6473 // equality comparisons between NANs will always return false. We specify a 6474 // negative max_abs_error_ term to indicate that ULP-based approximation will 6475 // be used for comparison. 6476 FloatingEqMatcher(FloatType rhs, bool nan_eq_nan) : 6477 rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) { 6478 } 6479 6480 // Constructor that supports a user-specified max_abs_error that will be used 6481 // for comparison instead of ULP-based approximation. The max absolute 6482 // should be non-negative. 6483 FloatingEqMatcher(FloatType rhs, bool nan_eq_nan, FloatType max_abs_error) : 6484 rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(max_abs_error) { 6485 GTEST_CHECK_(max_abs_error >= 0) 6486 << ", where max_abs_error is" << max_abs_error; 6487 } 6488 6489 // Implements floating point equality matcher as a Matcher<T>. 6490 template <typename T> 6491 class Impl : public MatcherInterface<T> { 6492 public: 6493 Impl(FloatType rhs, bool nan_eq_nan, FloatType max_abs_error) : 6494 rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(max_abs_error) {} 6495 6496 virtual bool MatchAndExplain(T value, 6497 MatchResultListener* /* listener */) const { 6498 const FloatingPoint<FloatType> lhs(value), rhs(rhs_); 6499 6500 // Compares NaNs first, if nan_eq_nan_ is true. 6501 if (lhs.is_nan() || rhs.is_nan()) { 6502 if (lhs.is_nan() && rhs.is_nan()) { 6503 return nan_eq_nan_; 6504 } 6505 // One is nan; the other is not nan. 6506 return false; 6507 } 6508 if (HasMaxAbsError()) { 6509 // We perform an equality check so that inf will match inf, regardless 6510 // of error bounds. If the result of value - rhs_ would result in 6511 // overflow or if either value is inf, the default result is infinity, 6512 // which should only match if max_abs_error_ is also infinity. 6513 return value == rhs_ || fabs(value - rhs_) <= max_abs_error_; 6514 } else { 6515 return lhs.AlmostEquals(rhs); 6516 } 6517 } 6518 6519 virtual void DescribeTo(::std::ostream* os) const { 6520 // os->precision() returns the previously set precision, which we 6521 // store to restore the ostream to its original configuration 6522 // after outputting. 6523 const ::std::streamsize old_precision = os->precision( 6524 ::std::numeric_limits<FloatType>::digits10 + 2); 6525 if (FloatingPoint<FloatType>(rhs_).is_nan()) { 6526 if (nan_eq_nan_) { 6527 *os << "is NaN"; 6528 } else { 6529 *os << "never matches"; 6530 } 6531 } else { 6532 *os << "is approximately " << rhs_; 6533 if (HasMaxAbsError()) { 6534 *os << " (absolute error <= " << max_abs_error_ << ")"; 6535 } 6536 } 6537 os->precision(old_precision); 6538 } 6539 6540 virtual void DescribeNegationTo(::std::ostream* os) const { 6541 // As before, get original precision. 6542 const ::std::streamsize old_precision = os->precision( 6543 ::std::numeric_limits<FloatType>::digits10 + 2); 6544 if (FloatingPoint<FloatType>(rhs_).is_nan()) { 6545 if (nan_eq_nan_) { 6546 *os << "isn't NaN"; 6547 } else { 6548 *os << "is anything"; 6549 } 6550 } else { 6551 *os << "isn't approximately " << rhs_; 6552 if (HasMaxAbsError()) { 6553 *os << " (absolute error > " << max_abs_error_ << ")"; 6554 } 6555 } 6556 // Restore original precision. 6557 os->precision(old_precision); 6558 } 6559 6560 private: 6561 bool HasMaxAbsError() const { 6562 return max_abs_error_ >= 0; 6563 } 6564 6565 const FloatType rhs_; 6566 const bool nan_eq_nan_; 6567 // max_abs_error will be used for value comparison when >= 0. 6568 const FloatType max_abs_error_; 6569 6570 GTEST_DISALLOW_ASSIGN_(Impl); 6571 }; 6572 6573 // The following 3 type conversion operators allow FloatEq(rhs) and 6574 // NanSensitiveFloatEq(rhs) to be used as a Matcher<float>, a 6575 // Matcher<const float&>, or a Matcher<float&>, but nothing else. 6576 // (While Google's C++ coding style doesn't allow arguments passed 6577 // by non-const reference, we may see them in code not conforming to 6578 // the style. Therefore Google Mock needs to support them.) 6579 operator Matcher<FloatType>() const { 6580 return MakeMatcher(new Impl<FloatType>(rhs_, nan_eq_nan_, max_abs_error_)); 6581 } 6582 6583 operator Matcher<const FloatType&>() const { 6584 return MakeMatcher( 6585 new Impl<const FloatType&>(rhs_, nan_eq_nan_, max_abs_error_)); 6586 } 6587 6588 operator Matcher<FloatType&>() const { 6589 return MakeMatcher(new Impl<FloatType&>(rhs_, nan_eq_nan_, max_abs_error_)); 6590 } 6591 6592 private: 6593 const FloatType rhs_; 6594 const bool nan_eq_nan_; 6595 // max_abs_error will be used for value comparison when >= 0. 6596 const FloatType max_abs_error_; 6597 6598 GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher); 6599 }; 6600 6601 // Implements the Pointee(m) matcher for matching a pointer whose 6602 // pointee matches matcher m. The pointer can be either raw or smart. 6603 template <typename InnerMatcher> 6604 class PointeeMatcher { 6605 public: 6606 explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {} 6607 6608 // This type conversion operator template allows Pointee(m) to be 6609 // used as a matcher for any pointer type whose pointee type is 6610 // compatible with the inner matcher, where type Pointer can be 6611 // either a raw pointer or a smart pointer. 6612 // 6613 // The reason we do this instead of relying on 6614 // MakePolymorphicMatcher() is that the latter is not flexible 6615 // enough for implementing the DescribeTo() method of Pointee(). 6616 template <typename Pointer> 6617 operator Matcher<Pointer>() const { 6618 return MakeMatcher(new Impl<Pointer>(matcher_)); 6619 } 6620 6621 private: 6622 // The monomorphic implementation that works for a particular pointer type. 6623 template <typename Pointer> 6624 class Impl : public MatcherInterface<Pointer> { 6625 public: 6626 typedef typename PointeeOf<GTEST_REMOVE_CONST_( // NOLINT 6627 GTEST_REMOVE_REFERENCE_(Pointer))>::type Pointee; 6628 6629 explicit Impl(const InnerMatcher& matcher) 6630 : matcher_(MatcherCast<const Pointee&>(matcher)) {} 6631 6632 virtual void DescribeTo(::std::ostream* os) const { 6633 *os << "points to a value that "; 6634 matcher_.DescribeTo(os); 6635 } 6636 6637 virtual void DescribeNegationTo(::std::ostream* os) const { 6638 *os << "does not point to a value that "; 6639 matcher_.DescribeTo(os); 6640 } 6641 6642 virtual bool MatchAndExplain(Pointer pointer, 6643 MatchResultListener* listener) const { 6644 if (GetRawPointer(pointer) == NULL) 6645 return false; 6646 6647 *listener << "which points to "; 6648 return MatchPrintAndExplain(*pointer, matcher_, listener); 6649 } 6650 6651 private: 6652 const Matcher<const Pointee&> matcher_; 6653 6654 GTEST_DISALLOW_ASSIGN_(Impl); 6655 }; 6656 6657 const InnerMatcher matcher_; 6658 6659 GTEST_DISALLOW_ASSIGN_(PointeeMatcher); 6660 }; 6661 6662 // Implements the Field() matcher for matching a field (i.e. member 6663 // variable) of an object. 6664 template <typename Class, typename FieldType> 6665 class FieldMatcher { 6666 public: 6667 FieldMatcher(FieldType Class::*field, 6668 const Matcher<const FieldType&>& matcher) 6669 : field_(field), matcher_(matcher) {} 6670 6671 void DescribeTo(::std::ostream* os) const { 6672 *os << "is an object whose given field "; 6673 matcher_.DescribeTo(os); 6674 } 6675 6676 void DescribeNegationTo(::std::ostream* os) const { 6677 *os << "is an object whose given field "; 6678 matcher_.DescribeNegationTo(os); 6679 } 6680 6681 template <typename T> 6682 bool MatchAndExplain(const T& value, MatchResultListener* listener) const { 6683 return MatchAndExplainImpl( 6684 typename ::testing::internal:: 6685 is_pointer<GTEST_REMOVE_CONST_(T)>::type(), 6686 value, listener); 6687 } 6688 6689 private: 6690 // The first argument of MatchAndExplainImpl() is needed to help 6691 // Symbian's C++ compiler choose which overload to use. Its type is 6692 // true_type iff the Field() matcher is used to match a pointer. 6693 bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, 6694 MatchResultListener* listener) const { 6695 *listener << "whose given field is "; 6696 return MatchPrintAndExplain(obj.*field_, matcher_, listener); 6697 } 6698 6699 bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, 6700 MatchResultListener* listener) const { 6701 if (p == NULL) 6702 return false; 6703 6704 *listener << "which points to an object "; 6705 // Since *p has a field, it must be a class/struct/union type and 6706 // thus cannot be a pointer. Therefore we pass false_type() as 6707 // the first argument. 6708 return MatchAndExplainImpl(false_type(), *p, listener); 6709 } 6710 6711 const FieldType Class::*field_; 6712 const Matcher<const FieldType&> matcher_; 6713 6714 GTEST_DISALLOW_ASSIGN_(FieldMatcher); 6715 }; 6716 6717 // Implements the Property() matcher for matching a property 6718 // (i.e. return value of a getter method) of an object. 6719 template <typename Class, typename PropertyType> 6720 class PropertyMatcher { 6721 public: 6722 // The property may have a reference type, so 'const PropertyType&' 6723 // may cause double references and fail to compile. That's why we 6724 // need GTEST_REFERENCE_TO_CONST, which works regardless of 6725 // PropertyType being a reference or not. 6726 typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty; 6727 6728 PropertyMatcher(PropertyType (Class::*property)() const, 6729 const Matcher<RefToConstProperty>& matcher) 6730 : property_(property), matcher_(matcher) {} 6731 6732 void DescribeTo(::std::ostream* os) const { 6733 *os << "is an object whose given property "; 6734 matcher_.DescribeTo(os); 6735 } 6736 6737 void DescribeNegationTo(::std::ostream* os) const { 6738 *os << "is an object whose given property "; 6739 matcher_.DescribeNegationTo(os); 6740 } 6741 6742 template <typename T> 6743 bool MatchAndExplain(const T&value, MatchResultListener* listener) const { 6744 return MatchAndExplainImpl( 6745 typename ::testing::internal:: 6746 is_pointer<GTEST_REMOVE_CONST_(T)>::type(), 6747 value, listener); 6748 } 6749 6750 private: 6751 // The first argument of MatchAndExplainImpl() is needed to help 6752 // Symbian's C++ compiler choose which overload to use. Its type is 6753 // true_type iff the Property() matcher is used to match a pointer. 6754 bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, 6755 MatchResultListener* listener) const { 6756 *listener << "whose given property is "; 6757 // Cannot pass the return value (for example, int) to MatchPrintAndExplain, 6758 // which takes a non-const reference as argument. 6759 RefToConstProperty result = (obj.*property_)(); 6760 return MatchPrintAndExplain(result, matcher_, listener); 6761 } 6762 6763 bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, 6764 MatchResultListener* listener) const { 6765 if (p == NULL) 6766 return false; 6767 6768 *listener << "which points to an object "; 6769 // Since *p has a property method, it must be a class/struct/union 6770 // type and thus cannot be a pointer. Therefore we pass 6771 // false_type() as the first argument. 6772 return MatchAndExplainImpl(false_type(), *p, listener); 6773 } 6774 6775 PropertyType (Class::*property_)() const; 6776 const Matcher<RefToConstProperty> matcher_; 6777 6778 GTEST_DISALLOW_ASSIGN_(PropertyMatcher); 6779 }; 6780 6781 // Type traits specifying various features of different functors for ResultOf. 6782 // The default template specifies features for functor objects. 6783 // Functor classes have to typedef argument_type and result_type 6784 // to be compatible with ResultOf. 6785 template <typename Functor> 6786 struct CallableTraits { 6787 typedef typename Functor::result_type ResultType; 6788 typedef Functor StorageType; 6789 6790 static void CheckIsValid(Functor /* functor */) {} 6791 template <typename T> 6792 static ResultType Invoke(Functor f, T arg) { return f(arg); } 6793 }; 6794 6795 // Specialization for function pointers. 6796 template <typename ArgType, typename ResType> 6797 struct CallableTraits<ResType(*)(ArgType)> { 6798 typedef ResType ResultType; 6799 typedef ResType(*StorageType)(ArgType); 6800 6801 static void CheckIsValid(ResType(*f)(ArgType)) { 6802 GTEST_CHECK_(f != NULL) 6803 << "NULL function pointer is passed into ResultOf()."; 6804 } 6805 template <typename T> 6806 static ResType Invoke(ResType(*f)(ArgType), T arg) { 6807 return (*f)(arg); 6808 } 6809 }; 6810 6811 // Implements the ResultOf() matcher for matching a return value of a 6812 // unary function of an object. 6813 template <typename Callable> 6814 class ResultOfMatcher { 6815 public: 6816 typedef typename CallableTraits<Callable>::ResultType ResultType; 6817 6818 ResultOfMatcher(Callable callable, const Matcher<ResultType>& matcher) 6819 : callable_(callable), matcher_(matcher) { 6820 CallableTraits<Callable>::CheckIsValid(callable_); 6821 } 6822 6823 template <typename T> 6824 operator Matcher<T>() const { 6825 return Matcher<T>(new Impl<T>(callable_, matcher_)); 6826 } 6827 6828 private: 6829 typedef typename CallableTraits<Callable>::StorageType CallableStorageType; 6830 6831 template <typename T> 6832 class Impl : public MatcherInterface<T> { 6833 public: 6834 Impl(CallableStorageType callable, const Matcher<ResultType>& matcher) 6835 : callable_(callable), matcher_(matcher) {} 6836 6837 virtual void DescribeTo(::std::ostream* os) const { 6838 *os << "is mapped by the given callable to a value that "; 6839 matcher_.DescribeTo(os); 6840 } 6841 6842 virtual void DescribeNegationTo(::std::ostream* os) const { 6843 *os << "is mapped by the given callable to a value that "; 6844 matcher_.DescribeNegationTo(os); 6845 } 6846 6847 virtual bool MatchAndExplain(T obj, MatchResultListener* listener) const { 6848 *listener << "which is mapped by the given callable to "; 6849 // Cannot pass the return value (for example, int) to 6850 // MatchPrintAndExplain, which takes a non-const reference as argument. 6851 ResultType result = 6852 CallableTraits<Callable>::template Invoke<T>(callable_, obj); 6853 return MatchPrintAndExplain(result, matcher_, listener); 6854 } 6855 6856 private: 6857 // Functors often define operator() as non-const method even though 6858 // they are actualy stateless. But we need to use them even when 6859 // 'this' is a const pointer. It's the user's responsibility not to 6860 // use stateful callables with ResultOf(), which does't guarantee 6861 // how many times the callable will be invoked. 6862 mutable CallableStorageType callable_; 6863 const Matcher<ResultType> matcher_; 6864 6865 GTEST_DISALLOW_ASSIGN_(Impl); 6866 }; // class Impl 6867 6868 const CallableStorageType callable_; 6869 const Matcher<ResultType> matcher_; 6870 6871 GTEST_DISALLOW_ASSIGN_(ResultOfMatcher); 6872 }; 6873 6874 // Implements a matcher that checks the size of an STL-style container. 6875 template <typename SizeMatcher> 6876 class SizeIsMatcher { 6877 public: 6878 explicit SizeIsMatcher(const SizeMatcher& size_matcher) 6879 : size_matcher_(size_matcher) { 6880 } 6881 6882 template <typename Container> 6883 operator Matcher<Container>() const { 6884 return MakeMatcher(new Impl<Container>(size_matcher_)); 6885 } 6886 6887 template <typename Container> 6888 class Impl : public MatcherInterface<Container> { 6889 public: 6890 typedef internal::StlContainerView< 6891 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView; 6892 typedef typename ContainerView::type::size_type SizeType; 6893 explicit Impl(const SizeMatcher& size_matcher) 6894 : size_matcher_(MatcherCast<SizeType>(size_matcher)) {} 6895 6896 virtual void DescribeTo(::std::ostream* os) const { 6897 *os << "size "; 6898 size_matcher_.DescribeTo(os); 6899 } 6900 virtual void DescribeNegationTo(::std::ostream* os) const { 6901 *os << "size "; 6902 size_matcher_.DescribeNegationTo(os); 6903 } 6904 6905 virtual bool MatchAndExplain(Container container, 6906 MatchResultListener* listener) const { 6907 SizeType size = container.size(); 6908 StringMatchResultListener size_listener; 6909 const bool result = size_matcher_.MatchAndExplain(size, &size_listener); 6910 *listener 6911 << "whose size " << size << (result ? " matches" : " doesn't match"); 6912 PrintIfNotEmpty(size_listener.str(), listener->stream()); 6913 return result; 6914 } 6915 6916 private: 6917 const Matcher<SizeType> size_matcher_; 6918 GTEST_DISALLOW_ASSIGN_(Impl); 6919 }; 6920 6921 private: 6922 const SizeMatcher size_matcher_; 6923 GTEST_DISALLOW_ASSIGN_(SizeIsMatcher); 6924 }; 6925 6926 // Implements an equality matcher for any STL-style container whose elements 6927 // support ==. This matcher is like Eq(), but its failure explanations provide 6928 // more detailed information that is useful when the container is used as a set. 6929 // The failure message reports elements that are in one of the operands but not 6930 // the other. The failure messages do not report duplicate or out-of-order 6931 // elements in the containers (which don't properly matter to sets, but can 6932 // occur if the containers are vectors or lists, for example). 6933 // 6934 // Uses the container's const_iterator, value_type, operator ==, 6935 // begin(), and end(). 6936 template <typename Container> 6937 class ContainerEqMatcher { 6938 public: 6939 typedef internal::StlContainerView<Container> View; 6940 typedef typename View::type StlContainer; 6941 typedef typename View::const_reference StlContainerReference; 6942 6943 // We make a copy of rhs in case the elements in it are modified 6944 // after this matcher is created. 6945 explicit ContainerEqMatcher(const Container& rhs) : rhs_(View::Copy(rhs)) { 6946 // Makes sure the user doesn't instantiate this class template 6947 // with a const or reference type. 6948 (void)testing::StaticAssertTypeEq<Container, 6949 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>(); 6950 } 6951 6952 void DescribeTo(::std::ostream* os) const { 6953 *os << "equals "; 6954 UniversalPrint(rhs_, os); 6955 } 6956 void DescribeNegationTo(::std::ostream* os) const { 6957 *os << "does not equal "; 6958 UniversalPrint(rhs_, os); 6959 } 6960 6961 template <typename LhsContainer> 6962 bool MatchAndExplain(const LhsContainer& lhs, 6963 MatchResultListener* listener) const { 6964 // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug 6965 // that causes LhsContainer to be a const type sometimes. 6966 typedef internal::StlContainerView<GTEST_REMOVE_CONST_(LhsContainer)> 6967 LhsView; 6968 typedef typename LhsView::type LhsStlContainer; 6969 StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); 6970 if (lhs_stl_container == rhs_) 6971 return true; 6972 6973 ::std::ostream* const os = listener->stream(); 6974 if (os != NULL) { 6975 // Something is different. Check for extra values first. 6976 bool printed_header = false; 6977 for (typename LhsStlContainer::const_iterator it = 6978 lhs_stl_container.begin(); 6979 it != lhs_stl_container.end(); ++it) { 6980 if (internal::ArrayAwareFind(rhs_.begin(), rhs_.end(), *it) == 6981 rhs_.end()) { 6982 if (printed_header) { 6983 *os << ", "; 6984 } else { 6985 *os << "which has these unexpected elements: "; 6986 printed_header = true; 6987 } 6988 UniversalPrint(*it, os); 6989 } 6990 } 6991 6992 // Now check for missing values. 6993 bool printed_header2 = false; 6994 for (typename StlContainer::const_iterator it = rhs_.begin(); 6995 it != rhs_.end(); ++it) { 6996 if (internal::ArrayAwareFind( 6997 lhs_stl_container.begin(), lhs_stl_container.end(), *it) == 6998 lhs_stl_container.end()) { 6999 if (printed_header2) { 7000 *os << ", "; 7001 } else { 7002 *os << (printed_header ? ",\nand" : "which") 7003 << " doesn't have these expected elements: "; 7004 printed_header2 = true; 7005 } 7006 UniversalPrint(*it, os); 7007 } 7008 } 7009 } 7010 7011 return false; 7012 } 7013 7014 private: 7015 const StlContainer rhs_; 7016 7017 GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher); 7018 }; 7019 7020 // A comparator functor that uses the < operator to compare two values. 7021 struct LessComparator { 7022 template <typename T, typename U> 7023 bool operator()(const T& lhs, const U& rhs) const { return lhs < rhs; } 7024 }; 7025 7026 // Implements WhenSortedBy(comparator, container_matcher). 7027 template <typename Comparator, typename ContainerMatcher> 7028 class WhenSortedByMatcher { 7029 public: 7030 WhenSortedByMatcher(const Comparator& comparator, 7031 const ContainerMatcher& matcher) 7032 : comparator_(comparator), matcher_(matcher) {} 7033 7034 template <typename LhsContainer> 7035 operator Matcher<LhsContainer>() const { 7036 return MakeMatcher(new Impl<LhsContainer>(comparator_, matcher_)); 7037 } 7038 7039 template <typename LhsContainer> 7040 class Impl : public MatcherInterface<LhsContainer> { 7041 public: 7042 typedef internal::StlContainerView< 7043 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView; 7044 typedef typename LhsView::type LhsStlContainer; 7045 typedef typename LhsView::const_reference LhsStlContainerReference; 7046 // Transforms std::pair<const Key, Value> into std::pair<Key, Value> 7047 // so that we can match associative containers. 7048 typedef typename RemoveConstFromKey< 7049 typename LhsStlContainer::value_type>::type LhsValue; 7050 7051 Impl(const Comparator& comparator, const ContainerMatcher& matcher) 7052 : comparator_(comparator), matcher_(matcher) {} 7053 7054 virtual void DescribeTo(::std::ostream* os) const { 7055 *os << "(when sorted) "; 7056 matcher_.DescribeTo(os); 7057 } 7058 7059 virtual void DescribeNegationTo(::std::ostream* os) const { 7060 *os << "(when sorted) "; 7061 matcher_.DescribeNegationTo(os); 7062 } 7063 7064 virtual bool MatchAndExplain(LhsContainer lhs, 7065 MatchResultListener* listener) const { 7066 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); 7067 ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(), 7068 lhs_stl_container.end()); 7069 ::std::sort( 7070 sorted_container.begin(), sorted_container.end(), comparator_); 7071 7072 if (!listener->IsInterested()) { 7073 // If the listener is not interested, we do not need to 7074 // construct the inner explanation. 7075 return matcher_.Matches(sorted_container); 7076 } 7077 7078 *listener << "which is "; 7079 UniversalPrint(sorted_container, listener->stream()); 7080 *listener << " when sorted"; 7081 7082 StringMatchResultListener inner_listener; 7083 const bool match = matcher_.MatchAndExplain(sorted_container, 7084 &inner_listener); 7085 PrintIfNotEmpty(inner_listener.str(), listener->stream()); 7086 return match; 7087 } 7088 7089 private: 7090 const Comparator comparator_; 7091 const Matcher<const ::std::vector<LhsValue>&> matcher_; 7092 7093 GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl); 7094 }; 7095 7096 private: 7097 const Comparator comparator_; 7098 const ContainerMatcher matcher_; 7099 7100 GTEST_DISALLOW_ASSIGN_(WhenSortedByMatcher); 7101 }; 7102 7103 // Implements Pointwise(tuple_matcher, rhs_container). tuple_matcher 7104 // must be able to be safely cast to Matcher<tuple<const T1&, const 7105 // T2&> >, where T1 and T2 are the types of elements in the LHS 7106 // container and the RHS container respectively. 7107 template <typename TupleMatcher, typename RhsContainer> 7108 class PointwiseMatcher { 7109 public: 7110 typedef internal::StlContainerView<RhsContainer> RhsView; 7111 typedef typename RhsView::type RhsStlContainer; 7112 typedef typename RhsStlContainer::value_type RhsValue; 7113 7114 // Like ContainerEq, we make a copy of rhs in case the elements in 7115 // it are modified after this matcher is created. 7116 PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs) 7117 : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) { 7118 // Makes sure the user doesn't instantiate this class template 7119 // with a const or reference type. 7120 (void)testing::StaticAssertTypeEq<RhsContainer, 7121 GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>(); 7122 } 7123 7124 template <typename LhsContainer> 7125 operator Matcher<LhsContainer>() const { 7126 return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_)); 7127 } 7128 7129 template <typename LhsContainer> 7130 class Impl : public MatcherInterface<LhsContainer> { 7131 public: 7132 typedef internal::StlContainerView< 7133 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView; 7134 typedef typename LhsView::type LhsStlContainer; 7135 typedef typename LhsView::const_reference LhsStlContainerReference; 7136 typedef typename LhsStlContainer::value_type LhsValue; 7137 // We pass the LHS value and the RHS value to the inner matcher by 7138 // reference, as they may be expensive to copy. We must use tuple 7139 // instead of pair here, as a pair cannot hold references (C++ 98, 7140 // 20.2.2 [lib.pairs]). 7141 typedef ::std::tr1::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg; 7142 7143 Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs) 7144 // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher. 7145 : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)), 7146 rhs_(rhs) {} 7147 7148 virtual void DescribeTo(::std::ostream* os) const { 7149 *os << "contains " << rhs_.size() 7150 << " values, where each value and its corresponding value in "; 7151 UniversalPrinter<RhsStlContainer>::Print(rhs_, os); 7152 *os << " "; 7153 mono_tuple_matcher_.DescribeTo(os); 7154 } 7155 virtual void DescribeNegationTo(::std::ostream* os) const { 7156 *os << "doesn't contain exactly " << rhs_.size() 7157 << " values, or contains a value x at some index i" 7158 << " where x and the i-th value of "; 7159 UniversalPrint(rhs_, os); 7160 *os << " "; 7161 mono_tuple_matcher_.DescribeNegationTo(os); 7162 } 7163 7164 virtual bool MatchAndExplain(LhsContainer lhs, 7165 MatchResultListener* listener) const { 7166 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); 7167 const size_t actual_size = lhs_stl_container.size(); 7168 if (actual_size != rhs_.size()) { 7169 *listener << "which contains " << actual_size << " values"; 7170 return false; 7171 } 7172 7173 typename LhsStlContainer::const_iterator left = lhs_stl_container.begin(); 7174 typename RhsStlContainer::const_iterator right = rhs_.begin(); 7175 for (size_t i = 0; i != actual_size; ++i, ++left, ++right) { 7176 const InnerMatcherArg value_pair(*left, *right); 7177 7178 if (listener->IsInterested()) { 7179 StringMatchResultListener inner_listener; 7180 if (!mono_tuple_matcher_.MatchAndExplain( 7181 value_pair, &inner_listener)) { 7182 *listener << "where the value pair ("; 7183 UniversalPrint(*left, listener->stream()); 7184 *listener << ", "; 7185 UniversalPrint(*right, listener->stream()); 7186 *listener << ") at index #" << i << " don't match"; 7187 PrintIfNotEmpty(inner_listener.str(), listener->stream()); 7188 return false; 7189 } 7190 } else { 7191 if (!mono_tuple_matcher_.Matches(value_pair)) 7192 return false; 7193 } 7194 } 7195 7196 return true; 7197 } 7198 7199 private: 7200 const Matcher<InnerMatcherArg> mono_tuple_matcher_; 7201 const RhsStlContainer rhs_; 7202 7203 GTEST_DISALLOW_ASSIGN_(Impl); 7204 }; 7205 7206 private: 7207 const TupleMatcher tuple_matcher_; 7208 const RhsStlContainer rhs_; 7209 7210 GTEST_DISALLOW_ASSIGN_(PointwiseMatcher); 7211 }; 7212 7213 // Holds the logic common to ContainsMatcherImpl and EachMatcherImpl. 7214 template <typename Container> 7215 class QuantifierMatcherImpl : public MatcherInterface<Container> { 7216 public: 7217 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; 7218 typedef StlContainerView<RawContainer> View; 7219 typedef typename View::type StlContainer; 7220 typedef typename View::const_reference StlContainerReference; 7221 typedef typename StlContainer::value_type Element; 7222 7223 template <typename InnerMatcher> 7224 explicit QuantifierMatcherImpl(InnerMatcher inner_matcher) 7225 : inner_matcher_( 7226 testing::SafeMatcherCast<const Element&>(inner_matcher)) {} 7227 7228 // Checks whether: 7229 // * All elements in the container match, if all_elements_should_match. 7230 // * Any element in the container matches, if !all_elements_should_match. 7231 bool MatchAndExplainImpl(bool all_elements_should_match, 7232 Container container, 7233 MatchResultListener* listener) const { 7234 StlContainerReference stl_container = View::ConstReference(container); 7235 size_t i = 0; 7236 for (typename StlContainer::const_iterator it = stl_container.begin(); 7237 it != stl_container.end(); ++it, ++i) { 7238 StringMatchResultListener inner_listener; 7239 const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener); 7240 7241 if (matches != all_elements_should_match) { 7242 *listener << "whose element #" << i 7243 << (matches ? " matches" : " doesn't match"); 7244 PrintIfNotEmpty(inner_listener.str(), listener->stream()); 7245 return !all_elements_should_match; 7246 } 7247 } 7248 return all_elements_should_match; 7249 } 7250 7251 protected: 7252 const Matcher<const Element&> inner_matcher_; 7253 7254 GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl); 7255 }; 7256 7257 // Implements Contains(element_matcher) for the given argument type Container. 7258 // Symmetric to EachMatcherImpl. 7259 template <typename Container> 7260 class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> { 7261 public: 7262 template <typename InnerMatcher> 7263 explicit ContainsMatcherImpl(InnerMatcher inner_matcher) 7264 : QuantifierMatcherImpl<Container>(inner_matcher) {} 7265 7266 // Describes what this matcher does. 7267 virtual void DescribeTo(::std::ostream* os) const { 7268 *os << "contains at least one element that "; 7269 this->inner_matcher_.DescribeTo(os); 7270 } 7271 7272 virtual void DescribeNegationTo(::std::ostream* os) const { 7273 *os << "doesn't contain any element that "; 7274 this->inner_matcher_.DescribeTo(os); 7275 } 7276 7277 virtual bool MatchAndExplain(Container container, 7278 MatchResultListener* listener) const { 7279 return this->MatchAndExplainImpl(false, container, listener); 7280 } 7281 7282 private: 7283 GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl); 7284 }; 7285 7286 // Implements Each(element_matcher) for the given argument type Container. 7287 // Symmetric to ContainsMatcherImpl. 7288 template <typename Container> 7289 class EachMatcherImpl : public QuantifierMatcherImpl<Container> { 7290 public: 7291 template <typename InnerMatcher> 7292 explicit EachMatcherImpl(InnerMatcher inner_matcher) 7293 : QuantifierMatcherImpl<Container>(inner_matcher) {} 7294 7295 // Describes what this matcher does. 7296 virtual void DescribeTo(::std::ostream* os) const { 7297 *os << "only contains elements that "; 7298 this->inner_matcher_.DescribeTo(os); 7299 } 7300 7301 virtual void DescribeNegationTo(::std::ostream* os) const { 7302 *os << "contains some element that "; 7303 this->inner_matcher_.DescribeNegationTo(os); 7304 } 7305 7306 virtual bool MatchAndExplain(Container container, 7307 MatchResultListener* listener) const { 7308 return this->MatchAndExplainImpl(true, container, listener); 7309 } 7310 7311 private: 7312 GTEST_DISALLOW_ASSIGN_(EachMatcherImpl); 7313 }; 7314 7315 // Implements polymorphic Contains(element_matcher). 7316 template <typename M> 7317 class ContainsMatcher { 7318 public: 7319 explicit ContainsMatcher(M m) : inner_matcher_(m) {} 7320 7321 template <typename Container> 7322 operator Matcher<Container>() const { 7323 return MakeMatcher(new ContainsMatcherImpl<Container>(inner_matcher_)); 7324 } 7325 7326 private: 7327 const M inner_matcher_; 7328 7329 GTEST_DISALLOW_ASSIGN_(ContainsMatcher); 7330 }; 7331 7332 // Implements polymorphic Each(element_matcher). 7333 template <typename M> 7334 class EachMatcher { 7335 public: 7336 explicit EachMatcher(M m) : inner_matcher_(m) {} 7337 7338 template <typename Container> 7339 operator Matcher<Container>() const { 7340 return MakeMatcher(new EachMatcherImpl<Container>(inner_matcher_)); 7341 } 7342 7343 private: 7344 const M inner_matcher_; 7345 7346 GTEST_DISALLOW_ASSIGN_(EachMatcher); 7347 }; 7348 7349 // Implements Key(inner_matcher) for the given argument pair type. 7350 // Key(inner_matcher) matches an std::pair whose 'first' field matches 7351 // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an 7352 // std::map that contains at least one element whose key is >= 5. 7353 template <typename PairType> 7354 class KeyMatcherImpl : public MatcherInterface<PairType> { 7355 public: 7356 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType; 7357 typedef typename RawPairType::first_type KeyType; 7358 7359 template <typename InnerMatcher> 7360 explicit KeyMatcherImpl(InnerMatcher inner_matcher) 7361 : inner_matcher_( 7362 testing::SafeMatcherCast<const KeyType&>(inner_matcher)) { 7363 } 7364 7365 // Returns true iff 'key_value.first' (the key) matches the inner matcher. 7366 virtual bool MatchAndExplain(PairType key_value, 7367 MatchResultListener* listener) const { 7368 StringMatchResultListener inner_listener; 7369 const bool match = inner_matcher_.MatchAndExplain(key_value.first, 7370 &inner_listener); 7371 const internal::string explanation = inner_listener.str(); 7372 if (explanation != "") { 7373 *listener << "whose first field is a value " << explanation; 7374 } 7375 return match; 7376 } 7377 7378 // Describes what this matcher does. 7379 virtual void DescribeTo(::std::ostream* os) const { 7380 *os << "has a key that "; 7381 inner_matcher_.DescribeTo(os); 7382 } 7383 7384 // Describes what the negation of this matcher does. 7385 virtual void DescribeNegationTo(::std::ostream* os) const { 7386 *os << "doesn't have a key that "; 7387 inner_matcher_.DescribeTo(os); 7388 } 7389 7390 private: 7391 const Matcher<const KeyType&> inner_matcher_; 7392 7393 GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl); 7394 }; 7395 7396 // Implements polymorphic Key(matcher_for_key). 7397 template <typename M> 7398 class KeyMatcher { 7399 public: 7400 explicit KeyMatcher(M m) : matcher_for_key_(m) {} 7401 7402 template <typename PairType> 7403 operator Matcher<PairType>() const { 7404 return MakeMatcher(new KeyMatcherImpl<PairType>(matcher_for_key_)); 7405 } 7406 7407 private: 7408 const M matcher_for_key_; 7409 7410 GTEST_DISALLOW_ASSIGN_(KeyMatcher); 7411 }; 7412 7413 // Implements Pair(first_matcher, second_matcher) for the given argument pair 7414 // type with its two matchers. See Pair() function below. 7415 template <typename PairType> 7416 class PairMatcherImpl : public MatcherInterface<PairType> { 7417 public: 7418 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType; 7419 typedef typename RawPairType::first_type FirstType; 7420 typedef typename RawPairType::second_type SecondType; 7421 7422 template <typename FirstMatcher, typename SecondMatcher> 7423 PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher) 7424 : first_matcher_( 7425 testing::SafeMatcherCast<const FirstType&>(first_matcher)), 7426 second_matcher_( 7427 testing::SafeMatcherCast<const SecondType&>(second_matcher)) { 7428 } 7429 7430 // Describes what this matcher does. 7431 virtual void DescribeTo(::std::ostream* os) const { 7432 *os << "has a first field that "; 7433 first_matcher_.DescribeTo(os); 7434 *os << ", and has a second field that "; 7435 second_matcher_.DescribeTo(os); 7436 } 7437 7438 // Describes what the negation of this matcher does. 7439 virtual void DescribeNegationTo(::std::ostream* os) const { 7440 *os << "has a first field that "; 7441 first_matcher_.DescribeNegationTo(os); 7442 *os << ", or has a second field that "; 7443 second_matcher_.DescribeNegationTo(os); 7444 } 7445 7446 // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.second' 7447 // matches second_matcher. 7448 virtual bool MatchAndExplain(PairType a_pair, 7449 MatchResultListener* listener) const { 7450 if (!listener->IsInterested()) { 7451 // If the listener is not interested, we don't need to construct the 7452 // explanation. 7453 return first_matcher_.Matches(a_pair.first) && 7454 second_matcher_.Matches(a_pair.second); 7455 } 7456 StringMatchResultListener first_inner_listener; 7457 if (!first_matcher_.MatchAndExplain(a_pair.first, 7458 &first_inner_listener)) { 7459 *listener << "whose first field does not match"; 7460 PrintIfNotEmpty(first_inner_listener.str(), listener->stream()); 7461 return false; 7462 } 7463 StringMatchResultListener second_inner_listener; 7464 if (!second_matcher_.MatchAndExplain(a_pair.second, 7465 &second_inner_listener)) { 7466 *listener << "whose second field does not match"; 7467 PrintIfNotEmpty(second_inner_listener.str(), listener->stream()); 7468 return false; 7469 } 7470 ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(), 7471 listener); 7472 return true; 7473 } 7474 7475 private: 7476 void ExplainSuccess(const internal::string& first_explanation, 7477 const internal::string& second_explanation, 7478 MatchResultListener* listener) const { 7479 *listener << "whose both fields match"; 7480 if (first_explanation != "") { 7481 *listener << ", where the first field is a value " << first_explanation; 7482 } 7483 if (second_explanation != "") { 7484 *listener << ", "; 7485 if (first_explanation != "") { 7486 *listener << "and "; 7487 } else { 7488 *listener << "where "; 7489 } 7490 *listener << "the second field is a value " << second_explanation; 7491 } 7492 } 7493 7494 const Matcher<const FirstType&> first_matcher_; 7495 const Matcher<const SecondType&> second_matcher_; 7496 7497 GTEST_DISALLOW_ASSIGN_(PairMatcherImpl); 7498 }; 7499 7500 // Implements polymorphic Pair(first_matcher, second_matcher). 7501 template <typename FirstMatcher, typename SecondMatcher> 7502 class PairMatcher { 7503 public: 7504 PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher) 7505 : first_matcher_(first_matcher), second_matcher_(second_matcher) {} 7506 7507 template <typename PairType> 7508 operator Matcher<PairType> () const { 7509 return MakeMatcher( 7510 new PairMatcherImpl<PairType>( 7511 first_matcher_, second_matcher_)); 7512 } 7513 7514 private: 7515 const FirstMatcher first_matcher_; 7516 const SecondMatcher second_matcher_; 7517 7518 GTEST_DISALLOW_ASSIGN_(PairMatcher); 7519 }; 7520 7521 // Implements ElementsAre() and ElementsAreArray(). 7522 template <typename Container> 7523 class ElementsAreMatcherImpl : public MatcherInterface<Container> { 7524 public: 7525 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; 7526 typedef internal::StlContainerView<RawContainer> View; 7527 typedef typename View::type StlContainer; 7528 typedef typename View::const_reference StlContainerReference; 7529 typedef typename StlContainer::value_type Element; 7530 7531 // Constructs the matcher from a sequence of element values or 7532 // element matchers. 7533 template <typename InputIter> 7534 ElementsAreMatcherImpl(InputIter first, InputIter last) { 7535 while (first != last) { 7536 matchers_.push_back(MatcherCast<const Element&>(*first++)); 7537 } 7538 } 7539 7540 // Describes what this matcher does. 7541 virtual void DescribeTo(::std::ostream* os) const { 7542 if (count() == 0) { 7543 *os << "is empty"; 7544 } else if (count() == 1) { 7545 *os << "has 1 element that "; 7546 matchers_[0].DescribeTo(os); 7547 } else { 7548 *os << "has " << Elements(count()) << " where\n"; 7549 for (size_t i = 0; i != count(); ++i) { 7550 *os << "element #" << i << " "; 7551 matchers_[i].DescribeTo(os); 7552 if (i + 1 < count()) { 7553 *os << ",\n"; 7554 } 7555 } 7556 } 7557 } 7558 7559 // Describes what the negation of this matcher does. 7560 virtual void DescribeNegationTo(::std::ostream* os) const { 7561 if (count() == 0) { 7562 *os << "isn't empty"; 7563 return; 7564 } 7565 7566 *os << "doesn't have " << Elements(count()) << ", or\n"; 7567 for (size_t i = 0; i != count(); ++i) { 7568 *os << "element #" << i << " "; 7569 matchers_[i].DescribeNegationTo(os); 7570 if (i + 1 < count()) { 7571 *os << ", or\n"; 7572 } 7573 } 7574 } 7575 7576 virtual bool MatchAndExplain(Container container, 7577 MatchResultListener* listener) const { 7578 // To work with stream-like "containers", we must only walk 7579 // through the elements in one pass. 7580 7581 const bool listener_interested = listener->IsInterested(); 7582 7583 // explanations[i] is the explanation of the element at index i. 7584 ::std::vector<internal::string> explanations(count()); 7585 StlContainerReference stl_container = View::ConstReference(container); 7586 typename StlContainer::const_iterator it = stl_container.begin(); 7587 size_t exam_pos = 0; 7588 bool mismatch_found = false; // Have we found a mismatched element yet? 7589 7590 // Go through the elements and matchers in pairs, until we reach 7591 // the end of either the elements or the matchers, or until we find a 7592 // mismatch. 7593 for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) { 7594 bool match; // Does the current element match the current matcher? 7595 if (listener_interested) { 7596 StringMatchResultListener s; 7597 match = matchers_[exam_pos].MatchAndExplain(*it, &s); 7598 explanations[exam_pos] = s.str(); 7599 } else { 7600 match = matchers_[exam_pos].Matches(*it); 7601 } 7602 7603 if (!match) { 7604 mismatch_found = true; 7605 break; 7606 } 7607 } 7608 // If mismatch_found is true, 'exam_pos' is the index of the mismatch. 7609 7610 // Find how many elements the actual container has. We avoid 7611 // calling size() s.t. this code works for stream-like "containers" 7612 // that don't define size(). 7613 size_t actual_count = exam_pos; 7614 for (; it != stl_container.end(); ++it) { 7615 ++actual_count; 7616 } 7617 7618 if (actual_count != count()) { 7619 // The element count doesn't match. If the container is empty, 7620 // there's no need to explain anything as Google Mock already 7621 // prints the empty container. Otherwise we just need to show 7622 // how many elements there actually are. 7623 if (listener_interested && (actual_count != 0)) { 7624 *listener << "which has " << Elements(actual_count); 7625 } 7626 return false; 7627 } 7628 7629 if (mismatch_found) { 7630 // The element count matches, but the exam_pos-th element doesn't match. 7631 if (listener_interested) { 7632 *listener << "whose element #" << exam_pos << " doesn't match"; 7633 PrintIfNotEmpty(explanations[exam_pos], listener->stream()); 7634 } 7635 return false; 7636 } 7637 7638 // Every element matches its expectation. We need to explain why 7639 // (the obvious ones can be skipped). 7640 if (listener_interested) { 7641 bool reason_printed = false; 7642 for (size_t i = 0; i != count(); ++i) { 7643 const internal::string& s = explanations[i]; 7644 if (!s.empty()) { 7645 if (reason_printed) { 7646 *listener << ",\nand "; 7647 } 7648 *listener << "whose element #" << i << " matches, " << s; 7649 reason_printed = true; 7650 } 7651 } 7652 } 7653 return true; 7654 } 7655 7656 private: 7657 static Message Elements(size_t count) { 7658 return Message() << count << (count == 1 ? " element" : " elements"); 7659 } 7660 7661 size_t count() const { return matchers_.size(); } 7662 7663 ::std::vector<Matcher<const Element&> > matchers_; 7664 7665 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl); 7666 }; 7667 7668 // Connectivity matrix of (elements X matchers), in element-major order. 7669 // Initially, there are no edges. 7670 // Use NextGraph() to iterate over all possible edge configurations. 7671 // Use Randomize() to generate a random edge configuration. 7672 class GTEST_API_ MatchMatrix { 7673 public: 7674 MatchMatrix(size_t num_elements, size_t num_matchers) 7675 : num_elements_(num_elements), 7676 num_matchers_(num_matchers), 7677 matched_(num_elements_* num_matchers_, 0) { 7678 } 7679 7680 size_t LhsSize() const { return num_elements_; } 7681 size_t RhsSize() const { return num_matchers_; } 7682 bool HasEdge(size_t ilhs, size_t irhs) const { 7683 return matched_[SpaceIndex(ilhs, irhs)] == 1; 7684 } 7685 void SetEdge(size_t ilhs, size_t irhs, bool b) { 7686 matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0; 7687 } 7688 7689 // Treating the connectivity matrix as a (LhsSize()*RhsSize())-bit number, 7690 // adds 1 to that number; returns false if incrementing the graph left it 7691 // empty. 7692 bool NextGraph(); 7693 7694 void Randomize(); 7695 7696 string DebugString() const; 7697 7698 private: 7699 size_t SpaceIndex(size_t ilhs, size_t irhs) const { 7700 return ilhs * num_matchers_ + irhs; 7701 } 7702 7703 size_t num_elements_; 7704 size_t num_matchers_; 7705 7706 // Each element is a char interpreted as bool. They are stored as a 7707 // flattened array in lhs-major order, use 'SpaceIndex()' to translate 7708 // a (ilhs, irhs) matrix coordinate into an offset. 7709 ::std::vector<char> matched_; 7710 }; 7711 7712 typedef ::std::pair<size_t, size_t> ElementMatcherPair; 7713 typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs; 7714 7715 // Returns a maximum bipartite matching for the specified graph 'g'. 7716 // The matching is represented as a vector of {element, matcher} pairs. 7717 GTEST_API_ ElementMatcherPairs 7718 FindMaxBipartiteMatching(const MatchMatrix& g); 7719 7720 GTEST_API_ bool FindPairing(const MatchMatrix& matrix, 7721 MatchResultListener* listener); 7722 7723 // Untyped base class for implementing UnorderedElementsAre. By 7724 // putting logic that's not specific to the element type here, we 7725 // reduce binary bloat and increase compilation speed. 7726 class GTEST_API_ UnorderedElementsAreMatcherImplBase { 7727 protected: 7728 // A vector of matcher describers, one for each element matcher. 7729 // Does not own the describers (and thus can be used only when the 7730 // element matchers are alive). 7731 typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec; 7732 7733 // Describes this UnorderedElementsAre matcher. 7734 void DescribeToImpl(::std::ostream* os) const; 7735 7736 // Describes the negation of this UnorderedElementsAre matcher. 7737 void DescribeNegationToImpl(::std::ostream* os) const; 7738 7739 bool VerifyAllElementsAndMatchersAreMatched( 7740 const ::std::vector<string>& element_printouts, 7741 const MatchMatrix& matrix, 7742 MatchResultListener* listener) const; 7743 7744 MatcherDescriberVec& matcher_describers() { 7745 return matcher_describers_; 7746 } 7747 7748 static Message Elements(size_t n) { 7749 return Message() << n << " element" << (n == 1 ? "" : "s"); 7750 } 7751 7752 private: 7753 MatcherDescriberVec matcher_describers_; 7754 7755 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase); 7756 }; 7757 7758 // Implements unordered ElementsAre and unordered ElementsAreArray. 7759 template <typename Container> 7760 class UnorderedElementsAreMatcherImpl 7761 : public MatcherInterface<Container>, 7762 public UnorderedElementsAreMatcherImplBase { 7763 public: 7764 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; 7765 typedef internal::StlContainerView<RawContainer> View; 7766 typedef typename View::type StlContainer; 7767 typedef typename View::const_reference StlContainerReference; 7768 typedef typename StlContainer::const_iterator StlContainerConstIterator; 7769 typedef typename StlContainer::value_type Element; 7770 7771 // Constructs the matcher from a sequence of element values or 7772 // element matchers. 7773 template <typename InputIter> 7774 UnorderedElementsAreMatcherImpl(InputIter first, InputIter last) { 7775 for (; first != last; ++first) { 7776 matchers_.push_back(MatcherCast<const Element&>(*first)); 7777 matcher_describers().push_back(matchers_.back().GetDescriber()); 7778 } 7779 } 7780 7781 // Describes what this matcher does. 7782 virtual void DescribeTo(::std::ostream* os) const { 7783 return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os); 7784 } 7785 7786 // Describes what the negation of this matcher does. 7787 virtual void DescribeNegationTo(::std::ostream* os) const { 7788 return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os); 7789 } 7790 7791 virtual bool MatchAndExplain(Container container, 7792 MatchResultListener* listener) const { 7793 StlContainerReference stl_container = View::ConstReference(container); 7794 ::std::vector<string> element_printouts; 7795 MatchMatrix matrix = AnalyzeElements(stl_container.begin(), 7796 stl_container.end(), 7797 &element_printouts, 7798 listener); 7799 7800 const size_t actual_count = matrix.LhsSize(); 7801 if (actual_count == 0 && matchers_.empty()) { 7802 return true; 7803 } 7804 if (actual_count != matchers_.size()) { 7805 // The element count doesn't match. If the container is empty, 7806 // there's no need to explain anything as Google Mock already 7807 // prints the empty container. Otherwise we just need to show 7808 // how many elements there actually are. 7809 if (actual_count != 0 && listener->IsInterested()) { 7810 *listener << "which has " << Elements(actual_count); 7811 } 7812 return false; 7813 } 7814 7815 return VerifyAllElementsAndMatchersAreMatched(element_printouts, 7816 matrix, listener) && 7817 FindPairing(matrix, listener); 7818 } 7819 7820 private: 7821 typedef ::std::vector<Matcher<const Element&> > MatcherVec; 7822 7823 template <typename ElementIter> 7824 MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last, 7825 ::std::vector<string>* element_printouts, 7826 MatchResultListener* listener) const { 7827 element_printouts->clear(); 7828 ::std::vector<char> did_match; 7829 size_t num_elements = 0; 7830 for (; elem_first != elem_last; ++num_elements, ++elem_first) { 7831 if (listener->IsInterested()) { 7832 element_printouts->push_back(PrintToString(*elem_first)); 7833 } 7834 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) { 7835 did_match.push_back(Matches(matchers_[irhs])(*elem_first)); 7836 } 7837 } 7838 7839 MatchMatrix matrix(num_elements, matchers_.size()); 7840 ::std::vector<char>::const_iterator did_match_iter = did_match.begin(); 7841 for (size_t ilhs = 0; ilhs != num_elements; ++ilhs) { 7842 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) { 7843 matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0); 7844 } 7845 } 7846 return matrix; 7847 } 7848 7849 MatcherVec matchers_; 7850 7851 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl); 7852 }; 7853 7854 // Functor for use in TransformTuple. 7855 // Performs MatcherCast<Target> on an input argument of any type. 7856 template <typename Target> 7857 struct CastAndAppendTransform { 7858 template <typename Arg> 7859 Matcher<Target> operator()(const Arg& a) const { 7860 return MatcherCast<Target>(a); 7861 } 7862 }; 7863 7864 // Implements UnorderedElementsAre. 7865 template <typename MatcherTuple> 7866 class UnorderedElementsAreMatcher { 7867 public: 7868 explicit UnorderedElementsAreMatcher(const MatcherTuple& args) 7869 : matchers_(args) {} 7870 7871 template <typename Container> 7872 operator Matcher<Container>() const { 7873 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; 7874 typedef typename internal::StlContainerView<RawContainer>::type View; 7875 typedef typename View::value_type Element; 7876 typedef ::std::vector<Matcher<const Element&> > MatcherVec; 7877 MatcherVec matchers; 7878 matchers.reserve(::std::tr1::tuple_size<MatcherTuple>::value); 7879 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_, 7880 ::std::back_inserter(matchers)); 7881 return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>( 7882 matchers.begin(), matchers.end())); 7883 } 7884 7885 private: 7886 const MatcherTuple matchers_; 7887 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcher); 7888 }; 7889 7890 // Implements ElementsAre. 7891 template <typename MatcherTuple> 7892 class ElementsAreMatcher { 7893 public: 7894 explicit ElementsAreMatcher(const MatcherTuple& args) : matchers_(args) {} 7895 7896 template <typename Container> 7897 operator Matcher<Container>() const { 7898 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; 7899 typedef typename internal::StlContainerView<RawContainer>::type View; 7900 typedef typename View::value_type Element; 7901 typedef ::std::vector<Matcher<const Element&> > MatcherVec; 7902 MatcherVec matchers; 7903 matchers.reserve(::std::tr1::tuple_size<MatcherTuple>::value); 7904 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_, 7905 ::std::back_inserter(matchers)); 7906 return MakeMatcher(new ElementsAreMatcherImpl<Container>( 7907 matchers.begin(), matchers.end())); 7908 } 7909 7910 private: 7911 const MatcherTuple matchers_; 7912 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher); 7913 }; 7914 7915 // Implements UnorderedElementsAreArray(). 7916 template <typename T> 7917 class UnorderedElementsAreArrayMatcher { 7918 public: 7919 UnorderedElementsAreArrayMatcher() {} 7920 7921 template <typename Iter> 7922 UnorderedElementsAreArrayMatcher(Iter first, Iter last) 7923 : matchers_(first, last) {} 7924 7925 template <typename Container> 7926 operator Matcher<Container>() const { 7927 return MakeMatcher( 7928 new UnorderedElementsAreMatcherImpl<Container>(matchers_.begin(), 7929 matchers_.end())); 7930 } 7931 7932 private: 7933 ::std::vector<T> matchers_; 7934 7935 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher); 7936 }; 7937 7938 // Implements ElementsAreArray(). 7939 template <typename T> 7940 class ElementsAreArrayMatcher { 7941 public: 7942 template <typename Iter> 7943 ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {} 7944 7945 template <typename Container> 7946 operator Matcher<Container>() const { 7947 return MakeMatcher(new ElementsAreMatcherImpl<Container>( 7948 matchers_.begin(), matchers_.end())); 7949 } 7950 7951 private: 7952 const ::std::vector<T> matchers_; 7953 7954 GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher); 7955 }; 7956 7957 // Returns the description for a matcher defined using the MATCHER*() 7958 // macro where the user-supplied description string is "", if 7959 // 'negation' is false; otherwise returns the description of the 7960 // negation of the matcher. 'param_values' contains a list of strings 7961 // that are the print-out of the matcher's parameters. 7962 GTEST_API_ string FormatMatcherDescription(bool negation, 7963 const char* matcher_name, 7964 const Strings& param_values); 7965 7966 } // namespace internal 7967 7968 // ElementsAreArray(first, last) 7969 // ElementsAreArray(pointer, count) 7970 // ElementsAreArray(array) 7971 // ElementsAreArray(vector) 7972 // ElementsAreArray({ e1, e2, ..., en }) 7973 // 7974 // The ElementsAreArray() functions are like ElementsAre(...), except 7975 // that they are given a homogeneous sequence rather than taking each 7976 // element as a function argument. The sequence can be specified as an 7977 // array, a pointer and count, a vector, an initializer list, or an 7978 // STL iterator range. In each of these cases, the underlying sequence 7979 // can be either a sequence of values or a sequence of matchers. 7980 // 7981 // All forms of ElementsAreArray() make a copy of the input matcher sequence. 7982 7983 template <typename Iter> 7984 inline internal::ElementsAreArrayMatcher< 7985 typename ::std::iterator_traits<Iter>::value_type> 7986 ElementsAreArray(Iter first, Iter last) { 7987 typedef typename ::std::iterator_traits<Iter>::value_type T; 7988 return internal::ElementsAreArrayMatcher<T>(first, last); 7989 } 7990 7991 template <typename T> 7992 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray( 7993 const T* pointer, size_t count) { 7994 return ElementsAreArray(pointer, pointer + count); 7995 } 7996 7997 template <typename T, size_t N> 7998 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray( 7999 const T (&array)[N]) { 8000 return ElementsAreArray(array, N); 8001 } 8002 8003 template <typename T, typename A> 8004 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray( 8005 const ::std::vector<T, A>& vec) { 8006 return ElementsAreArray(vec.begin(), vec.end()); 8007 } 8008 8009 #if GTEST_LANG_CXX11 8010 template <typename T> 8011 inline internal::ElementsAreArrayMatcher<T> 8012 ElementsAreArray(::std::initializer_list<T> xs) { 8013 return ElementsAreArray(xs.begin(), xs.end()); 8014 } 8015 #endif 8016 8017 // UnorderedElementsAreArray(first, last) 8018 // UnorderedElementsAreArray(pointer, count) 8019 // UnorderedElementsAreArray(array) 8020 // UnorderedElementsAreArray(vector) 8021 // UnorderedElementsAreArray({ e1, e2, ..., en }) 8022 // 8023 // The UnorderedElementsAreArray() functions are like 8024 // ElementsAreArray(...), but allow matching the elements in any order. 8025 template <typename Iter> 8026 inline internal::UnorderedElementsAreArrayMatcher< 8027 typename ::std::iterator_traits<Iter>::value_type> 8028 UnorderedElementsAreArray(Iter first, Iter last) { 8029 typedef typename ::std::iterator_traits<Iter>::value_type T; 8030 return internal::UnorderedElementsAreArrayMatcher<T>(first, last); 8031 } 8032 8033 template <typename T> 8034 inline internal::UnorderedElementsAreArrayMatcher<T> 8035 UnorderedElementsAreArray(const T* pointer, size_t count) { 8036 return UnorderedElementsAreArray(pointer, pointer + count); 8037 } 8038 8039 template <typename T, size_t N> 8040 inline internal::UnorderedElementsAreArrayMatcher<T> 8041 UnorderedElementsAreArray(const T (&array)[N]) { 8042 return UnorderedElementsAreArray(array, N); 8043 } 8044 8045 template <typename T, typename A> 8046 inline internal::UnorderedElementsAreArrayMatcher<T> 8047 UnorderedElementsAreArray(const ::std::vector<T, A>& vec) { 8048 return UnorderedElementsAreArray(vec.begin(), vec.end()); 8049 } 8050 8051 #if GTEST_LANG_CXX11 8052 template <typename T> 8053 inline internal::UnorderedElementsAreArrayMatcher<T> 8054 UnorderedElementsAreArray(::std::initializer_list<T> xs) { 8055 return UnorderedElementsAreArray(xs.begin(), xs.end()); 8056 } 8057 #endif 8058 8059 // _ is a matcher that matches anything of any type. 8060 // 8061 // This definition is fine as: 8062 // 8063 // 1. The C++ standard permits using the name _ in a namespace that 8064 // is not the global namespace or ::std. 8065 // 2. The AnythingMatcher class has no data member or constructor, 8066 // so it's OK to create global variables of this type. 8067 // 3. c-style has approved of using _ in this case. 8068 const internal::AnythingMatcher _ = {}; 8069 // Creates a matcher that matches any value of the given type T. 8070 template <typename T> 8071 inline Matcher<T> A() { return MakeMatcher(new internal::AnyMatcherImpl<T>()); } 8072 8073 // Creates a matcher that matches any value of the given type T. 8074 template <typename T> 8075 inline Matcher<T> An() { return A<T>(); } 8076 8077 // Creates a polymorphic matcher that matches anything equal to x. 8078 // Note: if the parameter of Eq() were declared as const T&, Eq("foo") 8079 // wouldn't compile. 8080 template <typename T> 8081 inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); } 8082 8083 // Constructs a Matcher<T> from a 'value' of type T. The constructed 8084 // matcher matches any value that's equal to 'value'. 8085 template <typename T> 8086 Matcher<T>::Matcher(T value) { *this = Eq(value); } 8087 8088 // Creates a monomorphic matcher that matches anything with type Lhs 8089 // and equal to rhs. A user may need to use this instead of Eq(...) 8090 // in order to resolve an overloading ambiguity. 8091 // 8092 // TypedEq<T>(x) is just a convenient short-hand for Matcher<T>(Eq(x)) 8093 // or Matcher<T>(x), but more readable than the latter. 8094 // 8095 // We could define similar monomorphic matchers for other comparison 8096 // operations (e.g. TypedLt, TypedGe, and etc), but decided not to do 8097 // it yet as those are used much less than Eq() in practice. A user 8098 // can always write Matcher<T>(Lt(5)) to be explicit about the type, 8099 // for example. 8100 template <typename Lhs, typename Rhs> 8101 inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); } 8102 8103 // Creates a polymorphic matcher that matches anything >= x. 8104 template <typename Rhs> 8105 inline internal::GeMatcher<Rhs> Ge(Rhs x) { 8106 return internal::GeMatcher<Rhs>(x); 8107 } 8108 8109 // Creates a polymorphic matcher that matches anything > x. 8110 template <typename Rhs> 8111 inline internal::GtMatcher<Rhs> Gt(Rhs x) { 8112 return internal::GtMatcher<Rhs>(x); 8113 } 8114 8115 // Creates a polymorphic matcher that matches anything <= x. 8116 template <typename Rhs> 8117 inline internal::LeMatcher<Rhs> Le(Rhs x) { 8118 return internal::LeMatcher<Rhs>(x); 8119 } 8120 8121 // Creates a polymorphic matcher that matches anything < x. 8122 template <typename Rhs> 8123 inline internal::LtMatcher<Rhs> Lt(Rhs x) { 8124 return internal::LtMatcher<Rhs>(x); 8125 } 8126 8127 // Creates a polymorphic matcher that matches anything != x. 8128 template <typename Rhs> 8129 inline internal::NeMatcher<Rhs> Ne(Rhs x) { 8130 return internal::NeMatcher<Rhs>(x); 8131 } 8132 8133 // Creates a polymorphic matcher that matches any NULL pointer. 8134 inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() { 8135 return MakePolymorphicMatcher(internal::IsNullMatcher()); 8136 } 8137 8138 // Creates a polymorphic matcher that matches any non-NULL pointer. 8139 // This is convenient as Not(NULL) doesn't compile (the compiler 8140 // thinks that that expression is comparing a pointer with an integer). 8141 inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() { 8142 return MakePolymorphicMatcher(internal::NotNullMatcher()); 8143 } 8144 8145 // Creates a polymorphic matcher that matches any argument that 8146 // references variable x. 8147 template <typename T> 8148 inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT 8149 return internal::RefMatcher<T&>(x); 8150 } 8151 8152 // Creates a matcher that matches any double argument approximately 8153 // equal to rhs, where two NANs are considered unequal. 8154 inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) { 8155 return internal::FloatingEqMatcher<double>(rhs, false); 8156 } 8157 8158 // Creates a matcher that matches any double argument approximately 8159 // equal to rhs, including NaN values when rhs is NaN. 8160 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(double rhs) { 8161 return internal::FloatingEqMatcher<double>(rhs, true); 8162 } 8163 8164 // Creates a matcher that matches any double argument approximately equal to 8165 // rhs, up to the specified max absolute error bound, where two NANs are 8166 // considered unequal. The max absolute error bound must be non-negative. 8167 inline internal::FloatingEqMatcher<double> DoubleNear( 8168 double rhs, double max_abs_error) { 8169 return internal::FloatingEqMatcher<double>(rhs, false, max_abs_error); 8170 } 8171 8172 // Creates a matcher that matches any double argument approximately equal to 8173 // rhs, up to the specified max absolute error bound, including NaN values when 8174 // rhs is NaN. The max absolute error bound must be non-negative. 8175 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear( 8176 double rhs, double max_abs_error) { 8177 return internal::FloatingEqMatcher<double>(rhs, true, max_abs_error); 8178 } 8179 8180 // Creates a matcher that matches any float argument approximately 8181 // equal to rhs, where two NANs are considered unequal. 8182 inline internal::FloatingEqMatcher<float> FloatEq(float rhs) { 8183 return internal::FloatingEqMatcher<float>(rhs, false); 8184 } 8185 8186 // Creates a matcher that matches any float argument approximately 8187 // equal to rhs, including NaN values when rhs is NaN. 8188 inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(float rhs) { 8189 return internal::FloatingEqMatcher<float>(rhs, true); 8190 } 8191 8192 // Creates a matcher that matches any float argument approximately equal to 8193 // rhs, up to the specified max absolute error bound, where two NANs are 8194 // considered unequal. The max absolute error bound must be non-negative. 8195 inline internal::FloatingEqMatcher<float> FloatNear( 8196 float rhs, float max_abs_error) { 8197 return internal::FloatingEqMatcher<float>(rhs, false, max_abs_error); 8198 } 8199 8200 // Creates a matcher that matches any float argument approximately equal to 8201 // rhs, up to the specified max absolute error bound, including NaN values when 8202 // rhs is NaN. The max absolute error bound must be non-negative. 8203 inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear( 8204 float rhs, float max_abs_error) { 8205 return internal::FloatingEqMatcher<float>(rhs, true, max_abs_error); 8206 } 8207 8208 // Creates a matcher that matches a pointer (raw or smart) that points 8209 // to a value that matches inner_matcher. 8210 template <typename InnerMatcher> 8211 inline internal::PointeeMatcher<InnerMatcher> Pointee( 8212 const InnerMatcher& inner_matcher) { 8213 return internal::PointeeMatcher<InnerMatcher>(inner_matcher); 8214 } 8215 8216 // Creates a matcher that matches an object whose given field matches 8217 // 'matcher'. For example, 8218 // Field(&Foo::number, Ge(5)) 8219 // matches a Foo object x iff x.number >= 5. 8220 template <typename Class, typename FieldType, typename FieldMatcher> 8221 inline PolymorphicMatcher< 8222 internal::FieldMatcher<Class, FieldType> > Field( 8223 FieldType Class::*field, const FieldMatcher& matcher) { 8224 return MakePolymorphicMatcher( 8225 internal::FieldMatcher<Class, FieldType>( 8226 field, MatcherCast<const FieldType&>(matcher))); 8227 // The call to MatcherCast() is required for supporting inner 8228 // matchers of compatible types. For example, it allows 8229 // Field(&Foo::bar, m) 8230 // to compile where bar is an int32 and m is a matcher for int64. 8231 } 8232 8233 // Creates a matcher that matches an object whose given property 8234 // matches 'matcher'. For example, 8235 // Property(&Foo::str, StartsWith("hi")) 8236 // matches a Foo object x iff x.str() starts with "hi". 8237 template <typename Class, typename PropertyType, typename PropertyMatcher> 8238 inline PolymorphicMatcher< 8239 internal::PropertyMatcher<Class, PropertyType> > Property( 8240 PropertyType (Class::*property)() const, const PropertyMatcher& matcher) { 8241 return MakePolymorphicMatcher( 8242 internal::PropertyMatcher<Class, PropertyType>( 8243 property, 8244 MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); 8245 // The call to MatcherCast() is required for supporting inner 8246 // matchers of compatible types. For example, it allows 8247 // Property(&Foo::bar, m) 8248 // to compile where bar() returns an int32 and m is a matcher for int64. 8249 } 8250 8251 // Creates a matcher that matches an object iff the result of applying 8252 // a callable to x matches 'matcher'. 8253 // For example, 8254 // ResultOf(f, StartsWith("hi")) 8255 // matches a Foo object x iff f(x) starts with "hi". 8256 // callable parameter can be a function, function pointer, or a functor. 8257 // Callable has to satisfy the following conditions: 8258 // * It is required to keep no state affecting the results of 8259 // the calls on it and make no assumptions about how many calls 8260 // will be made. Any state it keeps must be protected from the 8261 // concurrent access. 8262 // * If it is a function object, it has to define type result_type. 8263 // We recommend deriving your functor classes from std::unary_function. 8264 template <typename Callable, typename ResultOfMatcher> 8265 internal::ResultOfMatcher<Callable> ResultOf( 8266 Callable callable, const ResultOfMatcher& matcher) { 8267 return internal::ResultOfMatcher<Callable>( 8268 callable, 8269 MatcherCast<typename internal::CallableTraits<Callable>::ResultType>( 8270 matcher)); 8271 // The call to MatcherCast() is required for supporting inner 8272 // matchers of compatible types. For example, it allows 8273 // ResultOf(Function, m) 8274 // to compile where Function() returns an int32 and m is a matcher for int64. 8275 } 8276 8277 // String matchers. 8278 8279 // Matches a string equal to str. 8280 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > 8281 StrEq(const internal::string& str) { 8282 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( 8283 str, true, true)); 8284 } 8285 8286 // Matches a string not equal to str. 8287 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > 8288 StrNe(const internal::string& str) { 8289 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( 8290 str, false, true)); 8291 } 8292 8293 // Matches a string equal to str, ignoring case. 8294 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > 8295 StrCaseEq(const internal::string& str) { 8296 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( 8297 str, true, false)); 8298 } 8299 8300 // Matches a string not equal to str, ignoring case. 8301 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > 8302 StrCaseNe(const internal::string& str) { 8303 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( 8304 str, false, false)); 8305 } 8306 8307 // Creates a matcher that matches any string, std::string, or C string 8308 // that contains the given substring. 8309 inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::string> > 8310 HasSubstr(const internal::string& substring) { 8311 return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::string>( 8312 substring)); 8313 } 8314 8315 // Matches a string that starts with 'prefix' (case-sensitive). 8316 inline PolymorphicMatcher<internal::StartsWithMatcher<internal::string> > 8317 StartsWith(const internal::string& prefix) { 8318 return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::string>( 8319 prefix)); 8320 } 8321 8322 // Matches a string that ends with 'suffix' (case-sensitive). 8323 inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> > 8324 EndsWith(const internal::string& suffix) { 8325 return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string>( 8326 suffix)); 8327 } 8328 8329 // Matches a string that fully matches regular expression 'regex'. 8330 // The matcher takes ownership of 'regex'. 8331 inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( 8332 const internal::RE* regex) { 8333 return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true)); 8334 } 8335 inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( 8336 const internal::string& regex) { 8337 return MatchesRegex(new internal::RE(regex)); 8338 } 8339 8340 // Matches a string that contains regular expression 'regex'. 8341 // The matcher takes ownership of 'regex'. 8342 inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( 8343 const internal::RE* regex) { 8344 return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false)); 8345 } 8346 inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( 8347 const internal::string& regex) { 8348 return ContainsRegex(new internal::RE(regex)); 8349 } 8350 8351 #if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING 8352 // Wide string matchers. 8353 8354 // Matches a string equal to str. 8355 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > 8356 StrEq(const internal::wstring& str) { 8357 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( 8358 str, true, true)); 8359 } 8360 8361 // Matches a string not equal to str. 8362 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > 8363 StrNe(const internal::wstring& str) { 8364 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( 8365 str, false, true)); 8366 } 8367 8368 // Matches a string equal to str, ignoring case. 8369 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > 8370 StrCaseEq(const internal::wstring& str) { 8371 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( 8372 str, true, false)); 8373 } 8374 8375 // Matches a string not equal to str, ignoring case. 8376 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > 8377 StrCaseNe(const internal::wstring& str) { 8378 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( 8379 str, false, false)); 8380 } 8381 8382 // Creates a matcher that matches any wstring, std::wstring, or C wide string 8383 // that contains the given substring. 8384 inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::wstring> > 8385 HasSubstr(const internal::wstring& substring) { 8386 return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::wstring>( 8387 substring)); 8388 } 8389 8390 // Matches a string that starts with 'prefix' (case-sensitive). 8391 inline PolymorphicMatcher<internal::StartsWithMatcher<internal::wstring> > 8392 StartsWith(const internal::wstring& prefix) { 8393 return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::wstring>( 8394 prefix)); 8395 } 8396 8397 // Matches a string that ends with 'suffix' (case-sensitive). 8398 inline PolymorphicMatcher<internal::EndsWithMatcher<internal::wstring> > 8399 EndsWith(const internal::wstring& suffix) { 8400 return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::wstring>( 8401 suffix)); 8402 } 8403 8404 #endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING 8405 8406 // Creates a polymorphic matcher that matches a 2-tuple where the 8407 // first field == the second field. 8408 inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); } 8409 8410 // Creates a polymorphic matcher that matches a 2-tuple where the 8411 // first field >= the second field. 8412 inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); } 8413 8414 // Creates a polymorphic matcher that matches a 2-tuple where the 8415 // first field > the second field. 8416 inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); } 8417 8418 // Creates a polymorphic matcher that matches a 2-tuple where the 8419 // first field <= the second field. 8420 inline internal::Le2Matcher Le() { return internal::Le2Matcher(); } 8421 8422 // Creates a polymorphic matcher that matches a 2-tuple where the 8423 // first field < the second field. 8424 inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); } 8425 8426 // Creates a polymorphic matcher that matches a 2-tuple where the 8427 // first field != the second field. 8428 inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); } 8429 8430 // Creates a matcher that matches any value of type T that m doesn't 8431 // match. 8432 template <typename InnerMatcher> 8433 inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) { 8434 return internal::NotMatcher<InnerMatcher>(m); 8435 } 8436 8437 // Returns a matcher that matches anything that satisfies the given 8438 // predicate. The predicate can be any unary function or functor 8439 // whose return type can be implicitly converted to bool. 8440 template <typename Predicate> 8441 inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> > 8442 Truly(Predicate pred) { 8443 return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred)); 8444 } 8445 8446 // Returns a matcher that matches the container size. The container must 8447 // support both size() and size_type which all STL-like containers provide. 8448 // Note that the parameter 'size' can be a value of type size_type as well as 8449 // matcher. For instance: 8450 // EXPECT_THAT(container, SizeIs(2)); // Checks container has 2 elements. 8451 // EXPECT_THAT(container, SizeIs(Le(2)); // Checks container has at most 2. 8452 template <typename SizeMatcher> 8453 inline internal::SizeIsMatcher<SizeMatcher> 8454 SizeIs(const SizeMatcher& size_matcher) { 8455 return internal::SizeIsMatcher<SizeMatcher>(size_matcher); 8456 } 8457 8458 // Returns a matcher that matches an equal container. 8459 // This matcher behaves like Eq(), but in the event of mismatch lists the 8460 // values that are included in one container but not the other. (Duplicate 8461 // values and order differences are not explained.) 8462 template <typename Container> 8463 inline PolymorphicMatcher<internal::ContainerEqMatcher< // NOLINT 8464 GTEST_REMOVE_CONST_(Container)> > 8465 ContainerEq(const Container& rhs) { 8466 // This following line is for working around a bug in MSVC 8.0, 8467 // which causes Container to be a const type sometimes. 8468 typedef GTEST_REMOVE_CONST_(Container) RawContainer; 8469 return MakePolymorphicMatcher( 8470 internal::ContainerEqMatcher<RawContainer>(rhs)); 8471 } 8472 8473 // Returns a matcher that matches a container that, when sorted using 8474 // the given comparator, matches container_matcher. 8475 template <typename Comparator, typename ContainerMatcher> 8476 inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher> 8477 WhenSortedBy(const Comparator& comparator, 8478 const ContainerMatcher& container_matcher) { 8479 return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>( 8480 comparator, container_matcher); 8481 } 8482 8483 // Returns a matcher that matches a container that, when sorted using 8484 // the < operator, matches container_matcher. 8485 template <typename ContainerMatcher> 8486 inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher> 8487 WhenSorted(const ContainerMatcher& container_matcher) { 8488 return 8489 internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>( 8490 internal::LessComparator(), container_matcher); 8491 } 8492 8493 // Matches an STL-style container or a native array that contains the 8494 // same number of elements as in rhs, where its i-th element and rhs's 8495 // i-th element (as a pair) satisfy the given pair matcher, for all i. 8496 // TupleMatcher must be able to be safely cast to Matcher<tuple<const 8497 // T1&, const T2&> >, where T1 and T2 are the types of elements in the 8498 // LHS container and the RHS container respectively. 8499 template <typename TupleMatcher, typename Container> 8500 inline internal::PointwiseMatcher<TupleMatcher, 8501 GTEST_REMOVE_CONST_(Container)> 8502 Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) { 8503 // This following line is for working around a bug in MSVC 8.0, 8504 // which causes Container to be a const type sometimes. 8505 typedef GTEST_REMOVE_CONST_(Container) RawContainer; 8506 return internal::PointwiseMatcher<TupleMatcher, RawContainer>( 8507 tuple_matcher, rhs); 8508 } 8509 8510 // Matches an STL-style container or a native array that contains at 8511 // least one element matching the given value or matcher. 8512 // 8513 // Examples: 8514 // ::std::set<int> page_ids; 8515 // page_ids.insert(3); 8516 // page_ids.insert(1); 8517 // EXPECT_THAT(page_ids, Contains(1)); 8518 // EXPECT_THAT(page_ids, Contains(Gt(2))); 8519 // EXPECT_THAT(page_ids, Not(Contains(4))); 8520 // 8521 // ::std::map<int, size_t> page_lengths; 8522 // page_lengths[1] = 100; 8523 // EXPECT_THAT(page_lengths, 8524 // Contains(::std::pair<const int, size_t>(1, 100))); 8525 // 8526 // const char* user_ids[] = { "joe", "mike", "tom" }; 8527 // EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom")))); 8528 template <typename M> 8529 inline internal::ContainsMatcher<M> Contains(M matcher) { 8530 return internal::ContainsMatcher<M>(matcher); 8531 } 8532 8533 // Matches an STL-style container or a native array that contains only 8534 // elements matching the given value or matcher. 8535 // 8536 // Each(m) is semantically equivalent to Not(Contains(Not(m))). Only 8537 // the messages are different. 8538 // 8539 // Examples: 8540 // ::std::set<int> page_ids; 8541 // // Each(m) matches an empty container, regardless of what m is. 8542 // EXPECT_THAT(page_ids, Each(Eq(1))); 8543 // EXPECT_THAT(page_ids, Each(Eq(77))); 8544 // 8545 // page_ids.insert(3); 8546 // EXPECT_THAT(page_ids, Each(Gt(0))); 8547 // EXPECT_THAT(page_ids, Not(Each(Gt(4)))); 8548 // page_ids.insert(1); 8549 // EXPECT_THAT(page_ids, Not(Each(Lt(2)))); 8550 // 8551 // ::std::map<int, size_t> page_lengths; 8552 // page_lengths[1] = 100; 8553 // page_lengths[2] = 200; 8554 // page_lengths[3] = 300; 8555 // EXPECT_THAT(page_lengths, Not(Each(Pair(1, 100)))); 8556 // EXPECT_THAT(page_lengths, Each(Key(Le(3)))); 8557 // 8558 // const char* user_ids[] = { "joe", "mike", "tom" }; 8559 // EXPECT_THAT(user_ids, Not(Each(Eq(::std::string("tom"))))); 8560 template <typename M> 8561 inline internal::EachMatcher<M> Each(M matcher) { 8562 return internal::EachMatcher<M>(matcher); 8563 } 8564 8565 // Key(inner_matcher) matches an std::pair whose 'first' field matches 8566 // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an 8567 // std::map that contains at least one element whose key is >= 5. 8568 template <typename M> 8569 inline internal::KeyMatcher<M> Key(M inner_matcher) { 8570 return internal::KeyMatcher<M>(inner_matcher); 8571 } 8572 8573 // Pair(first_matcher, second_matcher) matches a std::pair whose 'first' field 8574 // matches first_matcher and whose 'second' field matches second_matcher. For 8575 // example, EXPECT_THAT(map_type, ElementsAre(Pair(Ge(5), "foo"))) can be used 8576 // to match a std::map<int, string> that contains exactly one element whose key 8577 // is >= 5 and whose value equals "foo". 8578 template <typename FirstMatcher, typename SecondMatcher> 8579 inline internal::PairMatcher<FirstMatcher, SecondMatcher> 8580 Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) { 8581 return internal::PairMatcher<FirstMatcher, SecondMatcher>( 8582 first_matcher, second_matcher); 8583 } 8584 8585 // Returns a predicate that is satisfied by anything that matches the 8586 // given matcher. 8587 template <typename M> 8588 inline internal::MatcherAsPredicate<M> Matches(M matcher) { 8589 return internal::MatcherAsPredicate<M>(matcher); 8590 } 8591 8592 // Returns true iff the value matches the matcher. 8593 template <typename T, typename M> 8594 inline bool Value(const T& value, M matcher) { 8595 return testing::Matches(matcher)(value); 8596 } 8597 8598 // Matches the value against the given matcher and explains the match 8599 // result to listener. 8600 template <typename T, typename M> 8601 inline bool ExplainMatchResult( 8602 M matcher, const T& value, MatchResultListener* listener) { 8603 return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener); 8604 } 8605 8606 #if GTEST_LANG_CXX11 8607 // Define variadic matcher versions. They are overloaded in 8608 // gmock-generated-matchers.h for the cases supported by pre C++11 compilers. 8609 template <typename... Args> 8610 inline internal::AllOfMatcher<Args...> AllOf(const Args&... matchers) { 8611 return internal::AllOfMatcher<Args...>(matchers...); 8612 } 8613 8614 template <typename... Args> 8615 inline internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) { 8616 return internal::AnyOfMatcher<Args...>(matchers...); 8617 } 8618 8619 #endif // GTEST_LANG_CXX11 8620 8621 // AllArgs(m) is a synonym of m. This is useful in 8622 // 8623 // EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq())); 8624 // 8625 // which is easier to read than 8626 // 8627 // EXPECT_CALL(foo, Bar(_, _)).With(Eq()); 8628 template <typename InnerMatcher> 8629 inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; } 8630 8631 // These macros allow using matchers to check values in Google Test 8632 // tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher) 8633 // succeed iff the value matches the matcher. If the assertion fails, 8634 // the value and the description of the matcher will be printed. 8635 #define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\ 8636 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) 8637 #define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\ 8638 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) 8639 8640 } // namespace testing 8641 8642 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ 8643 8644 namespace testing { 8645 8646 // An abstract handle of an expectation. 8647 class Expectation; 8648 8649 // A set of expectation handles. 8650 class ExpectationSet; 8651 8652 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION 8653 // and MUST NOT BE USED IN USER CODE!!! 8654 namespace internal { 8655 8656 // Implements a mock function. 8657 template <typename F> class FunctionMocker; 8658 8659 // Base class for expectations. 8660 class ExpectationBase; 8661 8662 // Implements an expectation. 8663 template <typename F> class TypedExpectation; 8664 8665 // Helper class for testing the Expectation class template. 8666 class ExpectationTester; 8667 8668 // Base class for function mockers. 8669 template <typename F> class FunctionMockerBase; 8670 8671 // Protects the mock object registry (in class Mock), all function 8672 // mockers, and all expectations. 8673 // 8674 // The reason we don't use more fine-grained protection is: when a 8675 // mock function Foo() is called, it needs to consult its expectations 8676 // to see which one should be picked. If another thread is allowed to 8677 // call a mock function (either Foo() or a different one) at the same 8678 // time, it could affect the "retired" attributes of Foo()'s 8679 // expectations when InSequence() is used, and thus affect which 8680 // expectation gets picked. Therefore, we sequence all mock function 8681 // calls to ensure the integrity of the mock objects' states. 8682 GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex); 8683 8684 // Untyped base class for ActionResultHolder<R>. 8685 class UntypedActionResultHolderBase; 8686 8687 // Abstract base class of FunctionMockerBase. This is the 8688 // type-agnostic part of the function mocker interface. Its pure 8689 // virtual methods are implemented by FunctionMockerBase. 8690 class GTEST_API_ UntypedFunctionMockerBase { 8691 public: 8692 UntypedFunctionMockerBase(); 8693 virtual ~UntypedFunctionMockerBase(); 8694 8695 // Verifies that all expectations on this mock function have been 8696 // satisfied. Reports one or more Google Test non-fatal failures 8697 // and returns false if not. 8698 bool VerifyAndClearExpectationsLocked() 8699 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); 8700 8701 // Clears the ON_CALL()s set on this mock function. 8702 virtual void ClearDefaultActionsLocked() 8703 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0; 8704 8705 // In all of the following Untyped* functions, it's the caller's 8706 // responsibility to guarantee the correctness of the arguments' 8707 // types. 8708 8709 // Performs the default action with the given arguments and returns 8710 // the action's result. The call description string will be used in 8711 // the error message to describe the call in the case the default 8712 // action fails. 8713 // L = * 8714 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( 8715 const void* untyped_args, 8716 const string& call_description) const = 0; 8717 8718 // Performs the given action with the given arguments and returns 8719 // the action's result. 8720 // L = * 8721 virtual UntypedActionResultHolderBase* UntypedPerformAction( 8722 const void* untyped_action, 8723 const void* untyped_args) const = 0; 8724 8725 // Writes a message that the call is uninteresting (i.e. neither 8726 // explicitly expected nor explicitly unexpected) to the given 8727 // ostream. 8728 virtual void UntypedDescribeUninterestingCall( 8729 const void* untyped_args, 8730 ::std::ostream* os) const 8731 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0; 8732 8733 // Returns the expectation that matches the given function arguments 8734 // (or NULL is there's no match); when a match is found, 8735 // untyped_action is set to point to the action that should be 8736 // performed (or NULL if the action is "do default"), and 8737 // is_excessive is modified to indicate whether the call exceeds the 8738 // expected number. 8739 virtual const ExpectationBase* UntypedFindMatchingExpectation( 8740 const void* untyped_args, 8741 const void** untyped_action, bool* is_excessive, 8742 ::std::ostream* what, ::std::ostream* why) 8743 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0; 8744 8745 // Prints the given function arguments to the ostream. 8746 virtual void UntypedPrintArgs(const void* untyped_args, 8747 ::std::ostream* os) const = 0; 8748 8749 // Sets the mock object this mock method belongs to, and registers 8750 // this information in the global mock registry. Will be called 8751 // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock 8752 // method. 8753 // TODO(wan@google.com): rename to SetAndRegisterOwner(). 8754 void RegisterOwner(const void* mock_obj) 8755 GTEST_LOCK_EXCLUDED_(g_gmock_mutex); 8756 8757 // Sets the mock object this mock method belongs to, and sets the 8758 // name of the mock function. Will be called upon each invocation 8759 // of this mock function. 8760 void SetOwnerAndName(const void* mock_obj, const char* name) 8761 GTEST_LOCK_EXCLUDED_(g_gmock_mutex); 8762 8763 // Returns the mock object this mock method belongs to. Must be 8764 // called after RegisterOwner() or SetOwnerAndName() has been 8765 // called. 8766 const void* MockObject() const 8767 GTEST_LOCK_EXCLUDED_(g_gmock_mutex); 8768 8769 // Returns the name of this mock method. Must be called after 8770 // SetOwnerAndName() has been called. 8771 const char* Name() const 8772 GTEST_LOCK_EXCLUDED_(g_gmock_mutex); 8773 8774 // Returns the result of invoking this mock function with the given 8775 // arguments. This function can be safely called from multiple 8776 // threads concurrently. The caller is responsible for deleting the 8777 // result. 8778 const UntypedActionResultHolderBase* UntypedInvokeWith( 8779 const void* untyped_args) 8780 GTEST_LOCK_EXCLUDED_(g_gmock_mutex); 8781 8782 protected: 8783 typedef std::vector<const void*> UntypedOnCallSpecs; 8784 8785 typedef std::vector<internal::linked_ptr<ExpectationBase> > 8786 UntypedExpectations; 8787 8788 // Returns an Expectation object that references and co-owns exp, 8789 // which must be an expectation on this mock function. 8790 Expectation GetHandleOf(ExpectationBase* exp); 8791 8792 // Address of the mock object this mock method belongs to. Only 8793 // valid after this mock method has been called or 8794 // ON_CALL/EXPECT_CALL has been invoked on it. 8795 const void* mock_obj_; // Protected by g_gmock_mutex. 8796 8797 // Name of the function being mocked. Only valid after this mock 8798 // method has been called. 8799 const char* name_; // Protected by g_gmock_mutex. 8800 8801 // All default action specs for this function mocker. 8802 UntypedOnCallSpecs untyped_on_call_specs_; 8803 8804 // All expectations for this function mocker. 8805 UntypedExpectations untyped_expectations_; 8806 }; // class UntypedFunctionMockerBase 8807 8808 // Untyped base class for OnCallSpec<F>. 8809 class UntypedOnCallSpecBase { 8810 public: 8811 // The arguments are the location of the ON_CALL() statement. 8812 UntypedOnCallSpecBase(const char* a_file, int a_line) 8813 : file_(a_file), line_(a_line), last_clause_(kNone) {} 8814 8815 // Where in the source file was the default action spec defined? 8816 const char* file() const { return file_; } 8817 int line() const { return line_; } 8818 8819 protected: 8820 // Gives each clause in the ON_CALL() statement a name. 8821 enum Clause { 8822 // Do not change the order of the enum members! The run-time 8823 // syntax checking relies on it. 8824 kNone, 8825 kWith, 8826 kWillByDefault 8827 }; 8828 8829 // Asserts that the ON_CALL() statement has a certain property. 8830 void AssertSpecProperty(bool property, const string& failure_message) const { 8831 Assert(property, file_, line_, failure_message); 8832 } 8833 8834 // Expects that the ON_CALL() statement has a certain property. 8835 void ExpectSpecProperty(bool property, const string& failure_message) const { 8836 Expect(property, file_, line_, failure_message); 8837 } 8838 8839 const char* file_; 8840 int line_; 8841 8842 // The last clause in the ON_CALL() statement as seen so far. 8843 // Initially kNone and changes as the statement is parsed. 8844 Clause last_clause_; 8845 }; // class UntypedOnCallSpecBase 8846 8847 // This template class implements an ON_CALL spec. 8848 template <typename F> 8849 class OnCallSpec : public UntypedOnCallSpecBase { 8850 public: 8851 typedef typename Function<F>::ArgumentTuple ArgumentTuple; 8852 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; 8853 8854 // Constructs an OnCallSpec object from the information inside 8855 // the parenthesis of an ON_CALL() statement. 8856 OnCallSpec(const char* a_file, int a_line, 8857 const ArgumentMatcherTuple& matchers) 8858 : UntypedOnCallSpecBase(a_file, a_line), 8859 matchers_(matchers), 8860 // By default, extra_matcher_ should match anything. However, 8861 // we cannot initialize it with _ as that triggers a compiler 8862 // bug in Symbian's C++ compiler (cannot decide between two 8863 // overloaded constructors of Matcher<const ArgumentTuple&>). 8864 extra_matcher_(A<const ArgumentTuple&>()) { 8865 } 8866 8867 // Implements the .With() clause. 8868 OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) { 8869 // Makes sure this is called at most once. 8870 ExpectSpecProperty(last_clause_ < kWith, 8871 ".With() cannot appear " 8872 "more than once in an ON_CALL()."); 8873 last_clause_ = kWith; 8874 8875 extra_matcher_ = m; 8876 return *this; 8877 } 8878 8879 // Implements the .WillByDefault() clause. 8880 OnCallSpec& WillByDefault(const Action<F>& action) { 8881 ExpectSpecProperty(last_clause_ < kWillByDefault, 8882 ".WillByDefault() must appear " 8883 "exactly once in an ON_CALL()."); 8884 last_clause_ = kWillByDefault; 8885 8886 ExpectSpecProperty(!action.IsDoDefault(), 8887 "DoDefault() cannot be used in ON_CALL()."); 8888 action_ = action; 8889 return *this; 8890 } 8891 8892 // Returns true iff the given arguments match the matchers. 8893 bool Matches(const ArgumentTuple& args) const { 8894 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args); 8895 } 8896 8897 // Returns the action specified by the user. 8898 const Action<F>& GetAction() const { 8899 AssertSpecProperty(last_clause_ == kWillByDefault, 8900 ".WillByDefault() must appear exactly " 8901 "once in an ON_CALL()."); 8902 return action_; 8903 } 8904 8905 private: 8906 // The information in statement 8907 // 8908 // ON_CALL(mock_object, Method(matchers)) 8909 // .With(multi-argument-matcher) 8910 // .WillByDefault(action); 8911 // 8912 // is recorded in the data members like this: 8913 // 8914 // source file that contains the statement => file_ 8915 // line number of the statement => line_ 8916 // matchers => matchers_ 8917 // multi-argument-matcher => extra_matcher_ 8918 // action => action_ 8919 ArgumentMatcherTuple matchers_; 8920 Matcher<const ArgumentTuple&> extra_matcher_; 8921 Action<F> action_; 8922 }; // class OnCallSpec 8923 8924 // Possible reactions on uninteresting calls. 8925 enum CallReaction { 8926 kAllow, 8927 kWarn, 8928 kFail, 8929 kDefault = kWarn // By default, warn about uninteresting calls. 8930 }; 8931 8932 } // namespace internal 8933 8934 // Utilities for manipulating mock objects. 8935 class GTEST_API_ Mock { 8936 public: 8937 // The following public methods can be called concurrently. 8938 8939 // Tells Google Mock to ignore mock_obj when checking for leaked 8940 // mock objects. 8941 static void AllowLeak(const void* mock_obj) 8942 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); 8943 8944 // Verifies and clears all expectations on the given mock object. 8945 // If the expectations aren't satisfied, generates one or more 8946 // Google Test non-fatal failures and returns false. 8947 static bool VerifyAndClearExpectations(void* mock_obj) 8948 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); 8949 8950 // Verifies all expectations on the given mock object and clears its 8951 // default actions and expectations. Returns true iff the 8952 // verification was successful. 8953 static bool VerifyAndClear(void* mock_obj) 8954 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); 8955 8956 private: 8957 friend class internal::UntypedFunctionMockerBase; 8958 8959 // Needed for a function mocker to register itself (so that we know 8960 // how to clear a mock object). 8961 template <typename F> 8962 friend class internal::FunctionMockerBase; 8963 8964 template <typename M> 8965 friend class NiceMock; 8966 8967 template <typename M> 8968 friend class NaggyMock; 8969 8970 template <typename M> 8971 friend class StrictMock; 8972 8973 // Tells Google Mock to allow uninteresting calls on the given mock 8974 // object. 8975 static void AllowUninterestingCalls(const void* mock_obj) 8976 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); 8977 8978 // Tells Google Mock to warn the user about uninteresting calls on 8979 // the given mock object. 8980 static void WarnUninterestingCalls(const void* mock_obj) 8981 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); 8982 8983 // Tells Google Mock to fail uninteresting calls on the given mock 8984 // object. 8985 static void FailUninterestingCalls(const void* mock_obj) 8986 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); 8987 8988 // Tells Google Mock the given mock object is being destroyed and 8989 // its entry in the call-reaction table should be removed. 8990 static void UnregisterCallReaction(const void* mock_obj) 8991 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); 8992 8993 // Returns the reaction Google Mock will have on uninteresting calls 8994 // made on the given mock object. 8995 static internal::CallReaction GetReactionOnUninterestingCalls( 8996 const void* mock_obj) 8997 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); 8998 8999 // Verifies that all expectations on the given mock object have been 9000 // satisfied. Reports one or more Google Test non-fatal failures 9001 // and returns false if not. 9002 static bool VerifyAndClearExpectationsLocked(void* mock_obj) 9003 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex); 9004 9005 // Clears all ON_CALL()s set on the given mock object. 9006 static void ClearDefaultActionsLocked(void* mock_obj) 9007 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex); 9008 9009 // Registers a mock object and a mock method it owns. 9010 static void Register( 9011 const void* mock_obj, 9012 internal::UntypedFunctionMockerBase* mocker) 9013 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); 9014 9015 // Tells Google Mock where in the source code mock_obj is used in an 9016 // ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this 9017 // information helps the user identify which object it is. 9018 static void RegisterUseByOnCallOrExpectCall( 9019 const void* mock_obj, const char* file, int line) 9020 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); 9021 9022 // Unregisters a mock method; removes the owning mock object from 9023 // the registry when the last mock method associated with it has 9024 // been unregistered. This is called only in the destructor of 9025 // FunctionMockerBase. 9026 static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker) 9027 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex); 9028 }; // class Mock 9029 9030 // An abstract handle of an expectation. Useful in the .After() 9031 // clause of EXPECT_CALL() for setting the (partial) order of 9032 // expectations. The syntax: 9033 // 9034 // Expectation e1 = EXPECT_CALL(...)...; 9035 // EXPECT_CALL(...).After(e1)...; 9036 // 9037 // sets two expectations where the latter can only be matched after 9038 // the former has been satisfied. 9039 // 9040 // Notes: 9041 // - This class is copyable and has value semantics. 9042 // - Constness is shallow: a const Expectation object itself cannot 9043 // be modified, but the mutable methods of the ExpectationBase 9044 // object it references can be called via expectation_base(). 9045 // - The constructors and destructor are defined out-of-line because 9046 // the Symbian WINSCW compiler wants to otherwise instantiate them 9047 // when it sees this class definition, at which point it doesn't have 9048 // ExpectationBase available yet, leading to incorrect destruction 9049 // in the linked_ptr (or compilation errors if using a checking 9050 // linked_ptr). 9051 class GTEST_API_ Expectation { 9052 public: 9053 // Constructs a null object that doesn't reference any expectation. 9054 Expectation(); 9055 9056 ~Expectation(); 9057 9058 // This single-argument ctor must not be explicit, in order to support the 9059 // Expectation e = EXPECT_CALL(...); 9060 // syntax. 9061 // 9062 // A TypedExpectation object stores its pre-requisites as 9063 // Expectation objects, and needs to call the non-const Retire() 9064 // method on the ExpectationBase objects they reference. Therefore 9065 // Expectation must receive a *non-const* reference to the 9066 // ExpectationBase object. 9067 Expectation(internal::ExpectationBase& exp); // NOLINT 9068 9069 // The compiler-generated copy ctor and operator= work exactly as 9070 // intended, so we don't need to define our own. 9071 9072 // Returns true iff rhs references the same expectation as this object does. 9073 bool operator==(const Expectation& rhs) const { 9074 return expectation_base_ == rhs.expectation_base_; 9075 } 9076 9077 bool operator!=(const Expectation& rhs) const { return !(*this == rhs); } 9078 9079 private: 9080 friend class ExpectationSet; 9081 friend class Sequence; 9082 friend class ::testing::internal::ExpectationBase; 9083 friend class ::testing::internal::UntypedFunctionMockerBase; 9084 9085 template <typename F> 9086 friend class ::testing::internal::FunctionMockerBase; 9087 9088 template <typename F> 9089 friend class ::testing::internal::TypedExpectation; 9090 9091 // This comparator is needed for putting Expectation objects into a set. 9092 class Less { 9093 public: 9094 bool operator()(const Expectation& lhs, const Expectation& rhs) const { 9095 return lhs.expectation_base_.get() < rhs.expectation_base_.get(); 9096 } 9097 }; 9098 9099 typedef ::std::set<Expectation, Less> Set; 9100 9101 Expectation( 9102 const internal::linked_ptr<internal::ExpectationBase>& expectation_base); 9103 9104 // Returns the expectation this object references. 9105 const internal::linked_ptr<internal::ExpectationBase>& 9106 expectation_base() const { 9107 return expectation_base_; 9108 } 9109 9110 // A linked_ptr that co-owns the expectation this handle references. 9111 internal::linked_ptr<internal::ExpectationBase> expectation_base_; 9112 }; 9113 9114 // A set of expectation handles. Useful in the .After() clause of 9115 // EXPECT_CALL() for setting the (partial) order of expectations. The 9116 // syntax: 9117 // 9118 // ExpectationSet es; 9119 // es += EXPECT_CALL(...)...; 9120 // es += EXPECT_CALL(...)...; 9121 // EXPECT_CALL(...).After(es)...; 9122 // 9123 // sets three expectations where the last one can only be matched 9124 // after the first two have both been satisfied. 9125 // 9126 // This class is copyable and has value semantics. 9127 class ExpectationSet { 9128 public: 9129 // A bidirectional iterator that can read a const element in the set. 9130 typedef Expectation::Set::const_iterator const_iterator; 9131 9132 // An object stored in the set. This is an alias of Expectation. 9133 typedef Expectation::Set::value_type value_type; 9134 9135 // Constructs an empty set. 9136 ExpectationSet() {} 9137 9138 // This single-argument ctor must not be explicit, in order to support the 9139 // ExpectationSet es = EXPECT_CALL(...); 9140 // syntax. 9141 ExpectationSet(internal::ExpectationBase& exp) { // NOLINT 9142 *this += Expectation(exp); 9143 } 9144 9145 // This single-argument ctor implements implicit conversion from 9146 // Expectation and thus must not be explicit. This allows either an 9147 // Expectation or an ExpectationSet to be used in .After(). 9148 ExpectationSet(const Expectation& e) { // NOLINT 9149 *this += e; 9150 } 9151 9152 // The compiler-generator ctor and operator= works exactly as 9153 // intended, so we don't need to define our own. 9154 9155 // Returns true iff rhs contains the same set of Expectation objects 9156 // as this does. 9157 bool operator==(const ExpectationSet& rhs) const { 9158 return expectations_ == rhs.expectations_; 9159 } 9160 9161 bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); } 9162 9163 // Implements the syntax 9164 // expectation_set += EXPECT_CALL(...); 9165 ExpectationSet& operator+=(const Expectation& e) { 9166 expectations_.insert(e); 9167 return *this; 9168 } 9169 9170 int size() const { return static_cast<int>(expectations_.size()); } 9171 9172 const_iterator begin() const { return expectations_.begin(); } 9173 const_iterator end() const { return expectations_.end(); } 9174 9175 private: 9176 Expectation::Set expectations_; 9177 }; 9178 9179 9180 // Sequence objects are used by a user to specify the relative order 9181 // in which the expectations should match. They are copyable (we rely 9182 // on the compiler-defined copy constructor and assignment operator). 9183 class GTEST_API_ Sequence { 9184 public: 9185 // Constructs an empty sequence. 9186 Sequence() : last_expectation_(new Expectation) {} 9187 9188 // Adds an expectation to this sequence. The caller must ensure 9189 // that no other thread is accessing this Sequence object. 9190 void AddExpectation(const Expectation& expectation) const; 9191 9192 private: 9193 // The last expectation in this sequence. We use a linked_ptr here 9194 // because Sequence objects are copyable and we want the copies to 9195 // be aliases. The linked_ptr allows the copies to co-own and share 9196 // the same Expectation object. 9197 internal::linked_ptr<Expectation> last_expectation_; 9198 }; // class Sequence 9199 9200 // An object of this type causes all EXPECT_CALL() statements 9201 // encountered in its scope to be put in an anonymous sequence. The 9202 // work is done in the constructor and destructor. You should only 9203 // create an InSequence object on the stack. 9204 // 9205 // The sole purpose for this class is to support easy definition of 9206 // sequential expectations, e.g. 9207 // 9208 // { 9209 // InSequence dummy; // The name of the object doesn't matter. 9210 // 9211 // // The following expectations must match in the order they appear. 9212 // EXPECT_CALL(a, Bar())...; 9213 // EXPECT_CALL(a, Baz())...; 9214 // ... 9215 // EXPECT_CALL(b, Xyz())...; 9216 // } 9217 // 9218 // You can create InSequence objects in multiple threads, as long as 9219 // they are used to affect different mock objects. The idea is that 9220 // each thread can create and set up its own mocks as if it's the only 9221 // thread. However, for clarity of your tests we recommend you to set 9222 // up mocks in the main thread unless you have a good reason not to do 9223 // so. 9224 class GTEST_API_ InSequence { 9225 public: 9226 InSequence(); 9227 ~InSequence(); 9228 private: 9229 bool sequence_created_; 9230 9231 GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT 9232 } GTEST_ATTRIBUTE_UNUSED_; 9233 9234 namespace internal { 9235 9236 // Points to the implicit sequence introduced by a living InSequence 9237 // object (if any) in the current thread or NULL. 9238 GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence; 9239 9240 // Base class for implementing expectations. 9241 // 9242 // There are two reasons for having a type-agnostic base class for 9243 // Expectation: 9244 // 9245 // 1. We need to store collections of expectations of different 9246 // types (e.g. all pre-requisites of a particular expectation, all 9247 // expectations in a sequence). Therefore these expectation objects 9248 // must share a common base class. 9249 // 9250 // 2. We can avoid binary code bloat by moving methods not depending 9251 // on the template argument of Expectation to the base class. 9252 // 9253 // This class is internal and mustn't be used by user code directly. 9254 class GTEST_API_ ExpectationBase { 9255 public: 9256 // source_text is the EXPECT_CALL(...) source that created this Expectation. 9257 ExpectationBase(const char* file, int line, const string& source_text); 9258 9259 virtual ~ExpectationBase(); 9260 9261 // Where in the source file was the expectation spec defined? 9262 const char* file() const { return file_; } 9263 int line() const { return line_; } 9264 const char* source_text() const { return source_text_.c_str(); } 9265 // Returns the cardinality specified in the expectation spec. 9266 const Cardinality& cardinality() const { return cardinality_; } 9267 9268 // Describes the source file location of this expectation. 9269 void DescribeLocationTo(::std::ostream* os) const { 9270 *os << FormatFileLocation(file(), line()) << " "; 9271 } 9272 9273 // Describes how many times a function call matching this 9274 // expectation has occurred. 9275 void DescribeCallCountTo(::std::ostream* os) const 9276 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); 9277 9278 // If this mock method has an extra matcher (i.e. .With(matcher)), 9279 // describes it to the ostream. 9280 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0; 9281 9282 protected: 9283 friend class ::testing::Expectation; 9284 friend class UntypedFunctionMockerBase; 9285 9286 enum Clause { 9287 // Don't change the order of the enum members! 9288 kNone, 9289 kWith, 9290 kTimes, 9291 kInSequence, 9292 kAfter, 9293 kWillOnce, 9294 kWillRepeatedly, 9295 kRetiresOnSaturation 9296 }; 9297 9298 typedef std::vector<const void*> UntypedActions; 9299 9300 // Returns an Expectation object that references and co-owns this 9301 // expectation. 9302 virtual Expectation GetHandle() = 0; 9303 9304 // Asserts that the EXPECT_CALL() statement has the given property. 9305 void AssertSpecProperty(bool property, const string& failure_message) const { 9306 Assert(property, file_, line_, failure_message); 9307 } 9308 9309 // Expects that the EXPECT_CALL() statement has the given property. 9310 void ExpectSpecProperty(bool property, const string& failure_message) const { 9311 Expect(property, file_, line_, failure_message); 9312 } 9313 9314 // Explicitly specifies the cardinality of this expectation. Used 9315 // by the subclasses to implement the .Times() clause. 9316 void SpecifyCardinality(const Cardinality& cardinality); 9317 9318 // Returns true iff the user specified the cardinality explicitly 9319 // using a .Times(). 9320 bool cardinality_specified() const { return cardinality_specified_; } 9321 9322 // Sets the cardinality of this expectation spec. 9323 void set_cardinality(const Cardinality& a_cardinality) { 9324 cardinality_ = a_cardinality; 9325 } 9326 9327 // The following group of methods should only be called after the 9328 // EXPECT_CALL() statement, and only when g_gmock_mutex is held by 9329 // the current thread. 9330 9331 // Retires all pre-requisites of this expectation. 9332 void RetireAllPreRequisites() 9333 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); 9334 9335 // Returns true iff this expectation is retired. 9336 bool is_retired() const 9337 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9338 g_gmock_mutex.AssertHeld(); 9339 return retired_; 9340 } 9341 9342 // Retires this expectation. 9343 void Retire() 9344 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9345 g_gmock_mutex.AssertHeld(); 9346 retired_ = true; 9347 } 9348 9349 // Returns true iff this expectation is satisfied. 9350 bool IsSatisfied() const 9351 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9352 g_gmock_mutex.AssertHeld(); 9353 return cardinality().IsSatisfiedByCallCount(call_count_); 9354 } 9355 9356 // Returns true iff this expectation is saturated. 9357 bool IsSaturated() const 9358 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9359 g_gmock_mutex.AssertHeld(); 9360 return cardinality().IsSaturatedByCallCount(call_count_); 9361 } 9362 9363 // Returns true iff this expectation is over-saturated. 9364 bool IsOverSaturated() const 9365 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9366 g_gmock_mutex.AssertHeld(); 9367 return cardinality().IsOverSaturatedByCallCount(call_count_); 9368 } 9369 9370 // Returns true iff all pre-requisites of this expectation are satisfied. 9371 bool AllPrerequisitesAreSatisfied() const 9372 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); 9373 9374 // Adds unsatisfied pre-requisites of this expectation to 'result'. 9375 void FindUnsatisfiedPrerequisites(ExpectationSet* result) const 9376 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); 9377 9378 // Returns the number this expectation has been invoked. 9379 int call_count() const 9380 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9381 g_gmock_mutex.AssertHeld(); 9382 return call_count_; 9383 } 9384 9385 // Increments the number this expectation has been invoked. 9386 void IncrementCallCount() 9387 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9388 g_gmock_mutex.AssertHeld(); 9389 call_count_++; 9390 } 9391 9392 // Checks the action count (i.e. the number of WillOnce() and 9393 // WillRepeatedly() clauses) against the cardinality if this hasn't 9394 // been done before. Prints a warning if there are too many or too 9395 // few actions. 9396 void CheckActionCountIfNotDone() const 9397 GTEST_LOCK_EXCLUDED_(mutex_); 9398 9399 friend class ::testing::Sequence; 9400 friend class ::testing::internal::ExpectationTester; 9401 9402 template <typename Function> 9403 friend class TypedExpectation; 9404 9405 // Implements the .Times() clause. 9406 void UntypedTimes(const Cardinality& a_cardinality); 9407 9408 // This group of fields are part of the spec and won't change after 9409 // an EXPECT_CALL() statement finishes. 9410 const char* file_; // The file that contains the expectation. 9411 int line_; // The line number of the expectation. 9412 const string source_text_; // The EXPECT_CALL(...) source text. 9413 // True iff the cardinality is specified explicitly. 9414 bool cardinality_specified_; 9415 Cardinality cardinality_; // The cardinality of the expectation. 9416 // The immediate pre-requisites (i.e. expectations that must be 9417 // satisfied before this expectation can be matched) of this 9418 // expectation. We use linked_ptr in the set because we want an 9419 // Expectation object to be co-owned by its FunctionMocker and its 9420 // successors. This allows multiple mock objects to be deleted at 9421 // different times. 9422 ExpectationSet immediate_prerequisites_; 9423 9424 // This group of fields are the current state of the expectation, 9425 // and can change as the mock function is called. 9426 int call_count_; // How many times this expectation has been invoked. 9427 bool retired_; // True iff this expectation has retired. 9428 UntypedActions untyped_actions_; 9429 bool extra_matcher_specified_; 9430 bool repeated_action_specified_; // True if a WillRepeatedly() was specified. 9431 bool retires_on_saturation_; 9432 Clause last_clause_; 9433 mutable bool action_count_checked_; // Under mutex_. 9434 mutable Mutex mutex_; // Protects action_count_checked_. 9435 9436 GTEST_DISALLOW_ASSIGN_(ExpectationBase); 9437 }; // class ExpectationBase 9438 9439 // Impements an expectation for the given function type. 9440 template <typename F> 9441 class TypedExpectation : public ExpectationBase { 9442 public: 9443 typedef typename Function<F>::ArgumentTuple ArgumentTuple; 9444 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; 9445 typedef typename Function<F>::Result Result; 9446 9447 TypedExpectation(FunctionMockerBase<F>* owner, 9448 const char* a_file, int a_line, const string& a_source_text, 9449 const ArgumentMatcherTuple& m) 9450 : ExpectationBase(a_file, a_line, a_source_text), 9451 owner_(owner), 9452 matchers_(m), 9453 // By default, extra_matcher_ should match anything. However, 9454 // we cannot initialize it with _ as that triggers a compiler 9455 // bug in Symbian's C++ compiler (cannot decide between two 9456 // overloaded constructors of Matcher<const ArgumentTuple&>). 9457 extra_matcher_(A<const ArgumentTuple&>()), 9458 repeated_action_(DoDefault()) {} 9459 9460 virtual ~TypedExpectation() { 9461 // Check the validity of the action count if it hasn't been done 9462 // yet (for example, if the expectation was never used). 9463 CheckActionCountIfNotDone(); 9464 for (UntypedActions::const_iterator it = untyped_actions_.begin(); 9465 it != untyped_actions_.end(); ++it) { 9466 delete static_cast<const Action<F>*>(*it); 9467 } 9468 } 9469 9470 // Implements the .With() clause. 9471 TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) { 9472 if (last_clause_ == kWith) { 9473 ExpectSpecProperty(false, 9474 ".With() cannot appear " 9475 "more than once in an EXPECT_CALL()."); 9476 } else { 9477 ExpectSpecProperty(last_clause_ < kWith, 9478 ".With() must be the first " 9479 "clause in an EXPECT_CALL()."); 9480 } 9481 last_clause_ = kWith; 9482 9483 extra_matcher_ = m; 9484 extra_matcher_specified_ = true; 9485 return *this; 9486 } 9487 9488 // Implements the .Times() clause. 9489 TypedExpectation& Times(const Cardinality& a_cardinality) { 9490 ExpectationBase::UntypedTimes(a_cardinality); 9491 return *this; 9492 } 9493 9494 // Implements the .Times() clause. 9495 TypedExpectation& Times(int n) { 9496 return Times(Exactly(n)); 9497 } 9498 9499 // Implements the .InSequence() clause. 9500 TypedExpectation& InSequence(const Sequence& s) { 9501 ExpectSpecProperty(last_clause_ <= kInSequence, 9502 ".InSequence() cannot appear after .After()," 9503 " .WillOnce(), .WillRepeatedly(), or " 9504 ".RetiresOnSaturation()."); 9505 last_clause_ = kInSequence; 9506 9507 s.AddExpectation(GetHandle()); 9508 return *this; 9509 } 9510 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) { 9511 return InSequence(s1).InSequence(s2); 9512 } 9513 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, 9514 const Sequence& s3) { 9515 return InSequence(s1, s2).InSequence(s3); 9516 } 9517 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, 9518 const Sequence& s3, const Sequence& s4) { 9519 return InSequence(s1, s2, s3).InSequence(s4); 9520 } 9521 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, 9522 const Sequence& s3, const Sequence& s4, 9523 const Sequence& s5) { 9524 return InSequence(s1, s2, s3, s4).InSequence(s5); 9525 } 9526 9527 // Implements that .After() clause. 9528 TypedExpectation& After(const ExpectationSet& s) { 9529 ExpectSpecProperty(last_clause_ <= kAfter, 9530 ".After() cannot appear after .WillOnce()," 9531 " .WillRepeatedly(), or " 9532 ".RetiresOnSaturation()."); 9533 last_clause_ = kAfter; 9534 9535 for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) { 9536 immediate_prerequisites_ += *it; 9537 } 9538 return *this; 9539 } 9540 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) { 9541 return After(s1).After(s2); 9542 } 9543 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, 9544 const ExpectationSet& s3) { 9545 return After(s1, s2).After(s3); 9546 } 9547 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, 9548 const ExpectationSet& s3, const ExpectationSet& s4) { 9549 return After(s1, s2, s3).After(s4); 9550 } 9551 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, 9552 const ExpectationSet& s3, const ExpectationSet& s4, 9553 const ExpectationSet& s5) { 9554 return After(s1, s2, s3, s4).After(s5); 9555 } 9556 9557 // Implements the .WillOnce() clause. 9558 TypedExpectation& WillOnce(const Action<F>& action) { 9559 ExpectSpecProperty(last_clause_ <= kWillOnce, 9560 ".WillOnce() cannot appear after " 9561 ".WillRepeatedly() or .RetiresOnSaturation()."); 9562 last_clause_ = kWillOnce; 9563 9564 untyped_actions_.push_back(new Action<F>(action)); 9565 if (!cardinality_specified()) { 9566 set_cardinality(Exactly(static_cast<int>(untyped_actions_.size()))); 9567 } 9568 return *this; 9569 } 9570 9571 // Implements the .WillRepeatedly() clause. 9572 TypedExpectation& WillRepeatedly(const Action<F>& action) { 9573 if (last_clause_ == kWillRepeatedly) { 9574 ExpectSpecProperty(false, 9575 ".WillRepeatedly() cannot appear " 9576 "more than once in an EXPECT_CALL()."); 9577 } else { 9578 ExpectSpecProperty(last_clause_ < kWillRepeatedly, 9579 ".WillRepeatedly() cannot appear " 9580 "after .RetiresOnSaturation()."); 9581 } 9582 last_clause_ = kWillRepeatedly; 9583 repeated_action_specified_ = true; 9584 9585 repeated_action_ = action; 9586 if (!cardinality_specified()) { 9587 set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size()))); 9588 } 9589 9590 // Now that no more action clauses can be specified, we check 9591 // whether their count makes sense. 9592 CheckActionCountIfNotDone(); 9593 return *this; 9594 } 9595 9596 // Implements the .RetiresOnSaturation() clause. 9597 TypedExpectation& RetiresOnSaturation() { 9598 ExpectSpecProperty(last_clause_ < kRetiresOnSaturation, 9599 ".RetiresOnSaturation() cannot appear " 9600 "more than once."); 9601 last_clause_ = kRetiresOnSaturation; 9602 retires_on_saturation_ = true; 9603 9604 // Now that no more action clauses can be specified, we check 9605 // whether their count makes sense. 9606 CheckActionCountIfNotDone(); 9607 return *this; 9608 } 9609 9610 // Returns the matchers for the arguments as specified inside the 9611 // EXPECT_CALL() macro. 9612 const ArgumentMatcherTuple& matchers() const { 9613 return matchers_; 9614 } 9615 9616 // Returns the matcher specified by the .With() clause. 9617 const Matcher<const ArgumentTuple&>& extra_matcher() const { 9618 return extra_matcher_; 9619 } 9620 9621 // Returns the action specified by the .WillRepeatedly() clause. 9622 const Action<F>& repeated_action() const { return repeated_action_; } 9623 9624 // If this mock method has an extra matcher (i.e. .With(matcher)), 9625 // describes it to the ostream. 9626 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) { 9627 if (extra_matcher_specified_) { 9628 *os << " Expected args: "; 9629 extra_matcher_.DescribeTo(os); 9630 *os << "\n"; 9631 } 9632 } 9633 9634 private: 9635 template <typename Function> 9636 friend class FunctionMockerBase; 9637 9638 // Returns an Expectation object that references and co-owns this 9639 // expectation. 9640 virtual Expectation GetHandle() { 9641 return owner_->GetHandleOf(this); 9642 } 9643 9644 // The following methods will be called only after the EXPECT_CALL() 9645 // statement finishes and when the current thread holds 9646 // g_gmock_mutex. 9647 9648 // Returns true iff this expectation matches the given arguments. 9649 bool Matches(const ArgumentTuple& args) const 9650 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9651 g_gmock_mutex.AssertHeld(); 9652 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args); 9653 } 9654 9655 // Returns true iff this expectation should handle the given arguments. 9656 bool ShouldHandleArguments(const ArgumentTuple& args) const 9657 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9658 g_gmock_mutex.AssertHeld(); 9659 9660 // In case the action count wasn't checked when the expectation 9661 // was defined (e.g. if this expectation has no WillRepeatedly() 9662 // or RetiresOnSaturation() clause), we check it when the 9663 // expectation is used for the first time. 9664 CheckActionCountIfNotDone(); 9665 return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args); 9666 } 9667 9668 // Describes the result of matching the arguments against this 9669 // expectation to the given ostream. 9670 void ExplainMatchResultTo( 9671 const ArgumentTuple& args, 9672 ::std::ostream* os) const 9673 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9674 g_gmock_mutex.AssertHeld(); 9675 9676 if (is_retired()) { 9677 *os << " Expected: the expectation is active\n" 9678 << " Actual: it is retired\n"; 9679 } else if (!Matches(args)) { 9680 if (!TupleMatches(matchers_, args)) { 9681 ExplainMatchFailureTupleTo(matchers_, args, os); 9682 } 9683 StringMatchResultListener listener; 9684 if (!extra_matcher_.MatchAndExplain(args, &listener)) { 9685 *os << " Expected args: "; 9686 extra_matcher_.DescribeTo(os); 9687 *os << "\n Actual: don't match"; 9688 9689 internal::PrintIfNotEmpty(listener.str(), os); 9690 *os << "\n"; 9691 } 9692 } else if (!AllPrerequisitesAreSatisfied()) { 9693 *os << " Expected: all pre-requisites are satisfied\n" 9694 << " Actual: the following immediate pre-requisites " 9695 << "are not satisfied:\n"; 9696 ExpectationSet unsatisfied_prereqs; 9697 FindUnsatisfiedPrerequisites(&unsatisfied_prereqs); 9698 int i = 0; 9699 for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin(); 9700 it != unsatisfied_prereqs.end(); ++it) { 9701 it->expectation_base()->DescribeLocationTo(os); 9702 *os << "pre-requisite #" << i++ << "\n"; 9703 } 9704 *os << " (end of pre-requisites)\n"; 9705 } else { 9706 // This line is here just for completeness' sake. It will never 9707 // be executed as currently the ExplainMatchResultTo() function 9708 // is called only when the mock function call does NOT match the 9709 // expectation. 9710 *os << "The call matches the expectation.\n"; 9711 } 9712 } 9713 9714 // Returns the action that should be taken for the current invocation. 9715 const Action<F>& GetCurrentAction( 9716 const FunctionMockerBase<F>* mocker, 9717 const ArgumentTuple& args) const 9718 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9719 g_gmock_mutex.AssertHeld(); 9720 const int count = call_count(); 9721 Assert(count >= 1, __FILE__, __LINE__, 9722 "call_count() is <= 0 when GetCurrentAction() is " 9723 "called - this should never happen."); 9724 9725 const int action_count = static_cast<int>(untyped_actions_.size()); 9726 if (action_count > 0 && !repeated_action_specified_ && 9727 count > action_count) { 9728 // If there is at least one WillOnce() and no WillRepeatedly(), 9729 // we warn the user when the WillOnce() clauses ran out. 9730 ::std::stringstream ss; 9731 DescribeLocationTo(&ss); 9732 ss << "Actions ran out in " << source_text() << "...\n" 9733 << "Called " << count << " times, but only " 9734 << action_count << " WillOnce()" 9735 << (action_count == 1 ? " is" : "s are") << " specified - "; 9736 mocker->DescribeDefaultActionTo(args, &ss); 9737 Log(kWarning, ss.str(), 1); 9738 } 9739 9740 return count <= action_count ? 9741 *static_cast<const Action<F>*>(untyped_actions_[count - 1]) : 9742 repeated_action(); 9743 } 9744 9745 // Given the arguments of a mock function call, if the call will 9746 // over-saturate this expectation, returns the default action; 9747 // otherwise, returns the next action in this expectation. Also 9748 // describes *what* happened to 'what', and explains *why* Google 9749 // Mock does it to 'why'. This method is not const as it calls 9750 // IncrementCallCount(). A return value of NULL means the default 9751 // action. 9752 const Action<F>* GetActionForArguments( 9753 const FunctionMockerBase<F>* mocker, 9754 const ArgumentTuple& args, 9755 ::std::ostream* what, 9756 ::std::ostream* why) 9757 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 9758 g_gmock_mutex.AssertHeld(); 9759 if (IsSaturated()) { 9760 // We have an excessive call. 9761 IncrementCallCount(); 9762 *what << "Mock function called more times than expected - "; 9763 mocker->DescribeDefaultActionTo(args, what); 9764 DescribeCallCountTo(why); 9765 9766 // TODO(wan@google.com): allow the user to control whether 9767 // unexpected calls should fail immediately or continue using a 9768 // flag --gmock_unexpected_calls_are_fatal. 9769 return NULL; 9770 } 9771 9772 IncrementCallCount(); 9773 RetireAllPreRequisites(); 9774 9775 if (retires_on_saturation_ && IsSaturated()) { 9776 Retire(); 9777 } 9778 9779 // Must be done after IncrementCount()! 9780 *what << "Mock function call matches " << source_text() <<"...\n"; 9781 return &(GetCurrentAction(mocker, args)); 9782 } 9783 9784 // All the fields below won't change once the EXPECT_CALL() 9785 // statement finishes. 9786 FunctionMockerBase<F>* const owner_; 9787 ArgumentMatcherTuple matchers_; 9788 Matcher<const ArgumentTuple&> extra_matcher_; 9789 Action<F> repeated_action_; 9790 9791 GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation); 9792 }; // class TypedExpectation 9793 9794 // A MockSpec object is used by ON_CALL() or EXPECT_CALL() for 9795 // specifying the default behavior of, or expectation on, a mock 9796 // function. 9797 9798 // Note: class MockSpec really belongs to the ::testing namespace. 9799 // However if we define it in ::testing, MSVC will complain when 9800 // classes in ::testing::internal declare it as a friend class 9801 // template. To workaround this compiler bug, we define MockSpec in 9802 // ::testing::internal and import it into ::testing. 9803 9804 // Logs a message including file and line number information. 9805 GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity, 9806 const char* file, int line, 9807 const string& message); 9808 9809 template <typename F> 9810 class MockSpec { 9811 public: 9812 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 9813 typedef typename internal::Function<F>::ArgumentMatcherTuple 9814 ArgumentMatcherTuple; 9815 9816 // Constructs a MockSpec object, given the function mocker object 9817 // that the spec is associated with. 9818 explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker) 9819 : function_mocker_(function_mocker) {} 9820 9821 // Adds a new default action spec to the function mocker and returns 9822 // the newly created spec. 9823 internal::OnCallSpec<F>& InternalDefaultActionSetAt( 9824 const char* file, int line, const char* obj, const char* call) { 9825 LogWithLocation(internal::kInfo, file, line, 9826 string("ON_CALL(") + obj + ", " + call + ") invoked"); 9827 return function_mocker_->AddNewOnCallSpec(file, line, matchers_); 9828 } 9829 9830 // Adds a new expectation spec to the function mocker and returns 9831 // the newly created spec. 9832 internal::TypedExpectation<F>& InternalExpectedAt( 9833 const char* file, int line, const char* obj, const char* call) { 9834 const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")"); 9835 LogWithLocation(internal::kInfo, file, line, source_text + " invoked"); 9836 return function_mocker_->AddNewExpectation( 9837 file, line, source_text, matchers_); 9838 } 9839 9840 private: 9841 template <typename Function> 9842 friend class internal::FunctionMocker; 9843 9844 void SetMatchers(const ArgumentMatcherTuple& matchers) { 9845 matchers_ = matchers; 9846 } 9847 9848 // The function mocker that owns this spec. 9849 internal::FunctionMockerBase<F>* const function_mocker_; 9850 // The argument matchers specified in the spec. 9851 ArgumentMatcherTuple matchers_; 9852 9853 GTEST_DISALLOW_ASSIGN_(MockSpec); 9854 }; // class MockSpec 9855 9856 // MSVC warns about using 'this' in base member initializer list, so 9857 // we need to temporarily disable the warning. We have to do it for 9858 // the entire class to suppress the warning, even though it's about 9859 // the constructor only. 9860 9861 #ifdef _MSC_VER 9862 # pragma warning(push) // Saves the current warning state. 9863 # pragma warning(disable:4355) // Temporarily disables warning 4355. 9864 #endif // _MSV_VER 9865 9866 // C++ treats the void type specially. For example, you cannot define 9867 // a void-typed variable or pass a void value to a function. 9868 // ActionResultHolder<T> holds a value of type T, where T must be a 9869 // copyable type or void (T doesn't need to be default-constructable). 9870 // It hides the syntactic difference between void and other types, and 9871 // is used to unify the code for invoking both void-returning and 9872 // non-void-returning mock functions. 9873 9874 // Untyped base class for ActionResultHolder<T>. 9875 class UntypedActionResultHolderBase { 9876 public: 9877 virtual ~UntypedActionResultHolderBase() {} 9878 9879 // Prints the held value as an action's result to os. 9880 virtual void PrintAsActionResult(::std::ostream* os) const = 0; 9881 }; 9882 9883 // This generic definition is used when T is not void. 9884 template <typename T> 9885 class ActionResultHolder : public UntypedActionResultHolderBase { 9886 public: 9887 explicit ActionResultHolder(T a_value) : value_(a_value) {} 9888 9889 // The compiler-generated copy constructor and assignment operator 9890 // are exactly what we need, so we don't need to define them. 9891 9892 // Returns the held value and deletes this object. 9893 T GetValueAndDelete() const { 9894 T retval(value_); 9895 delete this; 9896 return retval; 9897 } 9898 9899 // Prints the held value as an action's result to os. 9900 virtual void PrintAsActionResult(::std::ostream* os) const { 9901 *os << "\n Returns: "; 9902 // T may be a reference type, so we don't use UniversalPrint(). 9903 UniversalPrinter<T>::Print(value_, os); 9904 } 9905 9906 // Performs the given mock function's default action and returns the 9907 // result in a new-ed ActionResultHolder. 9908 template <typename F> 9909 static ActionResultHolder* PerformDefaultAction( 9910 const FunctionMockerBase<F>* func_mocker, 9911 const typename Function<F>::ArgumentTuple& args, 9912 const string& call_description) { 9913 return new ActionResultHolder( 9914 func_mocker->PerformDefaultAction(args, call_description)); 9915 } 9916 9917 // Performs the given action and returns the result in a new-ed 9918 // ActionResultHolder. 9919 template <typename F> 9920 static ActionResultHolder* 9921 PerformAction(const Action<F>& action, 9922 const typename Function<F>::ArgumentTuple& args) { 9923 return new ActionResultHolder(action.Perform(args)); 9924 } 9925 9926 private: 9927 T value_; 9928 9929 // T could be a reference type, so = isn't supported. 9930 GTEST_DISALLOW_ASSIGN_(ActionResultHolder); 9931 }; 9932 9933 // Specialization for T = void. 9934 template <> 9935 class ActionResultHolder<void> : public UntypedActionResultHolderBase { 9936 public: 9937 void GetValueAndDelete() const { delete this; } 9938 9939 virtual void PrintAsActionResult(::std::ostream* /* os */) const {} 9940 9941 // Performs the given mock function's default action and returns NULL; 9942 template <typename F> 9943 static ActionResultHolder* PerformDefaultAction( 9944 const FunctionMockerBase<F>* func_mocker, 9945 const typename Function<F>::ArgumentTuple& args, 9946 const string& call_description) { 9947 func_mocker->PerformDefaultAction(args, call_description); 9948 return NULL; 9949 } 9950 9951 // Performs the given action and returns NULL. 9952 template <typename F> 9953 static ActionResultHolder* PerformAction( 9954 const Action<F>& action, 9955 const typename Function<F>::ArgumentTuple& args) { 9956 action.Perform(args); 9957 return NULL; 9958 } 9959 }; 9960 9961 // The base of the function mocker class for the given function type. 9962 // We put the methods in this class instead of its child to avoid code 9963 // bloat. 9964 template <typename F> 9965 class FunctionMockerBase : public UntypedFunctionMockerBase { 9966 public: 9967 typedef typename Function<F>::Result Result; 9968 typedef typename Function<F>::ArgumentTuple ArgumentTuple; 9969 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; 9970 9971 FunctionMockerBase() : current_spec_(this) {} 9972 9973 // The destructor verifies that all expectations on this mock 9974 // function have been satisfied. If not, it will report Google Test 9975 // non-fatal failures for the violations. 9976 virtual ~FunctionMockerBase() 9977 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { 9978 MutexLock l(&g_gmock_mutex); 9979 VerifyAndClearExpectationsLocked(); 9980 Mock::UnregisterLocked(this); 9981 ClearDefaultActionsLocked(); 9982 } 9983 9984 // Returns the ON_CALL spec that matches this mock function with the 9985 // given arguments; returns NULL if no matching ON_CALL is found. 9986 // L = * 9987 const OnCallSpec<F>* FindOnCallSpec( 9988 const ArgumentTuple& args) const { 9989 for (UntypedOnCallSpecs::const_reverse_iterator it 9990 = untyped_on_call_specs_.rbegin(); 9991 it != untyped_on_call_specs_.rend(); ++it) { 9992 const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it); 9993 if (spec->Matches(args)) 9994 return spec; 9995 } 9996 9997 return NULL; 9998 } 9999 10000 // Performs the default action of this mock function on the given 10001 // arguments and returns the result. Asserts (or throws if 10002 // exceptions are enabled) with a helpful call descrption if there 10003 // is no valid return value. This method doesn't depend on the 10004 // mutable state of this object, and thus can be called concurrently 10005 // without locking. 10006 // L = * 10007 Result PerformDefaultAction(const ArgumentTuple& args, 10008 const string& call_description) const { 10009 const OnCallSpec<F>* const spec = 10010 this->FindOnCallSpec(args); 10011 if (spec != NULL) { 10012 return spec->GetAction().Perform(args); 10013 } 10014 const string message = call_description + 10015 "\n The mock function has no default action " 10016 "set, and its return type has no default value set."; 10017 #if GTEST_HAS_EXCEPTIONS 10018 if (!DefaultValue<Result>::Exists()) { 10019 throw std::runtime_error(message); 10020 } 10021 #else 10022 Assert(DefaultValue<Result>::Exists(), "", -1, message); 10023 #endif 10024 return DefaultValue<Result>::Get(); 10025 } 10026 10027 // Performs the default action with the given arguments and returns 10028 // the action's result. The call description string will be used in 10029 // the error message to describe the call in the case the default 10030 // action fails. The caller is responsible for deleting the result. 10031 // L = * 10032 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( 10033 const void* untyped_args, // must point to an ArgumentTuple 10034 const string& call_description) const { 10035 const ArgumentTuple& args = 10036 *static_cast<const ArgumentTuple*>(untyped_args); 10037 return ResultHolder::PerformDefaultAction(this, args, call_description); 10038 } 10039 10040 // Performs the given action with the given arguments and returns 10041 // the action's result. The caller is responsible for deleting the 10042 // result. 10043 // L = * 10044 virtual UntypedActionResultHolderBase* UntypedPerformAction( 10045 const void* untyped_action, const void* untyped_args) const { 10046 // Make a copy of the action before performing it, in case the 10047 // action deletes the mock object (and thus deletes itself). 10048 const Action<F> action = *static_cast<const Action<F>*>(untyped_action); 10049 const ArgumentTuple& args = 10050 *static_cast<const ArgumentTuple*>(untyped_args); 10051 return ResultHolder::PerformAction(action, args); 10052 } 10053 10054 // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked(): 10055 // clears the ON_CALL()s set on this mock function. 10056 virtual void ClearDefaultActionsLocked() 10057 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 10058 g_gmock_mutex.AssertHeld(); 10059 10060 // Deleting our default actions may trigger other mock objects to be 10061 // deleted, for example if an action contains a reference counted smart 10062 // pointer to that mock object, and that is the last reference. So if we 10063 // delete our actions within the context of the global mutex we may deadlock 10064 // when this method is called again. Instead, make a copy of the set of 10065 // actions to delete, clear our set within the mutex, and then delete the 10066 // actions outside of the mutex. 10067 UntypedOnCallSpecs specs_to_delete; 10068 untyped_on_call_specs_.swap(specs_to_delete); 10069 10070 g_gmock_mutex.Unlock(); 10071 for (UntypedOnCallSpecs::const_iterator it = 10072 specs_to_delete.begin(); 10073 it != specs_to_delete.end(); ++it) { 10074 delete static_cast<const OnCallSpec<F>*>(*it); 10075 } 10076 10077 // Lock the mutex again, since the caller expects it to be locked when we 10078 // return. 10079 g_gmock_mutex.Lock(); 10080 } 10081 10082 protected: 10083 template <typename Function> 10084 friend class MockSpec; 10085 10086 typedef ActionResultHolder<Result> ResultHolder; 10087 10088 // Returns the result of invoking this mock function with the given 10089 // arguments. This function can be safely called from multiple 10090 // threads concurrently. 10091 Result InvokeWith(const ArgumentTuple& args) 10092 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { 10093 const ResultHolder *rh = static_cast<const ResultHolder*>( 10094 this->UntypedInvokeWith(&args)); 10095 return rh ? rh->GetValueAndDelete() : Result(); 10096 } 10097 10098 // Adds and returns a default action spec for this mock function. 10099 OnCallSpec<F>& AddNewOnCallSpec( 10100 const char* file, int line, 10101 const ArgumentMatcherTuple& m) 10102 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { 10103 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); 10104 OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m); 10105 untyped_on_call_specs_.push_back(on_call_spec); 10106 return *on_call_spec; 10107 } 10108 10109 // Adds and returns an expectation spec for this mock function. 10110 TypedExpectation<F>& AddNewExpectation( 10111 const char* file, 10112 int line, 10113 const string& source_text, 10114 const ArgumentMatcherTuple& m) 10115 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { 10116 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); 10117 TypedExpectation<F>* const expectation = 10118 new TypedExpectation<F>(this, file, line, source_text, m); 10119 const linked_ptr<ExpectationBase> untyped_expectation(expectation); 10120 untyped_expectations_.push_back(untyped_expectation); 10121 10122 // Adds this expectation into the implicit sequence if there is one. 10123 Sequence* const implicit_sequence = g_gmock_implicit_sequence.get(); 10124 if (implicit_sequence != NULL) { 10125 implicit_sequence->AddExpectation(Expectation(untyped_expectation)); 10126 } 10127 10128 return *expectation; 10129 } 10130 10131 // The current spec (either default action spec or expectation spec) 10132 // being described on this function mocker. 10133 MockSpec<F>& current_spec() { return current_spec_; } 10134 10135 private: 10136 template <typename Func> friend class TypedExpectation; 10137 10138 // Some utilities needed for implementing UntypedInvokeWith(). 10139 10140 // Describes what default action will be performed for the given 10141 // arguments. 10142 // L = * 10143 void DescribeDefaultActionTo(const ArgumentTuple& args, 10144 ::std::ostream* os) const { 10145 const OnCallSpec<F>* const spec = FindOnCallSpec(args); 10146 10147 if (spec == NULL) { 10148 *os << (internal::type_equals<Result, void>::value ? 10149 "returning directly.\n" : 10150 "returning default value.\n"); 10151 } else { 10152 *os << "taking default action specified at:\n" 10153 << FormatFileLocation(spec->file(), spec->line()) << "\n"; 10154 } 10155 } 10156 10157 // Writes a message that the call is uninteresting (i.e. neither 10158 // explicitly expected nor explicitly unexpected) to the given 10159 // ostream. 10160 virtual void UntypedDescribeUninterestingCall( 10161 const void* untyped_args, 10162 ::std::ostream* os) const 10163 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { 10164 const ArgumentTuple& args = 10165 *static_cast<const ArgumentTuple*>(untyped_args); 10166 *os << "Uninteresting mock function call - "; 10167 DescribeDefaultActionTo(args, os); 10168 *os << " Function call: " << Name(); 10169 UniversalPrint(args, os); 10170 } 10171 10172 // Returns the expectation that matches the given function arguments 10173 // (or NULL is there's no match); when a match is found, 10174 // untyped_action is set to point to the action that should be 10175 // performed (or NULL if the action is "do default"), and 10176 // is_excessive is modified to indicate whether the call exceeds the 10177 // expected number. 10178 // 10179 // Critical section: We must find the matching expectation and the 10180 // corresponding action that needs to be taken in an ATOMIC 10181 // transaction. Otherwise another thread may call this mock 10182 // method in the middle and mess up the state. 10183 // 10184 // However, performing the action has to be left out of the critical 10185 // section. The reason is that we have no control on what the 10186 // action does (it can invoke an arbitrary user function or even a 10187 // mock function) and excessive locking could cause a dead lock. 10188 virtual const ExpectationBase* UntypedFindMatchingExpectation( 10189 const void* untyped_args, 10190 const void** untyped_action, bool* is_excessive, 10191 ::std::ostream* what, ::std::ostream* why) 10192 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { 10193 const ArgumentTuple& args = 10194 *static_cast<const ArgumentTuple*>(untyped_args); 10195 MutexLock l(&g_gmock_mutex); 10196 TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args); 10197 if (exp == NULL) { // A match wasn't found. 10198 this->FormatUnexpectedCallMessageLocked(args, what, why); 10199 return NULL; 10200 } 10201 10202 // This line must be done before calling GetActionForArguments(), 10203 // which will increment the call count for *exp and thus affect 10204 // its saturation status. 10205 *is_excessive = exp->IsSaturated(); 10206 const Action<F>* action = exp->GetActionForArguments(this, args, what, why); 10207 if (action != NULL && action->IsDoDefault()) 10208 action = NULL; // Normalize "do default" to NULL. 10209 *untyped_action = action; 10210 return exp; 10211 } 10212 10213 // Prints the given function arguments to the ostream. 10214 virtual void UntypedPrintArgs(const void* untyped_args, 10215 ::std::ostream* os) const { 10216 const ArgumentTuple& args = 10217 *static_cast<const ArgumentTuple*>(untyped_args); 10218 UniversalPrint(args, os); 10219 } 10220 10221 // Returns the expectation that matches the arguments, or NULL if no 10222 // expectation matches them. 10223 TypedExpectation<F>* FindMatchingExpectationLocked( 10224 const ArgumentTuple& args) const 10225 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 10226 g_gmock_mutex.AssertHeld(); 10227 for (typename UntypedExpectations::const_reverse_iterator it = 10228 untyped_expectations_.rbegin(); 10229 it != untyped_expectations_.rend(); ++it) { 10230 TypedExpectation<F>* const exp = 10231 static_cast<TypedExpectation<F>*>(it->get()); 10232 if (exp->ShouldHandleArguments(args)) { 10233 return exp; 10234 } 10235 } 10236 return NULL; 10237 } 10238 10239 // Returns a message that the arguments don't match any expectation. 10240 void FormatUnexpectedCallMessageLocked( 10241 const ArgumentTuple& args, 10242 ::std::ostream* os, 10243 ::std::ostream* why) const 10244 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 10245 g_gmock_mutex.AssertHeld(); 10246 *os << "\nUnexpected mock function call - "; 10247 DescribeDefaultActionTo(args, os); 10248 PrintTriedExpectationsLocked(args, why); 10249 } 10250 10251 // Prints a list of expectations that have been tried against the 10252 // current mock function call. 10253 void PrintTriedExpectationsLocked( 10254 const ArgumentTuple& args, 10255 ::std::ostream* why) const 10256 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { 10257 g_gmock_mutex.AssertHeld(); 10258 const int count = static_cast<int>(untyped_expectations_.size()); 10259 *why << "Google Mock tried the following " << count << " " 10260 << (count == 1 ? "expectation, but it didn't match" : 10261 "expectations, but none matched") 10262 << ":\n"; 10263 for (int i = 0; i < count; i++) { 10264 TypedExpectation<F>* const expectation = 10265 static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get()); 10266 *why << "\n"; 10267 expectation->DescribeLocationTo(why); 10268 if (count > 1) { 10269 *why << "tried expectation #" << i << ": "; 10270 } 10271 *why << expectation->source_text() << "...\n"; 10272 expectation->ExplainMatchResultTo(args, why); 10273 expectation->DescribeCallCountTo(why); 10274 } 10275 } 10276 10277 // The current spec (either default action spec or expectation spec) 10278 // being described on this function mocker. 10279 MockSpec<F> current_spec_; 10280 10281 // There is no generally useful and implementable semantics of 10282 // copying a mock object, so copying a mock is usually a user error. 10283 // Thus we disallow copying function mockers. If the user really 10284 // wants to copy a mock object, he should implement his own copy 10285 // operation, for example: 10286 // 10287 // class MockFoo : public Foo { 10288 // public: 10289 // // Defines a copy constructor explicitly. 10290 // MockFoo(const MockFoo& src) {} 10291 // ... 10292 // }; 10293 GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase); 10294 }; // class FunctionMockerBase 10295 10296 #ifdef _MSC_VER 10297 # pragma warning(pop) // Restores the warning state. 10298 #endif // _MSV_VER 10299 10300 // Implements methods of FunctionMockerBase. 10301 10302 // Verifies that all expectations on this mock function have been 10303 // satisfied. Reports one or more Google Test non-fatal failures and 10304 // returns false if not. 10305 10306 // Reports an uninteresting call (whose description is in msg) in the 10307 // manner specified by 'reaction'. 10308 void ReportUninterestingCall(CallReaction reaction, const string& msg); 10309 10310 } // namespace internal 10311 10312 // The style guide prohibits "using" statements in a namespace scope 10313 // inside a header file. However, the MockSpec class template is 10314 // meant to be defined in the ::testing namespace. The following line 10315 // is just a trick for working around a bug in MSVC 8.0, which cannot 10316 // handle it if we define MockSpec in ::testing. 10317 using internal::MockSpec; 10318 10319 // Const(x) is a convenient function for obtaining a const reference 10320 // to x. This is useful for setting expectations on an overloaded 10321 // const mock method, e.g. 10322 // 10323 // class MockFoo : public FooInterface { 10324 // public: 10325 // MOCK_METHOD0(Bar, int()); 10326 // MOCK_CONST_METHOD0(Bar, int&()); 10327 // }; 10328 // 10329 // MockFoo foo; 10330 // // Expects a call to non-const MockFoo::Bar(). 10331 // EXPECT_CALL(foo, Bar()); 10332 // // Expects a call to const MockFoo::Bar(). 10333 // EXPECT_CALL(Const(foo), Bar()); 10334 template <typename T> 10335 inline const T& Const(const T& x) { return x; } 10336 10337 // Constructs an Expectation object that references and co-owns exp. 10338 inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT 10339 : expectation_base_(exp.GetHandle().expectation_base()) {} 10340 10341 } // namespace testing 10342 10343 // A separate macro is required to avoid compile errors when the name 10344 // of the method used in call is a result of macro expansion. 10345 // See CompilesWithMethodNameExpandedFromMacro tests in 10346 // internal/gmock-spec-builders_test.cc for more details. 10347 #define GMOCK_ON_CALL_IMPL_(obj, call) \ 10348 ((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \ 10349 #obj, #call) 10350 #define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call) 10351 10352 #define GMOCK_EXPECT_CALL_IMPL_(obj, call) \ 10353 ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call) 10354 #define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call) 10355 10356 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ 10357 10358 namespace testing { 10359 namespace internal { 10360 10361 template <typename F> 10362 class FunctionMockerBase; 10363 10364 // Note: class FunctionMocker really belongs to the ::testing 10365 // namespace. However if we define it in ::testing, MSVC will 10366 // complain when classes in ::testing::internal declare it as a 10367 // friend class template. To workaround this compiler bug, we define 10368 // FunctionMocker in ::testing::internal and import it into ::testing. 10369 template <typename F> 10370 class FunctionMocker; 10371 10372 template <typename R> 10373 class FunctionMocker<R()> : public 10374 internal::FunctionMockerBase<R()> { 10375 public: 10376 typedef R F(); 10377 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 10378 10379 MockSpec<F>& With() { 10380 return this->current_spec(); 10381 } 10382 10383 R Invoke() { 10384 // Even though gcc and MSVC don't enforce it, 'this->' is required 10385 // by the C++ standard [14.6.4] here, as the base class type is 10386 // dependent on the template argument (and thus shouldn't be 10387 // looked into when resolving InvokeWith). 10388 return this->InvokeWith(ArgumentTuple()); 10389 } 10390 }; 10391 10392 template <typename R, typename A1> 10393 class FunctionMocker<R(A1)> : public 10394 internal::FunctionMockerBase<R(A1)> { 10395 public: 10396 typedef R F(A1); 10397 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 10398 10399 MockSpec<F>& With(const Matcher<A1>& m1) { 10400 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1)); 10401 return this->current_spec(); 10402 } 10403 10404 R Invoke(A1 a1) { 10405 // Even though gcc and MSVC don't enforce it, 'this->' is required 10406 // by the C++ standard [14.6.4] here, as the base class type is 10407 // dependent on the template argument (and thus shouldn't be 10408 // looked into when resolving InvokeWith). 10409 return this->InvokeWith(ArgumentTuple(a1)); 10410 } 10411 }; 10412 10413 template <typename R, typename A1, typename A2> 10414 class FunctionMocker<R(A1, A2)> : public 10415 internal::FunctionMockerBase<R(A1, A2)> { 10416 public: 10417 typedef R F(A1, A2); 10418 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 10419 10420 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2) { 10421 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2)); 10422 return this->current_spec(); 10423 } 10424 10425 R Invoke(A1 a1, A2 a2) { 10426 // Even though gcc and MSVC don't enforce it, 'this->' is required 10427 // by the C++ standard [14.6.4] here, as the base class type is 10428 // dependent on the template argument (and thus shouldn't be 10429 // looked into when resolving InvokeWith). 10430 return this->InvokeWith(ArgumentTuple(a1, a2)); 10431 } 10432 }; 10433 10434 template <typename R, typename A1, typename A2, typename A3> 10435 class FunctionMocker<R(A1, A2, A3)> : public 10436 internal::FunctionMockerBase<R(A1, A2, A3)> { 10437 public: 10438 typedef R F(A1, A2, A3); 10439 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 10440 10441 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, 10442 const Matcher<A3>& m3) { 10443 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3)); 10444 return this->current_spec(); 10445 } 10446 10447 R Invoke(A1 a1, A2 a2, A3 a3) { 10448 // Even though gcc and MSVC don't enforce it, 'this->' is required 10449 // by the C++ standard [14.6.4] here, as the base class type is 10450 // dependent on the template argument (and thus shouldn't be 10451 // looked into when resolving InvokeWith). 10452 return this->InvokeWith(ArgumentTuple(a1, a2, a3)); 10453 } 10454 }; 10455 10456 template <typename R, typename A1, typename A2, typename A3, typename A4> 10457 class FunctionMocker<R(A1, A2, A3, A4)> : public 10458 internal::FunctionMockerBase<R(A1, A2, A3, A4)> { 10459 public: 10460 typedef R F(A1, A2, A3, A4); 10461 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 10462 10463 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, 10464 const Matcher<A3>& m3, const Matcher<A4>& m4) { 10465 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4)); 10466 return this->current_spec(); 10467 } 10468 10469 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) { 10470 // Even though gcc and MSVC don't enforce it, 'this->' is required 10471 // by the C++ standard [14.6.4] here, as the base class type is 10472 // dependent on the template argument (and thus shouldn't be 10473 // looked into when resolving InvokeWith). 10474 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4)); 10475 } 10476 }; 10477 10478 template <typename R, typename A1, typename A2, typename A3, typename A4, 10479 typename A5> 10480 class FunctionMocker<R(A1, A2, A3, A4, A5)> : public 10481 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5)> { 10482 public: 10483 typedef R F(A1, A2, A3, A4, A5); 10484 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 10485 10486 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, 10487 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) { 10488 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, 10489 m5)); 10490 return this->current_spec(); 10491 } 10492 10493 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { 10494 // Even though gcc and MSVC don't enforce it, 'this->' is required 10495 // by the C++ standard [14.6.4] here, as the base class type is 10496 // dependent on the template argument (and thus shouldn't be 10497 // looked into when resolving InvokeWith). 10498 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5)); 10499 } 10500 }; 10501 10502 template <typename R, typename A1, typename A2, typename A3, typename A4, 10503 typename A5, typename A6> 10504 class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public 10505 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6)> { 10506 public: 10507 typedef R F(A1, A2, A3, A4, A5, A6); 10508 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 10509 10510 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, 10511 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, 10512 const Matcher<A6>& m6) { 10513 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, 10514 m6)); 10515 return this->current_spec(); 10516 } 10517 10518 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { 10519 // Even though gcc and MSVC don't enforce it, 'this->' is required 10520 // by the C++ standard [14.6.4] here, as the base class type is 10521 // dependent on the template argument (and thus shouldn't be 10522 // looked into when resolving InvokeWith). 10523 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6)); 10524 } 10525 }; 10526 10527 template <typename R, typename A1, typename A2, typename A3, typename A4, 10528 typename A5, typename A6, typename A7> 10529 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public 10530 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7)> { 10531 public: 10532 typedef R F(A1, A2, A3, A4, A5, A6, A7); 10533 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 10534 10535 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, 10536 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, 10537 const Matcher<A6>& m6, const Matcher<A7>& m7) { 10538 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, 10539 m6, m7)); 10540 return this->current_spec(); 10541 } 10542 10543 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { 10544 // Even though gcc and MSVC don't enforce it, 'this->' is required 10545 // by the C++ standard [14.6.4] here, as the base class type is 10546 // dependent on the template argument (and thus shouldn't be 10547 // looked into when resolving InvokeWith). 10548 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7)); 10549 } 10550 }; 10551 10552 template <typename R, typename A1, typename A2, typename A3, typename A4, 10553 typename A5, typename A6, typename A7, typename A8> 10554 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public 10555 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8)> { 10556 public: 10557 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8); 10558 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 10559 10560 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, 10561 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, 10562 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) { 10563 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, 10564 m6, m7, m8)); 10565 return this->current_spec(); 10566 } 10567 10568 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { 10569 // Even though gcc and MSVC don't enforce it, 'this->' is required 10570 // by the C++ standard [14.6.4] here, as the base class type is 10571 // dependent on the template argument (and thus shouldn't be 10572 // looked into when resolving InvokeWith). 10573 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8)); 10574 } 10575 }; 10576 10577 template <typename R, typename A1, typename A2, typename A3, typename A4, 10578 typename A5, typename A6, typename A7, typename A8, typename A9> 10579 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public 10580 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> { 10581 public: 10582 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9); 10583 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 10584 10585 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, 10586 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, 10587 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8, 10588 const Matcher<A9>& m9) { 10589 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, 10590 m6, m7, m8, m9)); 10591 return this->current_spec(); 10592 } 10593 10594 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { 10595 // Even though gcc and MSVC don't enforce it, 'this->' is required 10596 // by the C++ standard [14.6.4] here, as the base class type is 10597 // dependent on the template argument (and thus shouldn't be 10598 // looked into when resolving InvokeWith). 10599 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9)); 10600 } 10601 }; 10602 10603 template <typename R, typename A1, typename A2, typename A3, typename A4, 10604 typename A5, typename A6, typename A7, typename A8, typename A9, 10605 typename A10> 10606 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public 10607 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> { 10608 public: 10609 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); 10610 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; 10611 10612 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, 10613 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, 10614 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8, 10615 const Matcher<A9>& m9, const Matcher<A10>& m10) { 10616 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, 10617 m6, m7, m8, m9, m10)); 10618 return this->current_spec(); 10619 } 10620 10621 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, 10622 A10 a10) { 10623 // Even though gcc and MSVC don't enforce it, 'this->' is required 10624 // by the C++ standard [14.6.4] here, as the base class type is 10625 // dependent on the template argument (and thus shouldn't be 10626 // looked into when resolving InvokeWith). 10627 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9, 10628 a10)); 10629 } 10630 }; 10631 10632 } // namespace internal 10633 10634 // The style guide prohibits "using" statements in a namespace scope 10635 // inside a header file. However, the FunctionMocker class template 10636 // is meant to be defined in the ::testing namespace. The following 10637 // line is just a trick for working around a bug in MSVC 8.0, which 10638 // cannot handle it if we define FunctionMocker in ::testing. 10639 using internal::FunctionMocker; 10640 10641 // GMOCK_RESULT_(tn, F) expands to the result type of function type F. 10642 // We define this as a variadic macro in case F contains unprotected 10643 // commas (the same reason that we use variadic macros in other places 10644 // in this file). 10645 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10646 #define GMOCK_RESULT_(tn, ...) \ 10647 tn ::testing::internal::Function<__VA_ARGS__>::Result 10648 10649 // The type of argument N of the given function type. 10650 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10651 #define GMOCK_ARG_(tn, N, ...) \ 10652 tn ::testing::internal::Function<__VA_ARGS__>::Argument##N 10653 10654 // The matcher type for argument N of the given function type. 10655 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10656 #define GMOCK_MATCHER_(tn, N, ...) \ 10657 const ::testing::Matcher<GMOCK_ARG_(tn, N, __VA_ARGS__)>& 10658 10659 // The variable for mocking the given method. 10660 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10661 #define GMOCK_MOCKER_(arity, constness, Method) \ 10662 GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) 10663 10664 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10665 #define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \ 10666 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 10667 ) constness { \ 10668 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 10669 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ 10670 == 0), \ 10671 this_method_does_not_take_0_arguments); \ 10672 GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ 10673 return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ 10674 } \ 10675 ::testing::MockSpec<__VA_ARGS__>& \ 10676 gmock_##Method() constness { \ 10677 GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ 10678 return GMOCK_MOCKER_(0, constness, Method).With(); \ 10679 } \ 10680 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \ 10681 Method) 10682 10683 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10684 #define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \ 10685 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 10686 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ 10687 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 10688 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ 10689 == 1), \ 10690 this_method_does_not_take_1_argument); \ 10691 GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ 10692 return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \ 10693 } \ 10694 ::testing::MockSpec<__VA_ARGS__>& \ 10695 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ 10696 GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ 10697 return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ 10698 } \ 10699 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \ 10700 Method) 10701 10702 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10703 #define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \ 10704 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 10705 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ 10706 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ 10707 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 10708 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ 10709 == 2), \ 10710 this_method_does_not_take_2_arguments); \ 10711 GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ 10712 return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \ 10713 } \ 10714 ::testing::MockSpec<__VA_ARGS__>& \ 10715 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ 10716 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ 10717 GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ 10718 return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \ 10719 } \ 10720 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \ 10721 Method) 10722 10723 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10724 #define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \ 10725 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 10726 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ 10727 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ 10728 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ 10729 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 10730 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ 10731 == 3), \ 10732 this_method_does_not_take_3_arguments); \ 10733 GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ 10734 return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \ 10735 gmock_a3); \ 10736 } \ 10737 ::testing::MockSpec<__VA_ARGS__>& \ 10738 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ 10739 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ 10740 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ 10741 GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \ 10742 return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \ 10743 gmock_a3); \ 10744 } \ 10745 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \ 10746 Method) 10747 10748 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10749 #define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \ 10750 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 10751 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ 10752 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ 10753 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ 10754 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ 10755 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 10756 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ 10757 == 4), \ 10758 this_method_does_not_take_4_arguments); \ 10759 GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ 10760 return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \ 10761 gmock_a3, gmock_a4); \ 10762 } \ 10763 ::testing::MockSpec<__VA_ARGS__>& \ 10764 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ 10765 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ 10766 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ 10767 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ 10768 GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \ 10769 return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \ 10770 gmock_a3, gmock_a4); \ 10771 } \ 10772 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \ 10773 Method) 10774 10775 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10776 #define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \ 10777 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 10778 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ 10779 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ 10780 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ 10781 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ 10782 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ 10783 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 10784 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ 10785 == 5), \ 10786 this_method_does_not_take_5_arguments); \ 10787 GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ 10788 return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \ 10789 gmock_a3, gmock_a4, gmock_a5); \ 10790 } \ 10791 ::testing::MockSpec<__VA_ARGS__>& \ 10792 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ 10793 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ 10794 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ 10795 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ 10796 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ 10797 GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \ 10798 return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \ 10799 gmock_a3, gmock_a4, gmock_a5); \ 10800 } \ 10801 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \ 10802 Method) 10803 10804 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10805 #define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \ 10806 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 10807 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ 10808 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ 10809 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ 10810 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ 10811 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ 10812 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ 10813 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 10814 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ 10815 == 6), \ 10816 this_method_does_not_take_6_arguments); \ 10817 GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ 10818 return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \ 10819 gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ 10820 } \ 10821 ::testing::MockSpec<__VA_ARGS__>& \ 10822 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ 10823 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ 10824 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ 10825 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ 10826 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ 10827 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ 10828 GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \ 10829 return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \ 10830 gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ 10831 } \ 10832 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \ 10833 Method) 10834 10835 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10836 #define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \ 10837 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 10838 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ 10839 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ 10840 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ 10841 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ 10842 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ 10843 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ 10844 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ 10845 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 10846 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ 10847 == 7), \ 10848 this_method_does_not_take_7_arguments); \ 10849 GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ 10850 return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \ 10851 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ 10852 } \ 10853 ::testing::MockSpec<__VA_ARGS__>& \ 10854 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ 10855 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ 10856 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ 10857 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ 10858 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ 10859 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ 10860 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ 10861 GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \ 10862 return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \ 10863 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ 10864 } \ 10865 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \ 10866 Method) 10867 10868 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10869 #define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \ 10870 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 10871 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ 10872 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ 10873 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ 10874 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ 10875 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ 10876 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ 10877 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ 10878 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ 10879 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 10880 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ 10881 == 8), \ 10882 this_method_does_not_take_8_arguments); \ 10883 GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ 10884 return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \ 10885 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ 10886 } \ 10887 ::testing::MockSpec<__VA_ARGS__>& \ 10888 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ 10889 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ 10890 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ 10891 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ 10892 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ 10893 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ 10894 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ 10895 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ 10896 GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \ 10897 return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \ 10898 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ 10899 } \ 10900 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \ 10901 Method) 10902 10903 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10904 #define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \ 10905 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 10906 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ 10907 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ 10908 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ 10909 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ 10910 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ 10911 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ 10912 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ 10913 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ 10914 GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ 10915 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 10916 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ 10917 == 9), \ 10918 this_method_does_not_take_9_arguments); \ 10919 GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ 10920 return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \ 10921 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ 10922 gmock_a9); \ 10923 } \ 10924 ::testing::MockSpec<__VA_ARGS__>& \ 10925 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ 10926 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ 10927 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ 10928 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ 10929 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ 10930 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ 10931 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ 10932 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ 10933 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ 10934 GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \ 10935 return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \ 10936 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ 10937 gmock_a9); \ 10938 } \ 10939 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \ 10940 Method) 10941 10942 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 10943 #define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \ 10944 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 10945 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ 10946 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ 10947 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ 10948 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ 10949 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ 10950 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ 10951 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ 10952 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ 10953 GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \ 10954 GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \ 10955 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 10956 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ 10957 == 10), \ 10958 this_method_does_not_take_10_arguments); \ 10959 GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ 10960 return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \ 10961 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ 10962 gmock_a10); \ 10963 } \ 10964 ::testing::MockSpec<__VA_ARGS__>& \ 10965 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ 10966 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ 10967 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ 10968 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ 10969 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ 10970 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ 10971 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ 10972 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ 10973 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \ 10974 GMOCK_MATCHER_(tn, 10, \ 10975 __VA_ARGS__) gmock_a10) constness { \ 10976 GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \ 10977 return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \ 10978 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ 10979 gmock_a10); \ 10980 } \ 10981 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \ 10982 Method) 10983 10984 #define MOCK_METHOD0(m, ...) GMOCK_METHOD0_(, , , m, __VA_ARGS__) 10985 #define MOCK_METHOD1(m, ...) GMOCK_METHOD1_(, , , m, __VA_ARGS__) 10986 #define MOCK_METHOD2(m, ...) GMOCK_METHOD2_(, , , m, __VA_ARGS__) 10987 #define MOCK_METHOD3(m, ...) GMOCK_METHOD3_(, , , m, __VA_ARGS__) 10988 #define MOCK_METHOD4(m, ...) GMOCK_METHOD4_(, , , m, __VA_ARGS__) 10989 #define MOCK_METHOD5(m, ...) GMOCK_METHOD5_(, , , m, __VA_ARGS__) 10990 #define MOCK_METHOD6(m, ...) GMOCK_METHOD6_(, , , m, __VA_ARGS__) 10991 #define MOCK_METHOD7(m, ...) GMOCK_METHOD7_(, , , m, __VA_ARGS__) 10992 #define MOCK_METHOD8(m, ...) GMOCK_METHOD8_(, , , m, __VA_ARGS__) 10993 #define MOCK_METHOD9(m, ...) GMOCK_METHOD9_(, , , m, __VA_ARGS__) 10994 #define MOCK_METHOD10(m, ...) GMOCK_METHOD10_(, , , m, __VA_ARGS__) 10995 10996 #define MOCK_CONST_METHOD0(m, ...) GMOCK_METHOD0_(, const, , m, __VA_ARGS__) 10997 #define MOCK_CONST_METHOD1(m, ...) GMOCK_METHOD1_(, const, , m, __VA_ARGS__) 10998 #define MOCK_CONST_METHOD2(m, ...) GMOCK_METHOD2_(, const, , m, __VA_ARGS__) 10999 #define MOCK_CONST_METHOD3(m, ...) GMOCK_METHOD3_(, const, , m, __VA_ARGS__) 11000 #define MOCK_CONST_METHOD4(m, ...) GMOCK_METHOD4_(, const, , m, __VA_ARGS__) 11001 #define MOCK_CONST_METHOD5(m, ...) GMOCK_METHOD5_(, const, , m, __VA_ARGS__) 11002 #define MOCK_CONST_METHOD6(m, ...) GMOCK_METHOD6_(, const, , m, __VA_ARGS__) 11003 #define MOCK_CONST_METHOD7(m, ...) GMOCK_METHOD7_(, const, , m, __VA_ARGS__) 11004 #define MOCK_CONST_METHOD8(m, ...) GMOCK_METHOD8_(, const, , m, __VA_ARGS__) 11005 #define MOCK_CONST_METHOD9(m, ...) GMOCK_METHOD9_(, const, , m, __VA_ARGS__) 11006 #define MOCK_CONST_METHOD10(m, ...) GMOCK_METHOD10_(, const, , m, __VA_ARGS__) 11007 11008 #define MOCK_METHOD0_T(m, ...) GMOCK_METHOD0_(typename, , , m, __VA_ARGS__) 11009 #define MOCK_METHOD1_T(m, ...) GMOCK_METHOD1_(typename, , , m, __VA_ARGS__) 11010 #define MOCK_METHOD2_T(m, ...) GMOCK_METHOD2_(typename, , , m, __VA_ARGS__) 11011 #define MOCK_METHOD3_T(m, ...) GMOCK_METHOD3_(typename, , , m, __VA_ARGS__) 11012 #define MOCK_METHOD4_T(m, ...) GMOCK_METHOD4_(typename, , , m, __VA_ARGS__) 11013 #define MOCK_METHOD5_T(m, ...) GMOCK_METHOD5_(typename, , , m, __VA_ARGS__) 11014 #define MOCK_METHOD6_T(m, ...) GMOCK_METHOD6_(typename, , , m, __VA_ARGS__) 11015 #define MOCK_METHOD7_T(m, ...) GMOCK_METHOD7_(typename, , , m, __VA_ARGS__) 11016 #define MOCK_METHOD8_T(m, ...) GMOCK_METHOD8_(typename, , , m, __VA_ARGS__) 11017 #define MOCK_METHOD9_T(m, ...) GMOCK_METHOD9_(typename, , , m, __VA_ARGS__) 11018 #define MOCK_METHOD10_T(m, ...) GMOCK_METHOD10_(typename, , , m, __VA_ARGS__) 11019 11020 #define MOCK_CONST_METHOD0_T(m, ...) \ 11021 GMOCK_METHOD0_(typename, const, , m, __VA_ARGS__) 11022 #define MOCK_CONST_METHOD1_T(m, ...) \ 11023 GMOCK_METHOD1_(typename, const, , m, __VA_ARGS__) 11024 #define MOCK_CONST_METHOD2_T(m, ...) \ 11025 GMOCK_METHOD2_(typename, const, , m, __VA_ARGS__) 11026 #define MOCK_CONST_METHOD3_T(m, ...) \ 11027 GMOCK_METHOD3_(typename, const, , m, __VA_ARGS__) 11028 #define MOCK_CONST_METHOD4_T(m, ...) \ 11029 GMOCK_METHOD4_(typename, const, , m, __VA_ARGS__) 11030 #define MOCK_CONST_METHOD5_T(m, ...) \ 11031 GMOCK_METHOD5_(typename, const, , m, __VA_ARGS__) 11032 #define MOCK_CONST_METHOD6_T(m, ...) \ 11033 GMOCK_METHOD6_(typename, const, , m, __VA_ARGS__) 11034 #define MOCK_CONST_METHOD7_T(m, ...) \ 11035 GMOCK_METHOD7_(typename, const, , m, __VA_ARGS__) 11036 #define MOCK_CONST_METHOD8_T(m, ...) \ 11037 GMOCK_METHOD8_(typename, const, , m, __VA_ARGS__) 11038 #define MOCK_CONST_METHOD9_T(m, ...) \ 11039 GMOCK_METHOD9_(typename, const, , m, __VA_ARGS__) 11040 #define MOCK_CONST_METHOD10_T(m, ...) \ 11041 GMOCK_METHOD10_(typename, const, , m, __VA_ARGS__) 11042 11043 #define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \ 11044 GMOCK_METHOD0_(, , ct, m, __VA_ARGS__) 11045 #define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \ 11046 GMOCK_METHOD1_(, , ct, m, __VA_ARGS__) 11047 #define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \ 11048 GMOCK_METHOD2_(, , ct, m, __VA_ARGS__) 11049 #define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \ 11050 GMOCK_METHOD3_(, , ct, m, __VA_ARGS__) 11051 #define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \ 11052 GMOCK_METHOD4_(, , ct, m, __VA_ARGS__) 11053 #define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \ 11054 GMOCK_METHOD5_(, , ct, m, __VA_ARGS__) 11055 #define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \ 11056 GMOCK_METHOD6_(, , ct, m, __VA_ARGS__) 11057 #define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \ 11058 GMOCK_METHOD7_(, , ct, m, __VA_ARGS__) 11059 #define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \ 11060 GMOCK_METHOD8_(, , ct, m, __VA_ARGS__) 11061 #define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \ 11062 GMOCK_METHOD9_(, , ct, m, __VA_ARGS__) 11063 #define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \ 11064 GMOCK_METHOD10_(, , ct, m, __VA_ARGS__) 11065 11066 #define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \ 11067 GMOCK_METHOD0_(, const, ct, m, __VA_ARGS__) 11068 #define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \ 11069 GMOCK_METHOD1_(, const, ct, m, __VA_ARGS__) 11070 #define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \ 11071 GMOCK_METHOD2_(, const, ct, m, __VA_ARGS__) 11072 #define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \ 11073 GMOCK_METHOD3_(, const, ct, m, __VA_ARGS__) 11074 #define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \ 11075 GMOCK_METHOD4_(, const, ct, m, __VA_ARGS__) 11076 #define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \ 11077 GMOCK_METHOD5_(, const, ct, m, __VA_ARGS__) 11078 #define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \ 11079 GMOCK_METHOD6_(, const, ct, m, __VA_ARGS__) 11080 #define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \ 11081 GMOCK_METHOD7_(, const, ct, m, __VA_ARGS__) 11082 #define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \ 11083 GMOCK_METHOD8_(, const, ct, m, __VA_ARGS__) 11084 #define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \ 11085 GMOCK_METHOD9_(, const, ct, m, __VA_ARGS__) 11086 #define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \ 11087 GMOCK_METHOD10_(, const, ct, m, __VA_ARGS__) 11088 11089 #define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \ 11090 GMOCK_METHOD0_(typename, , ct, m, __VA_ARGS__) 11091 #define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \ 11092 GMOCK_METHOD1_(typename, , ct, m, __VA_ARGS__) 11093 #define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \ 11094 GMOCK_METHOD2_(typename, , ct, m, __VA_ARGS__) 11095 #define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \ 11096 GMOCK_METHOD3_(typename, , ct, m, __VA_ARGS__) 11097 #define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \ 11098 GMOCK_METHOD4_(typename, , ct, m, __VA_ARGS__) 11099 #define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \ 11100 GMOCK_METHOD5_(typename, , ct, m, __VA_ARGS__) 11101 #define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \ 11102 GMOCK_METHOD6_(typename, , ct, m, __VA_ARGS__) 11103 #define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \ 11104 GMOCK_METHOD7_(typename, , ct, m, __VA_ARGS__) 11105 #define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \ 11106 GMOCK_METHOD8_(typename, , ct, m, __VA_ARGS__) 11107 #define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \ 11108 GMOCK_METHOD9_(typename, , ct, m, __VA_ARGS__) 11109 #define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \ 11110 GMOCK_METHOD10_(typename, , ct, m, __VA_ARGS__) 11111 11112 #define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \ 11113 GMOCK_METHOD0_(typename, const, ct, m, __VA_ARGS__) 11114 #define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \ 11115 GMOCK_METHOD1_(typename, const, ct, m, __VA_ARGS__) 11116 #define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \ 11117 GMOCK_METHOD2_(typename, const, ct, m, __VA_ARGS__) 11118 #define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \ 11119 GMOCK_METHOD3_(typename, const, ct, m, __VA_ARGS__) 11120 #define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \ 11121 GMOCK_METHOD4_(typename, const, ct, m, __VA_ARGS__) 11122 #define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \ 11123 GMOCK_METHOD5_(typename, const, ct, m, __VA_ARGS__) 11124 #define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \ 11125 GMOCK_METHOD6_(typename, const, ct, m, __VA_ARGS__) 11126 #define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \ 11127 GMOCK_METHOD7_(typename, const, ct, m, __VA_ARGS__) 11128 #define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \ 11129 GMOCK_METHOD8_(typename, const, ct, m, __VA_ARGS__) 11130 #define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \ 11131 GMOCK_METHOD9_(typename, const, ct, m, __VA_ARGS__) 11132 #define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \ 11133 GMOCK_METHOD10_(typename, const, ct, m, __VA_ARGS__) 11134 11135 // A MockFunction<F> class has one mock method whose type is F. It is 11136 // useful when you just want your test code to emit some messages and 11137 // have Google Mock verify the right messages are sent (and perhaps at 11138 // the right times). For example, if you are exercising code: 11139 // 11140 // Foo(1); 11141 // Foo(2); 11142 // Foo(3); 11143 // 11144 // and want to verify that Foo(1) and Foo(3) both invoke 11145 // mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: 11146 // 11147 // TEST(FooTest, InvokesBarCorrectly) { 11148 // MyMock mock; 11149 // MockFunction<void(string check_point_name)> check; 11150 // { 11151 // InSequence s; 11152 // 11153 // EXPECT_CALL(mock, Bar("a")); 11154 // EXPECT_CALL(check, Call("1")); 11155 // EXPECT_CALL(check, Call("2")); 11156 // EXPECT_CALL(mock, Bar("a")); 11157 // } 11158 // Foo(1); 11159 // check.Call("1"); 11160 // Foo(2); 11161 // check.Call("2"); 11162 // Foo(3); 11163 // } 11164 // 11165 // The expectation spec says that the first Bar("a") must happen 11166 // before check point "1", the second Bar("a") must happen after check 11167 // point "2", and nothing should happen between the two check 11168 // points. The explicit check points make it easy to tell which 11169 // Bar("a") is called by which call to Foo(). 11170 template <typename F> 11171 class MockFunction; 11172 11173 template <typename R> 11174 class MockFunction<R()> { 11175 public: 11176 MockFunction() {} 11177 11178 MOCK_METHOD0_T(Call, R()); 11179 11180 private: 11181 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 11182 }; 11183 11184 template <typename R, typename A0> 11185 class MockFunction<R(A0)> { 11186 public: 11187 MockFunction() {} 11188 11189 MOCK_METHOD1_T(Call, R(A0)); 11190 11191 private: 11192 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 11193 }; 11194 11195 template <typename R, typename A0, typename A1> 11196 class MockFunction<R(A0, A1)> { 11197 public: 11198 MockFunction() {} 11199 11200 MOCK_METHOD2_T(Call, R(A0, A1)); 11201 11202 private: 11203 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 11204 }; 11205 11206 template <typename R, typename A0, typename A1, typename A2> 11207 class MockFunction<R(A0, A1, A2)> { 11208 public: 11209 MockFunction() {} 11210 11211 MOCK_METHOD3_T(Call, R(A0, A1, A2)); 11212 11213 private: 11214 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 11215 }; 11216 11217 template <typename R, typename A0, typename A1, typename A2, typename A3> 11218 class MockFunction<R(A0, A1, A2, A3)> { 11219 public: 11220 MockFunction() {} 11221 11222 MOCK_METHOD4_T(Call, R(A0, A1, A2, A3)); 11223 11224 private: 11225 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 11226 }; 11227 11228 template <typename R, typename A0, typename A1, typename A2, typename A3, 11229 typename A4> 11230 class MockFunction<R(A0, A1, A2, A3, A4)> { 11231 public: 11232 MockFunction() {} 11233 11234 MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4)); 11235 11236 private: 11237 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 11238 }; 11239 11240 template <typename R, typename A0, typename A1, typename A2, typename A3, 11241 typename A4, typename A5> 11242 class MockFunction<R(A0, A1, A2, A3, A4, A5)> { 11243 public: 11244 MockFunction() {} 11245 11246 MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5)); 11247 11248 private: 11249 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 11250 }; 11251 11252 template <typename R, typename A0, typename A1, typename A2, typename A3, 11253 typename A4, typename A5, typename A6> 11254 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> { 11255 public: 11256 MockFunction() {} 11257 11258 MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6)); 11259 11260 private: 11261 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 11262 }; 11263 11264 template <typename R, typename A0, typename A1, typename A2, typename A3, 11265 typename A4, typename A5, typename A6, typename A7> 11266 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> { 11267 public: 11268 MockFunction() {} 11269 11270 MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7)); 11271 11272 private: 11273 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 11274 }; 11275 11276 template <typename R, typename A0, typename A1, typename A2, typename A3, 11277 typename A4, typename A5, typename A6, typename A7, typename A8> 11278 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> { 11279 public: 11280 MockFunction() {} 11281 11282 MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8)); 11283 11284 private: 11285 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 11286 }; 11287 11288 template <typename R, typename A0, typename A1, typename A2, typename A3, 11289 typename A4, typename A5, typename A6, typename A7, typename A8, 11290 typename A9> 11291 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> { 11292 public: 11293 MockFunction() {} 11294 11295 MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)); 11296 11297 private: 11298 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 11299 }; 11300 11301 } // namespace testing 11302 11303 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ 11304 // This file was GENERATED by command: 11305 // pump.py gmock-generated-nice-strict.h.pump 11306 // DO NOT EDIT BY HAND!!! 11307 11308 // Copyright 2008, Google Inc. 11309 // All rights reserved. 11310 // 11311 // Redistribution and use in source and binary forms, with or without 11312 // modification, are permitted provided that the following conditions are 11313 // met: 11314 // 11315 // * Redistributions of source code must retain the above copyright 11316 // notice, this list of conditions and the following disclaimer. 11317 // * Redistributions in binary form must reproduce the above 11318 // copyright notice, this list of conditions and the following disclaimer 11319 // in the documentation and/or other materials provided with the 11320 // distribution. 11321 // * Neither the name of Google Inc. nor the names of its 11322 // contributors may be used to endorse or promote products derived from 11323 // this software without specific prior written permission. 11324 // 11325 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 11326 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11327 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 11328 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 11329 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11330 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11331 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 11332 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 11333 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 11334 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 11335 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11336 // 11337 // Author: wan@google.com (Zhanyong Wan) 11338 11339 // Implements class templates NiceMock, NaggyMock, and StrictMock. 11340 // 11341 // Given a mock class MockFoo that is created using Google Mock, 11342 // NiceMock<MockFoo> is a subclass of MockFoo that allows 11343 // uninteresting calls (i.e. calls to mock methods that have no 11344 // EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo 11345 // that prints a warning when an uninteresting call occurs, and 11346 // StrictMock<MockFoo> is a subclass of MockFoo that treats all 11347 // uninteresting calls as errors. 11348 // 11349 // Currently a mock is naggy by default, so MockFoo and 11350 // NaggyMock<MockFoo> behave like the same. However, we will soon 11351 // switch the default behavior of mocks to be nice, as that in general 11352 // leads to more maintainable tests. When that happens, MockFoo will 11353 // stop behaving like NaggyMock<MockFoo> and start behaving like 11354 // NiceMock<MockFoo>. 11355 // 11356 // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of 11357 // their respective base class, with up-to 10 arguments. Therefore 11358 // you can write NiceMock<MockFoo>(5, "a") to construct a nice mock 11359 // where MockFoo has a constructor that accepts (int, const char*), 11360 // for example. 11361 // 11362 // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>, 11363 // and StrictMock<MockFoo> only works for mock methods defined using 11364 // the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. 11365 // If a mock method is defined in a base class of MockFoo, the "nice" 11366 // or "strict" modifier may not affect it, depending on the compiler. 11367 // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT 11368 // supported. 11369 // 11370 // Another known limitation is that the constructors of the base mock 11371 // cannot have arguments passed by non-const reference, which are 11372 // banned by the Google C++ style guide anyway. 11373 11374 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ 11375 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ 11376 11377 11378 namespace testing { 11379 11380 template <class MockClass> 11381 class NiceMock : public MockClass { 11382 public: 11383 // We don't factor out the constructor body to a common method, as 11384 // we have to avoid a possible clash with members of MockClass. 11385 NiceMock() { 11386 ::testing::Mock::AllowUninterestingCalls( 11387 internal::ImplicitCast_<MockClass*>(this)); 11388 } 11389 11390 // C++ doesn't (yet) allow inheritance of constructors, so we have 11391 // to define it for each arity. 11392 template <typename A1> 11393 explicit NiceMock(const A1& a1) : MockClass(a1) { 11394 ::testing::Mock::AllowUninterestingCalls( 11395 internal::ImplicitCast_<MockClass*>(this)); 11396 } 11397 template <typename A1, typename A2> 11398 NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { 11399 ::testing::Mock::AllowUninterestingCalls( 11400 internal::ImplicitCast_<MockClass*>(this)); 11401 } 11402 11403 template <typename A1, typename A2, typename A3> 11404 NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { 11405 ::testing::Mock::AllowUninterestingCalls( 11406 internal::ImplicitCast_<MockClass*>(this)); 11407 } 11408 11409 template <typename A1, typename A2, typename A3, typename A4> 11410 NiceMock(const A1& a1, const A2& a2, const A3& a3, 11411 const A4& a4) : MockClass(a1, a2, a3, a4) { 11412 ::testing::Mock::AllowUninterestingCalls( 11413 internal::ImplicitCast_<MockClass*>(this)); 11414 } 11415 11416 template <typename A1, typename A2, typename A3, typename A4, typename A5> 11417 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11418 const A5& a5) : MockClass(a1, a2, a3, a4, a5) { 11419 ::testing::Mock::AllowUninterestingCalls( 11420 internal::ImplicitCast_<MockClass*>(this)); 11421 } 11422 11423 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11424 typename A6> 11425 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11426 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { 11427 ::testing::Mock::AllowUninterestingCalls( 11428 internal::ImplicitCast_<MockClass*>(this)); 11429 } 11430 11431 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11432 typename A6, typename A7> 11433 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11434 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, 11435 a6, a7) { 11436 ::testing::Mock::AllowUninterestingCalls( 11437 internal::ImplicitCast_<MockClass*>(this)); 11438 } 11439 11440 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11441 typename A6, typename A7, typename A8> 11442 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11443 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, 11444 a2, a3, a4, a5, a6, a7, a8) { 11445 ::testing::Mock::AllowUninterestingCalls( 11446 internal::ImplicitCast_<MockClass*>(this)); 11447 } 11448 11449 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11450 typename A6, typename A7, typename A8, typename A9> 11451 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11452 const A5& a5, const A6& a6, const A7& a7, const A8& a8, 11453 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { 11454 ::testing::Mock::AllowUninterestingCalls( 11455 internal::ImplicitCast_<MockClass*>(this)); 11456 } 11457 11458 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11459 typename A6, typename A7, typename A8, typename A9, typename A10> 11460 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11461 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, 11462 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { 11463 ::testing::Mock::AllowUninterestingCalls( 11464 internal::ImplicitCast_<MockClass*>(this)); 11465 } 11466 11467 virtual ~NiceMock() { 11468 ::testing::Mock::UnregisterCallReaction( 11469 internal::ImplicitCast_<MockClass*>(this)); 11470 } 11471 11472 private: 11473 GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); 11474 }; 11475 11476 template <class MockClass> 11477 class NaggyMock : public MockClass { 11478 public: 11479 // We don't factor out the constructor body to a common method, as 11480 // we have to avoid a possible clash with members of MockClass. 11481 NaggyMock() { 11482 ::testing::Mock::WarnUninterestingCalls( 11483 internal::ImplicitCast_<MockClass*>(this)); 11484 } 11485 11486 // C++ doesn't (yet) allow inheritance of constructors, so we have 11487 // to define it for each arity. 11488 template <typename A1> 11489 explicit NaggyMock(const A1& a1) : MockClass(a1) { 11490 ::testing::Mock::WarnUninterestingCalls( 11491 internal::ImplicitCast_<MockClass*>(this)); 11492 } 11493 template <typename A1, typename A2> 11494 NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { 11495 ::testing::Mock::WarnUninterestingCalls( 11496 internal::ImplicitCast_<MockClass*>(this)); 11497 } 11498 11499 template <typename A1, typename A2, typename A3> 11500 NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { 11501 ::testing::Mock::WarnUninterestingCalls( 11502 internal::ImplicitCast_<MockClass*>(this)); 11503 } 11504 11505 template <typename A1, typename A2, typename A3, typename A4> 11506 NaggyMock(const A1& a1, const A2& a2, const A3& a3, 11507 const A4& a4) : MockClass(a1, a2, a3, a4) { 11508 ::testing::Mock::WarnUninterestingCalls( 11509 internal::ImplicitCast_<MockClass*>(this)); 11510 } 11511 11512 template <typename A1, typename A2, typename A3, typename A4, typename A5> 11513 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11514 const A5& a5) : MockClass(a1, a2, a3, a4, a5) { 11515 ::testing::Mock::WarnUninterestingCalls( 11516 internal::ImplicitCast_<MockClass*>(this)); 11517 } 11518 11519 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11520 typename A6> 11521 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11522 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { 11523 ::testing::Mock::WarnUninterestingCalls( 11524 internal::ImplicitCast_<MockClass*>(this)); 11525 } 11526 11527 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11528 typename A6, typename A7> 11529 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11530 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, 11531 a6, a7) { 11532 ::testing::Mock::WarnUninterestingCalls( 11533 internal::ImplicitCast_<MockClass*>(this)); 11534 } 11535 11536 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11537 typename A6, typename A7, typename A8> 11538 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11539 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, 11540 a2, a3, a4, a5, a6, a7, a8) { 11541 ::testing::Mock::WarnUninterestingCalls( 11542 internal::ImplicitCast_<MockClass*>(this)); 11543 } 11544 11545 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11546 typename A6, typename A7, typename A8, typename A9> 11547 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11548 const A5& a5, const A6& a6, const A7& a7, const A8& a8, 11549 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { 11550 ::testing::Mock::WarnUninterestingCalls( 11551 internal::ImplicitCast_<MockClass*>(this)); 11552 } 11553 11554 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11555 typename A6, typename A7, typename A8, typename A9, typename A10> 11556 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11557 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, 11558 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { 11559 ::testing::Mock::WarnUninterestingCalls( 11560 internal::ImplicitCast_<MockClass*>(this)); 11561 } 11562 11563 virtual ~NaggyMock() { 11564 ::testing::Mock::UnregisterCallReaction( 11565 internal::ImplicitCast_<MockClass*>(this)); 11566 } 11567 11568 private: 11569 GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock); 11570 }; 11571 11572 template <class MockClass> 11573 class StrictMock : public MockClass { 11574 public: 11575 // We don't factor out the constructor body to a common method, as 11576 // we have to avoid a possible clash with members of MockClass. 11577 StrictMock() { 11578 ::testing::Mock::FailUninterestingCalls( 11579 internal::ImplicitCast_<MockClass*>(this)); 11580 } 11581 11582 // C++ doesn't (yet) allow inheritance of constructors, so we have 11583 // to define it for each arity. 11584 template <typename A1> 11585 explicit StrictMock(const A1& a1) : MockClass(a1) { 11586 ::testing::Mock::FailUninterestingCalls( 11587 internal::ImplicitCast_<MockClass*>(this)); 11588 } 11589 template <typename A1, typename A2> 11590 StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { 11591 ::testing::Mock::FailUninterestingCalls( 11592 internal::ImplicitCast_<MockClass*>(this)); 11593 } 11594 11595 template <typename A1, typename A2, typename A3> 11596 StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { 11597 ::testing::Mock::FailUninterestingCalls( 11598 internal::ImplicitCast_<MockClass*>(this)); 11599 } 11600 11601 template <typename A1, typename A2, typename A3, typename A4> 11602 StrictMock(const A1& a1, const A2& a2, const A3& a3, 11603 const A4& a4) : MockClass(a1, a2, a3, a4) { 11604 ::testing::Mock::FailUninterestingCalls( 11605 internal::ImplicitCast_<MockClass*>(this)); 11606 } 11607 11608 template <typename A1, typename A2, typename A3, typename A4, typename A5> 11609 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11610 const A5& a5) : MockClass(a1, a2, a3, a4, a5) { 11611 ::testing::Mock::FailUninterestingCalls( 11612 internal::ImplicitCast_<MockClass*>(this)); 11613 } 11614 11615 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11616 typename A6> 11617 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11618 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { 11619 ::testing::Mock::FailUninterestingCalls( 11620 internal::ImplicitCast_<MockClass*>(this)); 11621 } 11622 11623 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11624 typename A6, typename A7> 11625 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11626 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, 11627 a6, a7) { 11628 ::testing::Mock::FailUninterestingCalls( 11629 internal::ImplicitCast_<MockClass*>(this)); 11630 } 11631 11632 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11633 typename A6, typename A7, typename A8> 11634 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11635 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, 11636 a2, a3, a4, a5, a6, a7, a8) { 11637 ::testing::Mock::FailUninterestingCalls( 11638 internal::ImplicitCast_<MockClass*>(this)); 11639 } 11640 11641 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11642 typename A6, typename A7, typename A8, typename A9> 11643 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11644 const A5& a5, const A6& a6, const A7& a7, const A8& a8, 11645 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { 11646 ::testing::Mock::FailUninterestingCalls( 11647 internal::ImplicitCast_<MockClass*>(this)); 11648 } 11649 11650 template <typename A1, typename A2, typename A3, typename A4, typename A5, 11651 typename A6, typename A7, typename A8, typename A9, typename A10> 11652 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, 11653 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, 11654 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { 11655 ::testing::Mock::FailUninterestingCalls( 11656 internal::ImplicitCast_<MockClass*>(this)); 11657 } 11658 11659 virtual ~StrictMock() { 11660 ::testing::Mock::UnregisterCallReaction( 11661 internal::ImplicitCast_<MockClass*>(this)); 11662 } 11663 11664 private: 11665 GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); 11666 }; 11667 11668 // The following specializations catch some (relatively more common) 11669 // user errors of nesting nice and strict mocks. They do NOT catch 11670 // all possible errors. 11671 11672 // These specializations are declared but not defined, as NiceMock, 11673 // NaggyMock, and StrictMock cannot be nested. 11674 11675 template <typename MockClass> 11676 class NiceMock<NiceMock<MockClass> >; 11677 template <typename MockClass> 11678 class NiceMock<NaggyMock<MockClass> >; 11679 template <typename MockClass> 11680 class NiceMock<StrictMock<MockClass> >; 11681 11682 template <typename MockClass> 11683 class NaggyMock<NiceMock<MockClass> >; 11684 template <typename MockClass> 11685 class NaggyMock<NaggyMock<MockClass> >; 11686 template <typename MockClass> 11687 class NaggyMock<StrictMock<MockClass> >; 11688 11689 template <typename MockClass> 11690 class StrictMock<NiceMock<MockClass> >; 11691 template <typename MockClass> 11692 class StrictMock<NaggyMock<MockClass> >; 11693 template <typename MockClass> 11694 class StrictMock<StrictMock<MockClass> >; 11695 11696 } // namespace testing 11697 11698 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ 11699 // This file was GENERATED by command: 11700 // pump.py gmock-generated-matchers.h.pump 11701 // DO NOT EDIT BY HAND!!! 11702 11703 // Copyright 2008, Google Inc. 11704 // All rights reserved. 11705 // 11706 // Redistribution and use in source and binary forms, with or without 11707 // modification, are permitted provided that the following conditions are 11708 // met: 11709 // 11710 // * Redistributions of source code must retain the above copyright 11711 // notice, this list of conditions and the following disclaimer. 11712 // * Redistributions in binary form must reproduce the above 11713 // copyright notice, this list of conditions and the following disclaimer 11714 // in the documentation and/or other materials provided with the 11715 // distribution. 11716 // * Neither the name of Google Inc. nor the names of its 11717 // contributors may be used to endorse or promote products derived from 11718 // this software without specific prior written permission. 11719 // 11720 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 11721 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11722 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 11723 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 11724 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11725 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11726 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 11727 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 11728 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 11729 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 11730 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11731 11732 // Google Mock - a framework for writing C++ mock classes. 11733 // 11734 // This file implements some commonly used variadic matchers. 11735 11736 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ 11737 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ 11738 11739 #include <iterator> 11740 #include <sstream> 11741 #include <string> 11742 #include <vector> 11743 11744 namespace testing { 11745 namespace internal { 11746 11747 // The type of the i-th (0-based) field of Tuple. 11748 #define GMOCK_FIELD_TYPE_(Tuple, i) \ 11749 typename ::std::tr1::tuple_element<i, Tuple>::type 11750 11751 // TupleFields<Tuple, k0, ..., kn> is for selecting fields from a 11752 // tuple of type Tuple. It has two members: 11753 // 11754 // type: a tuple type whose i-th field is the ki-th field of Tuple. 11755 // GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple. 11756 // 11757 // For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have: 11758 // 11759 // type is tuple<int, bool>, and 11760 // GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true). 11761 11762 template <class Tuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1, 11763 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1, 11764 int k9 = -1> 11765 class TupleFields; 11766 11767 // This generic version is used when there are 10 selectors. 11768 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6, 11769 int k7, int k8, int k9> 11770 class TupleFields { 11771 public: 11772 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), 11773 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), 11774 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4), 11775 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6), 11776 GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8), 11777 GMOCK_FIELD_TYPE_(Tuple, k9)> type; 11778 static type GetSelectedFields(const Tuple& t) { 11779 using ::std::tr1::get; 11780 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t), 11781 get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t), get<k9>(t)); 11782 } 11783 }; 11784 11785 // The following specialization is used for 0 ~ 9 selectors. 11786 11787 template <class Tuple> 11788 class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { 11789 public: 11790 typedef ::std::tr1::tuple<> type; 11791 static type GetSelectedFields(const Tuple& /* t */) { 11792 using ::std::tr1::get; 11793 return type(); 11794 } 11795 }; 11796 11797 template <class Tuple, int k0> 11798 class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> { 11799 public: 11800 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type; 11801 static type GetSelectedFields(const Tuple& t) { 11802 using ::std::tr1::get; 11803 return type(get<k0>(t)); 11804 } 11805 }; 11806 11807 template <class Tuple, int k0, int k1> 11808 class TupleFields<Tuple, k0, k1, -1, -1, -1, -1, -1, -1, -1, -1> { 11809 public: 11810 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), 11811 GMOCK_FIELD_TYPE_(Tuple, k1)> type; 11812 static type GetSelectedFields(const Tuple& t) { 11813 using ::std::tr1::get; 11814 return type(get<k0>(t), get<k1>(t)); 11815 } 11816 }; 11817 11818 template <class Tuple, int k0, int k1, int k2> 11819 class TupleFields<Tuple, k0, k1, k2, -1, -1, -1, -1, -1, -1, -1> { 11820 public: 11821 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), 11822 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2)> type; 11823 static type GetSelectedFields(const Tuple& t) { 11824 using ::std::tr1::get; 11825 return type(get<k0>(t), get<k1>(t), get<k2>(t)); 11826 } 11827 }; 11828 11829 template <class Tuple, int k0, int k1, int k2, int k3> 11830 class TupleFields<Tuple, k0, k1, k2, k3, -1, -1, -1, -1, -1, -1> { 11831 public: 11832 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), 11833 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), 11834 GMOCK_FIELD_TYPE_(Tuple, k3)> type; 11835 static type GetSelectedFields(const Tuple& t) { 11836 using ::std::tr1::get; 11837 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t)); 11838 } 11839 }; 11840 11841 template <class Tuple, int k0, int k1, int k2, int k3, int k4> 11842 class TupleFields<Tuple, k0, k1, k2, k3, k4, -1, -1, -1, -1, -1> { 11843 public: 11844 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), 11845 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), 11846 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4)> type; 11847 static type GetSelectedFields(const Tuple& t) { 11848 using ::std::tr1::get; 11849 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t)); 11850 } 11851 }; 11852 11853 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5> 11854 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, -1, -1, -1, -1> { 11855 public: 11856 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), 11857 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), 11858 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4), 11859 GMOCK_FIELD_TYPE_(Tuple, k5)> type; 11860 static type GetSelectedFields(const Tuple& t) { 11861 using ::std::tr1::get; 11862 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t), 11863 get<k5>(t)); 11864 } 11865 }; 11866 11867 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6> 11868 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, -1, -1, -1> { 11869 public: 11870 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), 11871 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), 11872 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4), 11873 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6)> type; 11874 static type GetSelectedFields(const Tuple& t) { 11875 using ::std::tr1::get; 11876 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t), 11877 get<k5>(t), get<k6>(t)); 11878 } 11879 }; 11880 11881 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6, 11882 int k7> 11883 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, -1, -1> { 11884 public: 11885 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), 11886 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), 11887 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4), 11888 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6), 11889 GMOCK_FIELD_TYPE_(Tuple, k7)> type; 11890 static type GetSelectedFields(const Tuple& t) { 11891 using ::std::tr1::get; 11892 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t), 11893 get<k5>(t), get<k6>(t), get<k7>(t)); 11894 } 11895 }; 11896 11897 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6, 11898 int k7, int k8> 11899 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, -1> { 11900 public: 11901 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), 11902 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), 11903 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4), 11904 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6), 11905 GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8)> type; 11906 static type GetSelectedFields(const Tuple& t) { 11907 using ::std::tr1::get; 11908 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t), 11909 get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t)); 11910 } 11911 }; 11912 11913 #undef GMOCK_FIELD_TYPE_ 11914 11915 // Implements the Args() matcher. 11916 template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1, 11917 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1, 11918 int k9 = -1> 11919 class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> { 11920 public: 11921 // ArgsTuple may have top-level const or reference modifiers. 11922 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple; 11923 typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, 11924 k6, k7, k8, k9>::type SelectedArgs; 11925 typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher; 11926 11927 template <typename InnerMatcher> 11928 explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) 11929 : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {} 11930 11931 virtual bool MatchAndExplain(ArgsTuple args, 11932 MatchResultListener* listener) const { 11933 const SelectedArgs& selected_args = GetSelectedArgs(args); 11934 if (!listener->IsInterested()) 11935 return inner_matcher_.Matches(selected_args); 11936 11937 PrintIndices(listener->stream()); 11938 *listener << "are " << PrintToString(selected_args); 11939 11940 StringMatchResultListener inner_listener; 11941 const bool match = inner_matcher_.MatchAndExplain(selected_args, 11942 &inner_listener); 11943 PrintIfNotEmpty(inner_listener.str(), listener->stream()); 11944 return match; 11945 } 11946 11947 virtual void DescribeTo(::std::ostream* os) const { 11948 *os << "are a tuple "; 11949 PrintIndices(os); 11950 inner_matcher_.DescribeTo(os); 11951 } 11952 11953 virtual void DescribeNegationTo(::std::ostream* os) const { 11954 *os << "are a tuple "; 11955 PrintIndices(os); 11956 inner_matcher_.DescribeNegationTo(os); 11957 } 11958 11959 private: 11960 static SelectedArgs GetSelectedArgs(ArgsTuple args) { 11961 return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, 11962 k9>::GetSelectedFields(args); 11963 } 11964 11965 // Prints the indices of the selected fields. 11966 static void PrintIndices(::std::ostream* os) { 11967 *os << "whose fields ("; 11968 const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 }; 11969 for (int i = 0; i < 10; i++) { 11970 if (indices[i] < 0) 11971 break; 11972 11973 if (i >= 1) 11974 *os << ", "; 11975 11976 *os << "#" << indices[i]; 11977 } 11978 *os << ") "; 11979 } 11980 11981 const MonomorphicInnerMatcher inner_matcher_; 11982 11983 GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl); 11984 }; 11985 11986 template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1, 11987 int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, 11988 int k8 = -1, int k9 = -1> 11989 class ArgsMatcher { 11990 public: 11991 explicit ArgsMatcher(const InnerMatcher& inner_matcher) 11992 : inner_matcher_(inner_matcher) {} 11993 11994 template <typename ArgsTuple> 11995 operator Matcher<ArgsTuple>() const { 11996 return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k5, 11997 k6, k7, k8, k9>(inner_matcher_)); 11998 } 11999 12000 private: 12001 const InnerMatcher inner_matcher_; 12002 12003 GTEST_DISALLOW_ASSIGN_(ArgsMatcher); 12004 }; 12005 12006 // A set of metafunctions for computing the result type of AllOf. 12007 // AllOf(m1, ..., mN) returns 12008 // AllOfResultN<decltype(m1), ..., decltype(mN)>::type. 12009 12010 // Although AllOf isn't defined for one argument, AllOfResult1 is defined 12011 // to simplify the implementation. 12012 template <typename M1> 12013 struct AllOfResult1 { 12014 typedef M1 type; 12015 }; 12016 12017 template <typename M1, typename M2> 12018 struct AllOfResult2 { 12019 typedef BothOfMatcher< 12020 typename AllOfResult1<M1>::type, 12021 typename AllOfResult1<M2>::type 12022 > type; 12023 }; 12024 12025 template <typename M1, typename M2, typename M3> 12026 struct AllOfResult3 { 12027 typedef BothOfMatcher< 12028 typename AllOfResult1<M1>::type, 12029 typename AllOfResult2<M2, M3>::type 12030 > type; 12031 }; 12032 12033 template <typename M1, typename M2, typename M3, typename M4> 12034 struct AllOfResult4 { 12035 typedef BothOfMatcher< 12036 typename AllOfResult2<M1, M2>::type, 12037 typename AllOfResult2<M3, M4>::type 12038 > type; 12039 }; 12040 12041 template <typename M1, typename M2, typename M3, typename M4, typename M5> 12042 struct AllOfResult5 { 12043 typedef BothOfMatcher< 12044 typename AllOfResult2<M1, M2>::type, 12045 typename AllOfResult3<M3, M4, M5>::type 12046 > type; 12047 }; 12048 12049 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12050 typename M6> 12051 struct AllOfResult6 { 12052 typedef BothOfMatcher< 12053 typename AllOfResult3<M1, M2, M3>::type, 12054 typename AllOfResult3<M4, M5, M6>::type 12055 > type; 12056 }; 12057 12058 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12059 typename M6, typename M7> 12060 struct AllOfResult7 { 12061 typedef BothOfMatcher< 12062 typename AllOfResult3<M1, M2, M3>::type, 12063 typename AllOfResult4<M4, M5, M6, M7>::type 12064 > type; 12065 }; 12066 12067 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12068 typename M6, typename M7, typename M8> 12069 struct AllOfResult8 { 12070 typedef BothOfMatcher< 12071 typename AllOfResult4<M1, M2, M3, M4>::type, 12072 typename AllOfResult4<M5, M6, M7, M8>::type 12073 > type; 12074 }; 12075 12076 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12077 typename M6, typename M7, typename M8, typename M9> 12078 struct AllOfResult9 { 12079 typedef BothOfMatcher< 12080 typename AllOfResult4<M1, M2, M3, M4>::type, 12081 typename AllOfResult5<M5, M6, M7, M8, M9>::type 12082 > type; 12083 }; 12084 12085 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12086 typename M6, typename M7, typename M8, typename M9, typename M10> 12087 struct AllOfResult10 { 12088 typedef BothOfMatcher< 12089 typename AllOfResult5<M1, M2, M3, M4, M5>::type, 12090 typename AllOfResult5<M6, M7, M8, M9, M10>::type 12091 > type; 12092 }; 12093 12094 // A set of metafunctions for computing the result type of AnyOf. 12095 // AnyOf(m1, ..., mN) returns 12096 // AnyOfResultN<decltype(m1), ..., decltype(mN)>::type. 12097 12098 // Although AnyOf isn't defined for one argument, AnyOfResult1 is defined 12099 // to simplify the implementation. 12100 template <typename M1> 12101 struct AnyOfResult1 { 12102 typedef M1 type; 12103 }; 12104 12105 template <typename M1, typename M2> 12106 struct AnyOfResult2 { 12107 typedef EitherOfMatcher< 12108 typename AnyOfResult1<M1>::type, 12109 typename AnyOfResult1<M2>::type 12110 > type; 12111 }; 12112 12113 template <typename M1, typename M2, typename M3> 12114 struct AnyOfResult3 { 12115 typedef EitherOfMatcher< 12116 typename AnyOfResult1<M1>::type, 12117 typename AnyOfResult2<M2, M3>::type 12118 > type; 12119 }; 12120 12121 template <typename M1, typename M2, typename M3, typename M4> 12122 struct AnyOfResult4 { 12123 typedef EitherOfMatcher< 12124 typename AnyOfResult2<M1, M2>::type, 12125 typename AnyOfResult2<M3, M4>::type 12126 > type; 12127 }; 12128 12129 template <typename M1, typename M2, typename M3, typename M4, typename M5> 12130 struct AnyOfResult5 { 12131 typedef EitherOfMatcher< 12132 typename AnyOfResult2<M1, M2>::type, 12133 typename AnyOfResult3<M3, M4, M5>::type 12134 > type; 12135 }; 12136 12137 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12138 typename M6> 12139 struct AnyOfResult6 { 12140 typedef EitherOfMatcher< 12141 typename AnyOfResult3<M1, M2, M3>::type, 12142 typename AnyOfResult3<M4, M5, M6>::type 12143 > type; 12144 }; 12145 12146 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12147 typename M6, typename M7> 12148 struct AnyOfResult7 { 12149 typedef EitherOfMatcher< 12150 typename AnyOfResult3<M1, M2, M3>::type, 12151 typename AnyOfResult4<M4, M5, M6, M7>::type 12152 > type; 12153 }; 12154 12155 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12156 typename M6, typename M7, typename M8> 12157 struct AnyOfResult8 { 12158 typedef EitherOfMatcher< 12159 typename AnyOfResult4<M1, M2, M3, M4>::type, 12160 typename AnyOfResult4<M5, M6, M7, M8>::type 12161 > type; 12162 }; 12163 12164 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12165 typename M6, typename M7, typename M8, typename M9> 12166 struct AnyOfResult9 { 12167 typedef EitherOfMatcher< 12168 typename AnyOfResult4<M1, M2, M3, M4>::type, 12169 typename AnyOfResult5<M5, M6, M7, M8, M9>::type 12170 > type; 12171 }; 12172 12173 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12174 typename M6, typename M7, typename M8, typename M9, typename M10> 12175 struct AnyOfResult10 { 12176 typedef EitherOfMatcher< 12177 typename AnyOfResult5<M1, M2, M3, M4, M5>::type, 12178 typename AnyOfResult5<M6, M7, M8, M9, M10>::type 12179 > type; 12180 }; 12181 12182 } // namespace internal 12183 12184 // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected 12185 // fields of it matches a_matcher. C++ doesn't support default 12186 // arguments for function templates, so we have to overload it. 12187 template <typename InnerMatcher> 12188 inline internal::ArgsMatcher<InnerMatcher> 12189 Args(const InnerMatcher& matcher) { 12190 return internal::ArgsMatcher<InnerMatcher>(matcher); 12191 } 12192 12193 template <int k1, typename InnerMatcher> 12194 inline internal::ArgsMatcher<InnerMatcher, k1> 12195 Args(const InnerMatcher& matcher) { 12196 return internal::ArgsMatcher<InnerMatcher, k1>(matcher); 12197 } 12198 12199 template <int k1, int k2, typename InnerMatcher> 12200 inline internal::ArgsMatcher<InnerMatcher, k1, k2> 12201 Args(const InnerMatcher& matcher) { 12202 return internal::ArgsMatcher<InnerMatcher, k1, k2>(matcher); 12203 } 12204 12205 template <int k1, int k2, int k3, typename InnerMatcher> 12206 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3> 12207 Args(const InnerMatcher& matcher) { 12208 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3>(matcher); 12209 } 12210 12211 template <int k1, int k2, int k3, int k4, typename InnerMatcher> 12212 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4> 12213 Args(const InnerMatcher& matcher) { 12214 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>(matcher); 12215 } 12216 12217 template <int k1, int k2, int k3, int k4, int k5, typename InnerMatcher> 12218 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5> 12219 Args(const InnerMatcher& matcher) { 12220 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>(matcher); 12221 } 12222 12223 template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerMatcher> 12224 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6> 12225 Args(const InnerMatcher& matcher) { 12226 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>(matcher); 12227 } 12228 12229 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, 12230 typename InnerMatcher> 12231 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7> 12232 Args(const InnerMatcher& matcher) { 12233 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, 12234 k7>(matcher); 12235 } 12236 12237 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, 12238 typename InnerMatcher> 12239 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8> 12240 Args(const InnerMatcher& matcher) { 12241 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, 12242 k8>(matcher); 12243 } 12244 12245 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, 12246 int k9, typename InnerMatcher> 12247 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9> 12248 Args(const InnerMatcher& matcher) { 12249 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, 12250 k9>(matcher); 12251 } 12252 12253 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, 12254 int k9, int k10, typename InnerMatcher> 12255 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9, 12256 k10> 12257 Args(const InnerMatcher& matcher) { 12258 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, 12259 k9, k10>(matcher); 12260 } 12261 12262 // ElementsAre(e_1, e_2, ... e_n) matches an STL-style container with 12263 // n elements, where the i-th element in the container must 12264 // match the i-th argument in the list. Each argument of 12265 // ElementsAre() can be either a value or a matcher. We support up to 12266 // 10 arguments. 12267 // 12268 // The use of DecayArray in the implementation allows ElementsAre() 12269 // to accept string literals, whose type is const char[N], but we 12270 // want to treat them as const char*. 12271 // 12272 // NOTE: Since ElementsAre() cares about the order of the elements, it 12273 // must not be used with containers whose elements's order is 12274 // undefined (e.g. hash_map). 12275 12276 inline internal::ElementsAreMatcher< 12277 std::tr1::tuple<> > 12278 ElementsAre() { 12279 typedef std::tr1::tuple<> Args; 12280 return internal::ElementsAreMatcher<Args>(Args()); 12281 } 12282 12283 template <typename T1> 12284 inline internal::ElementsAreMatcher< 12285 std::tr1::tuple< 12286 typename internal::DecayArray<T1>::type> > 12287 ElementsAre(const T1& e1) { 12288 typedef std::tr1::tuple< 12289 typename internal::DecayArray<T1>::type> Args; 12290 return internal::ElementsAreMatcher<Args>(Args(e1)); 12291 } 12292 12293 template <typename T1, typename T2> 12294 inline internal::ElementsAreMatcher< 12295 std::tr1::tuple< 12296 typename internal::DecayArray<T1>::type, 12297 typename internal::DecayArray<T2>::type> > 12298 ElementsAre(const T1& e1, const T2& e2) { 12299 typedef std::tr1::tuple< 12300 typename internal::DecayArray<T1>::type, 12301 typename internal::DecayArray<T2>::type> Args; 12302 return internal::ElementsAreMatcher<Args>(Args(e1, e2)); 12303 } 12304 12305 template <typename T1, typename T2, typename T3> 12306 inline internal::ElementsAreMatcher< 12307 std::tr1::tuple< 12308 typename internal::DecayArray<T1>::type, 12309 typename internal::DecayArray<T2>::type, 12310 typename internal::DecayArray<T3>::type> > 12311 ElementsAre(const T1& e1, const T2& e2, const T3& e3) { 12312 typedef std::tr1::tuple< 12313 typename internal::DecayArray<T1>::type, 12314 typename internal::DecayArray<T2>::type, 12315 typename internal::DecayArray<T3>::type> Args; 12316 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3)); 12317 } 12318 12319 template <typename T1, typename T2, typename T3, typename T4> 12320 inline internal::ElementsAreMatcher< 12321 std::tr1::tuple< 12322 typename internal::DecayArray<T1>::type, 12323 typename internal::DecayArray<T2>::type, 12324 typename internal::DecayArray<T3>::type, 12325 typename internal::DecayArray<T4>::type> > 12326 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) { 12327 typedef std::tr1::tuple< 12328 typename internal::DecayArray<T1>::type, 12329 typename internal::DecayArray<T2>::type, 12330 typename internal::DecayArray<T3>::type, 12331 typename internal::DecayArray<T4>::type> Args; 12332 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4)); 12333 } 12334 12335 template <typename T1, typename T2, typename T3, typename T4, typename T5> 12336 inline internal::ElementsAreMatcher< 12337 std::tr1::tuple< 12338 typename internal::DecayArray<T1>::type, 12339 typename internal::DecayArray<T2>::type, 12340 typename internal::DecayArray<T3>::type, 12341 typename internal::DecayArray<T4>::type, 12342 typename internal::DecayArray<T5>::type> > 12343 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12344 const T5& e5) { 12345 typedef std::tr1::tuple< 12346 typename internal::DecayArray<T1>::type, 12347 typename internal::DecayArray<T2>::type, 12348 typename internal::DecayArray<T3>::type, 12349 typename internal::DecayArray<T4>::type, 12350 typename internal::DecayArray<T5>::type> Args; 12351 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5)); 12352 } 12353 12354 template <typename T1, typename T2, typename T3, typename T4, typename T5, 12355 typename T6> 12356 inline internal::ElementsAreMatcher< 12357 std::tr1::tuple< 12358 typename internal::DecayArray<T1>::type, 12359 typename internal::DecayArray<T2>::type, 12360 typename internal::DecayArray<T3>::type, 12361 typename internal::DecayArray<T4>::type, 12362 typename internal::DecayArray<T5>::type, 12363 typename internal::DecayArray<T6>::type> > 12364 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12365 const T5& e5, const T6& e6) { 12366 typedef std::tr1::tuple< 12367 typename internal::DecayArray<T1>::type, 12368 typename internal::DecayArray<T2>::type, 12369 typename internal::DecayArray<T3>::type, 12370 typename internal::DecayArray<T4>::type, 12371 typename internal::DecayArray<T5>::type, 12372 typename internal::DecayArray<T6>::type> Args; 12373 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6)); 12374 } 12375 12376 template <typename T1, typename T2, typename T3, typename T4, typename T5, 12377 typename T6, typename T7> 12378 inline internal::ElementsAreMatcher< 12379 std::tr1::tuple< 12380 typename internal::DecayArray<T1>::type, 12381 typename internal::DecayArray<T2>::type, 12382 typename internal::DecayArray<T3>::type, 12383 typename internal::DecayArray<T4>::type, 12384 typename internal::DecayArray<T5>::type, 12385 typename internal::DecayArray<T6>::type, 12386 typename internal::DecayArray<T7>::type> > 12387 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12388 const T5& e5, const T6& e6, const T7& e7) { 12389 typedef std::tr1::tuple< 12390 typename internal::DecayArray<T1>::type, 12391 typename internal::DecayArray<T2>::type, 12392 typename internal::DecayArray<T3>::type, 12393 typename internal::DecayArray<T4>::type, 12394 typename internal::DecayArray<T5>::type, 12395 typename internal::DecayArray<T6>::type, 12396 typename internal::DecayArray<T7>::type> Args; 12397 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7)); 12398 } 12399 12400 template <typename T1, typename T2, typename T3, typename T4, typename T5, 12401 typename T6, typename T7, typename T8> 12402 inline internal::ElementsAreMatcher< 12403 std::tr1::tuple< 12404 typename internal::DecayArray<T1>::type, 12405 typename internal::DecayArray<T2>::type, 12406 typename internal::DecayArray<T3>::type, 12407 typename internal::DecayArray<T4>::type, 12408 typename internal::DecayArray<T5>::type, 12409 typename internal::DecayArray<T6>::type, 12410 typename internal::DecayArray<T7>::type, 12411 typename internal::DecayArray<T8>::type> > 12412 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12413 const T5& e5, const T6& e6, const T7& e7, const T8& e8) { 12414 typedef std::tr1::tuple< 12415 typename internal::DecayArray<T1>::type, 12416 typename internal::DecayArray<T2>::type, 12417 typename internal::DecayArray<T3>::type, 12418 typename internal::DecayArray<T4>::type, 12419 typename internal::DecayArray<T5>::type, 12420 typename internal::DecayArray<T6>::type, 12421 typename internal::DecayArray<T7>::type, 12422 typename internal::DecayArray<T8>::type> Args; 12423 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7, 12424 e8)); 12425 } 12426 12427 template <typename T1, typename T2, typename T3, typename T4, typename T5, 12428 typename T6, typename T7, typename T8, typename T9> 12429 inline internal::ElementsAreMatcher< 12430 std::tr1::tuple< 12431 typename internal::DecayArray<T1>::type, 12432 typename internal::DecayArray<T2>::type, 12433 typename internal::DecayArray<T3>::type, 12434 typename internal::DecayArray<T4>::type, 12435 typename internal::DecayArray<T5>::type, 12436 typename internal::DecayArray<T6>::type, 12437 typename internal::DecayArray<T7>::type, 12438 typename internal::DecayArray<T8>::type, 12439 typename internal::DecayArray<T9>::type> > 12440 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12441 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) { 12442 typedef std::tr1::tuple< 12443 typename internal::DecayArray<T1>::type, 12444 typename internal::DecayArray<T2>::type, 12445 typename internal::DecayArray<T3>::type, 12446 typename internal::DecayArray<T4>::type, 12447 typename internal::DecayArray<T5>::type, 12448 typename internal::DecayArray<T6>::type, 12449 typename internal::DecayArray<T7>::type, 12450 typename internal::DecayArray<T8>::type, 12451 typename internal::DecayArray<T9>::type> Args; 12452 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7, 12453 e8, e9)); 12454 } 12455 12456 template <typename T1, typename T2, typename T3, typename T4, typename T5, 12457 typename T6, typename T7, typename T8, typename T9, typename T10> 12458 inline internal::ElementsAreMatcher< 12459 std::tr1::tuple< 12460 typename internal::DecayArray<T1>::type, 12461 typename internal::DecayArray<T2>::type, 12462 typename internal::DecayArray<T3>::type, 12463 typename internal::DecayArray<T4>::type, 12464 typename internal::DecayArray<T5>::type, 12465 typename internal::DecayArray<T6>::type, 12466 typename internal::DecayArray<T7>::type, 12467 typename internal::DecayArray<T8>::type, 12468 typename internal::DecayArray<T9>::type, 12469 typename internal::DecayArray<T10>::type> > 12470 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12471 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9, 12472 const T10& e10) { 12473 typedef std::tr1::tuple< 12474 typename internal::DecayArray<T1>::type, 12475 typename internal::DecayArray<T2>::type, 12476 typename internal::DecayArray<T3>::type, 12477 typename internal::DecayArray<T4>::type, 12478 typename internal::DecayArray<T5>::type, 12479 typename internal::DecayArray<T6>::type, 12480 typename internal::DecayArray<T7>::type, 12481 typename internal::DecayArray<T8>::type, 12482 typename internal::DecayArray<T9>::type, 12483 typename internal::DecayArray<T10>::type> Args; 12484 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7, 12485 e8, e9, e10)); 12486 } 12487 12488 // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension 12489 // that matches n elements in any order. We support up to n=10 arguments. 12490 12491 inline internal::UnorderedElementsAreMatcher< 12492 std::tr1::tuple<> > 12493 UnorderedElementsAre() { 12494 typedef std::tr1::tuple<> Args; 12495 return internal::UnorderedElementsAreMatcher<Args>(Args()); 12496 } 12497 12498 template <typename T1> 12499 inline internal::UnorderedElementsAreMatcher< 12500 std::tr1::tuple< 12501 typename internal::DecayArray<T1>::type> > 12502 UnorderedElementsAre(const T1& e1) { 12503 typedef std::tr1::tuple< 12504 typename internal::DecayArray<T1>::type> Args; 12505 return internal::UnorderedElementsAreMatcher<Args>(Args(e1)); 12506 } 12507 12508 template <typename T1, typename T2> 12509 inline internal::UnorderedElementsAreMatcher< 12510 std::tr1::tuple< 12511 typename internal::DecayArray<T1>::type, 12512 typename internal::DecayArray<T2>::type> > 12513 UnorderedElementsAre(const T1& e1, const T2& e2) { 12514 typedef std::tr1::tuple< 12515 typename internal::DecayArray<T1>::type, 12516 typename internal::DecayArray<T2>::type> Args; 12517 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2)); 12518 } 12519 12520 template <typename T1, typename T2, typename T3> 12521 inline internal::UnorderedElementsAreMatcher< 12522 std::tr1::tuple< 12523 typename internal::DecayArray<T1>::type, 12524 typename internal::DecayArray<T2>::type, 12525 typename internal::DecayArray<T3>::type> > 12526 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3) { 12527 typedef std::tr1::tuple< 12528 typename internal::DecayArray<T1>::type, 12529 typename internal::DecayArray<T2>::type, 12530 typename internal::DecayArray<T3>::type> Args; 12531 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3)); 12532 } 12533 12534 template <typename T1, typename T2, typename T3, typename T4> 12535 inline internal::UnorderedElementsAreMatcher< 12536 std::tr1::tuple< 12537 typename internal::DecayArray<T1>::type, 12538 typename internal::DecayArray<T2>::type, 12539 typename internal::DecayArray<T3>::type, 12540 typename internal::DecayArray<T4>::type> > 12541 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) { 12542 typedef std::tr1::tuple< 12543 typename internal::DecayArray<T1>::type, 12544 typename internal::DecayArray<T2>::type, 12545 typename internal::DecayArray<T3>::type, 12546 typename internal::DecayArray<T4>::type> Args; 12547 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4)); 12548 } 12549 12550 template <typename T1, typename T2, typename T3, typename T4, typename T5> 12551 inline internal::UnorderedElementsAreMatcher< 12552 std::tr1::tuple< 12553 typename internal::DecayArray<T1>::type, 12554 typename internal::DecayArray<T2>::type, 12555 typename internal::DecayArray<T3>::type, 12556 typename internal::DecayArray<T4>::type, 12557 typename internal::DecayArray<T5>::type> > 12558 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12559 const T5& e5) { 12560 typedef std::tr1::tuple< 12561 typename internal::DecayArray<T1>::type, 12562 typename internal::DecayArray<T2>::type, 12563 typename internal::DecayArray<T3>::type, 12564 typename internal::DecayArray<T4>::type, 12565 typename internal::DecayArray<T5>::type> Args; 12566 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5)); 12567 } 12568 12569 template <typename T1, typename T2, typename T3, typename T4, typename T5, 12570 typename T6> 12571 inline internal::UnorderedElementsAreMatcher< 12572 std::tr1::tuple< 12573 typename internal::DecayArray<T1>::type, 12574 typename internal::DecayArray<T2>::type, 12575 typename internal::DecayArray<T3>::type, 12576 typename internal::DecayArray<T4>::type, 12577 typename internal::DecayArray<T5>::type, 12578 typename internal::DecayArray<T6>::type> > 12579 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12580 const T5& e5, const T6& e6) { 12581 typedef std::tr1::tuple< 12582 typename internal::DecayArray<T1>::type, 12583 typename internal::DecayArray<T2>::type, 12584 typename internal::DecayArray<T3>::type, 12585 typename internal::DecayArray<T4>::type, 12586 typename internal::DecayArray<T5>::type, 12587 typename internal::DecayArray<T6>::type> Args; 12588 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, 12589 e6)); 12590 } 12591 12592 template <typename T1, typename T2, typename T3, typename T4, typename T5, 12593 typename T6, typename T7> 12594 inline internal::UnorderedElementsAreMatcher< 12595 std::tr1::tuple< 12596 typename internal::DecayArray<T1>::type, 12597 typename internal::DecayArray<T2>::type, 12598 typename internal::DecayArray<T3>::type, 12599 typename internal::DecayArray<T4>::type, 12600 typename internal::DecayArray<T5>::type, 12601 typename internal::DecayArray<T6>::type, 12602 typename internal::DecayArray<T7>::type> > 12603 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12604 const T5& e5, const T6& e6, const T7& e7) { 12605 typedef std::tr1::tuple< 12606 typename internal::DecayArray<T1>::type, 12607 typename internal::DecayArray<T2>::type, 12608 typename internal::DecayArray<T3>::type, 12609 typename internal::DecayArray<T4>::type, 12610 typename internal::DecayArray<T5>::type, 12611 typename internal::DecayArray<T6>::type, 12612 typename internal::DecayArray<T7>::type> Args; 12613 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, 12614 e6, e7)); 12615 } 12616 12617 template <typename T1, typename T2, typename T3, typename T4, typename T5, 12618 typename T6, typename T7, typename T8> 12619 inline internal::UnorderedElementsAreMatcher< 12620 std::tr1::tuple< 12621 typename internal::DecayArray<T1>::type, 12622 typename internal::DecayArray<T2>::type, 12623 typename internal::DecayArray<T3>::type, 12624 typename internal::DecayArray<T4>::type, 12625 typename internal::DecayArray<T5>::type, 12626 typename internal::DecayArray<T6>::type, 12627 typename internal::DecayArray<T7>::type, 12628 typename internal::DecayArray<T8>::type> > 12629 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12630 const T5& e5, const T6& e6, const T7& e7, const T8& e8) { 12631 typedef std::tr1::tuple< 12632 typename internal::DecayArray<T1>::type, 12633 typename internal::DecayArray<T2>::type, 12634 typename internal::DecayArray<T3>::type, 12635 typename internal::DecayArray<T4>::type, 12636 typename internal::DecayArray<T5>::type, 12637 typename internal::DecayArray<T6>::type, 12638 typename internal::DecayArray<T7>::type, 12639 typename internal::DecayArray<T8>::type> Args; 12640 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, 12641 e6, e7, e8)); 12642 } 12643 12644 template <typename T1, typename T2, typename T3, typename T4, typename T5, 12645 typename T6, typename T7, typename T8, typename T9> 12646 inline internal::UnorderedElementsAreMatcher< 12647 std::tr1::tuple< 12648 typename internal::DecayArray<T1>::type, 12649 typename internal::DecayArray<T2>::type, 12650 typename internal::DecayArray<T3>::type, 12651 typename internal::DecayArray<T4>::type, 12652 typename internal::DecayArray<T5>::type, 12653 typename internal::DecayArray<T6>::type, 12654 typename internal::DecayArray<T7>::type, 12655 typename internal::DecayArray<T8>::type, 12656 typename internal::DecayArray<T9>::type> > 12657 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12658 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) { 12659 typedef std::tr1::tuple< 12660 typename internal::DecayArray<T1>::type, 12661 typename internal::DecayArray<T2>::type, 12662 typename internal::DecayArray<T3>::type, 12663 typename internal::DecayArray<T4>::type, 12664 typename internal::DecayArray<T5>::type, 12665 typename internal::DecayArray<T6>::type, 12666 typename internal::DecayArray<T7>::type, 12667 typename internal::DecayArray<T8>::type, 12668 typename internal::DecayArray<T9>::type> Args; 12669 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, 12670 e6, e7, e8, e9)); 12671 } 12672 12673 template <typename T1, typename T2, typename T3, typename T4, typename T5, 12674 typename T6, typename T7, typename T8, typename T9, typename T10> 12675 inline internal::UnorderedElementsAreMatcher< 12676 std::tr1::tuple< 12677 typename internal::DecayArray<T1>::type, 12678 typename internal::DecayArray<T2>::type, 12679 typename internal::DecayArray<T3>::type, 12680 typename internal::DecayArray<T4>::type, 12681 typename internal::DecayArray<T5>::type, 12682 typename internal::DecayArray<T6>::type, 12683 typename internal::DecayArray<T7>::type, 12684 typename internal::DecayArray<T8>::type, 12685 typename internal::DecayArray<T9>::type, 12686 typename internal::DecayArray<T10>::type> > 12687 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, 12688 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9, 12689 const T10& e10) { 12690 typedef std::tr1::tuple< 12691 typename internal::DecayArray<T1>::type, 12692 typename internal::DecayArray<T2>::type, 12693 typename internal::DecayArray<T3>::type, 12694 typename internal::DecayArray<T4>::type, 12695 typename internal::DecayArray<T5>::type, 12696 typename internal::DecayArray<T6>::type, 12697 typename internal::DecayArray<T7>::type, 12698 typename internal::DecayArray<T8>::type, 12699 typename internal::DecayArray<T9>::type, 12700 typename internal::DecayArray<T10>::type> Args; 12701 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, 12702 e6, e7, e8, e9, e10)); 12703 } 12704 12705 // AllOf(m1, m2, ..., mk) matches any value that matches all of the given 12706 // sub-matchers. AllOf is called fully qualified to prevent ADL from firing. 12707 12708 template <typename M1, typename M2> 12709 inline typename internal::AllOfResult2<M1, M2>::type 12710 AllOf(M1 m1, M2 m2) { 12711 return typename internal::AllOfResult2<M1, M2>::type( 12712 m1, 12713 m2); 12714 } 12715 12716 template <typename M1, typename M2, typename M3> 12717 inline typename internal::AllOfResult3<M1, M2, M3>::type 12718 AllOf(M1 m1, M2 m2, M3 m3) { 12719 return typename internal::AllOfResult3<M1, M2, M3>::type( 12720 m1, 12721 ::testing::AllOf(m2, m3)); 12722 } 12723 12724 template <typename M1, typename M2, typename M3, typename M4> 12725 inline typename internal::AllOfResult4<M1, M2, M3, M4>::type 12726 AllOf(M1 m1, M2 m2, M3 m3, M4 m4) { 12727 return typename internal::AllOfResult4<M1, M2, M3, M4>::type( 12728 ::testing::AllOf(m1, m2), 12729 ::testing::AllOf(m3, m4)); 12730 } 12731 12732 template <typename M1, typename M2, typename M3, typename M4, typename M5> 12733 inline typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type 12734 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) { 12735 return typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type( 12736 ::testing::AllOf(m1, m2), 12737 ::testing::AllOf(m3, m4, m5)); 12738 } 12739 12740 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12741 typename M6> 12742 inline typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type 12743 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) { 12744 return typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type( 12745 ::testing::AllOf(m1, m2, m3), 12746 ::testing::AllOf(m4, m5, m6)); 12747 } 12748 12749 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12750 typename M6, typename M7> 12751 inline typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type 12752 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) { 12753 return typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type( 12754 ::testing::AllOf(m1, m2, m3), 12755 ::testing::AllOf(m4, m5, m6, m7)); 12756 } 12757 12758 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12759 typename M6, typename M7, typename M8> 12760 inline typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type 12761 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) { 12762 return typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type( 12763 ::testing::AllOf(m1, m2, m3, m4), 12764 ::testing::AllOf(m5, m6, m7, m8)); 12765 } 12766 12767 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12768 typename M6, typename M7, typename M8, typename M9> 12769 inline typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type 12770 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) { 12771 return typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, 12772 M9>::type( 12773 ::testing::AllOf(m1, m2, m3, m4), 12774 ::testing::AllOf(m5, m6, m7, m8, m9)); 12775 } 12776 12777 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12778 typename M6, typename M7, typename M8, typename M9, typename M10> 12779 inline typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9, 12780 M10>::type 12781 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 12782 return typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9, 12783 M10>::type( 12784 ::testing::AllOf(m1, m2, m3, m4, m5), 12785 ::testing::AllOf(m6, m7, m8, m9, m10)); 12786 } 12787 12788 // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given 12789 // sub-matchers. AnyOf is called fully qualified to prevent ADL from firing. 12790 12791 template <typename M1, typename M2> 12792 inline typename internal::AnyOfResult2<M1, M2>::type 12793 AnyOf(M1 m1, M2 m2) { 12794 return typename internal::AnyOfResult2<M1, M2>::type( 12795 m1, 12796 m2); 12797 } 12798 12799 template <typename M1, typename M2, typename M3> 12800 inline typename internal::AnyOfResult3<M1, M2, M3>::type 12801 AnyOf(M1 m1, M2 m2, M3 m3) { 12802 return typename internal::AnyOfResult3<M1, M2, M3>::type( 12803 m1, 12804 ::testing::AnyOf(m2, m3)); 12805 } 12806 12807 template <typename M1, typename M2, typename M3, typename M4> 12808 inline typename internal::AnyOfResult4<M1, M2, M3, M4>::type 12809 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4) { 12810 return typename internal::AnyOfResult4<M1, M2, M3, M4>::type( 12811 ::testing::AnyOf(m1, m2), 12812 ::testing::AnyOf(m3, m4)); 12813 } 12814 12815 template <typename M1, typename M2, typename M3, typename M4, typename M5> 12816 inline typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type 12817 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) { 12818 return typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type( 12819 ::testing::AnyOf(m1, m2), 12820 ::testing::AnyOf(m3, m4, m5)); 12821 } 12822 12823 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12824 typename M6> 12825 inline typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type 12826 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) { 12827 return typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type( 12828 ::testing::AnyOf(m1, m2, m3), 12829 ::testing::AnyOf(m4, m5, m6)); 12830 } 12831 12832 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12833 typename M6, typename M7> 12834 inline typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type 12835 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) { 12836 return typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type( 12837 ::testing::AnyOf(m1, m2, m3), 12838 ::testing::AnyOf(m4, m5, m6, m7)); 12839 } 12840 12841 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12842 typename M6, typename M7, typename M8> 12843 inline typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type 12844 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) { 12845 return typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type( 12846 ::testing::AnyOf(m1, m2, m3, m4), 12847 ::testing::AnyOf(m5, m6, m7, m8)); 12848 } 12849 12850 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12851 typename M6, typename M7, typename M8, typename M9> 12852 inline typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type 12853 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) { 12854 return typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, 12855 M9>::type( 12856 ::testing::AnyOf(m1, m2, m3, m4), 12857 ::testing::AnyOf(m5, m6, m7, m8, m9)); 12858 } 12859 12860 template <typename M1, typename M2, typename M3, typename M4, typename M5, 12861 typename M6, typename M7, typename M8, typename M9, typename M10> 12862 inline typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9, 12863 M10>::type 12864 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 12865 return typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9, 12866 M10>::type( 12867 ::testing::AnyOf(m1, m2, m3, m4, m5), 12868 ::testing::AnyOf(m6, m7, m8, m9, m10)); 12869 } 12870 12871 } // namespace testing 12872 12873 12874 // The MATCHER* family of macros can be used in a namespace scope to 12875 // define custom matchers easily. 12876 // 12877 // Basic Usage 12878 // =========== 12879 // 12880 // The syntax 12881 // 12882 // MATCHER(name, description_string) { statements; } 12883 // 12884 // defines a matcher with the given name that executes the statements, 12885 // which must return a bool to indicate if the match succeeds. Inside 12886 // the statements, you can refer to the value being matched by 'arg', 12887 // and refer to its type by 'arg_type'. 12888 // 12889 // The description string documents what the matcher does, and is used 12890 // to generate the failure message when the match fails. Since a 12891 // MATCHER() is usually defined in a header file shared by multiple 12892 // C++ source files, we require the description to be a C-string 12893 // literal to avoid possible side effects. It can be empty, in which 12894 // case we'll use the sequence of words in the matcher name as the 12895 // description. 12896 // 12897 // For example: 12898 // 12899 // MATCHER(IsEven, "") { return (arg % 2) == 0; } 12900 // 12901 // allows you to write 12902 // 12903 // // Expects mock_foo.Bar(n) to be called where n is even. 12904 // EXPECT_CALL(mock_foo, Bar(IsEven())); 12905 // 12906 // or, 12907 // 12908 // // Verifies that the value of some_expression is even. 12909 // EXPECT_THAT(some_expression, IsEven()); 12910 // 12911 // If the above assertion fails, it will print something like: 12912 // 12913 // Value of: some_expression 12914 // Expected: is even 12915 // Actual: 7 12916 // 12917 // where the description "is even" is automatically calculated from the 12918 // matcher name IsEven. 12919 // 12920 // Argument Type 12921 // ============= 12922 // 12923 // Note that the type of the value being matched (arg_type) is 12924 // determined by the context in which you use the matcher and is 12925 // supplied to you by the compiler, so you don't need to worry about 12926 // declaring it (nor can you). This allows the matcher to be 12927 // polymorphic. For example, IsEven() can be used to match any type 12928 // where the value of "(arg % 2) == 0" can be implicitly converted to 12929 // a bool. In the "Bar(IsEven())" example above, if method Bar() 12930 // takes an int, 'arg_type' will be int; if it takes an unsigned long, 12931 // 'arg_type' will be unsigned long; and so on. 12932 // 12933 // Parameterizing Matchers 12934 // ======================= 12935 // 12936 // Sometimes you'll want to parameterize the matcher. For that you 12937 // can use another macro: 12938 // 12939 // MATCHER_P(name, param_name, description_string) { statements; } 12940 // 12941 // For example: 12942 // 12943 // MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; } 12944 // 12945 // will allow you to write: 12946 // 12947 // EXPECT_THAT(Blah("a"), HasAbsoluteValue(n)); 12948 // 12949 // which may lead to this message (assuming n is 10): 12950 // 12951 // Value of: Blah("a") 12952 // Expected: has absolute value 10 12953 // Actual: -9 12954 // 12955 // Note that both the matcher description and its parameter are 12956 // printed, making the message human-friendly. 12957 // 12958 // In the matcher definition body, you can write 'foo_type' to 12959 // reference the type of a parameter named 'foo'. For example, in the 12960 // body of MATCHER_P(HasAbsoluteValue, value) above, you can write 12961 // 'value_type' to refer to the type of 'value'. 12962 // 12963 // We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to 12964 // support multi-parameter matchers. 12965 // 12966 // Describing Parameterized Matchers 12967 // ================================= 12968 // 12969 // The last argument to MATCHER*() is a string-typed expression. The 12970 // expression can reference all of the matcher's parameters and a 12971 // special bool-typed variable named 'negation'. When 'negation' is 12972 // false, the expression should evaluate to the matcher's description; 12973 // otherwise it should evaluate to the description of the negation of 12974 // the matcher. For example, 12975 // 12976 // using testing::PrintToString; 12977 // 12978 // MATCHER_P2(InClosedRange, low, hi, 12979 // string(negation ? "is not" : "is") + " in range [" + 12980 // PrintToString(low) + ", " + PrintToString(hi) + "]") { 12981 // return low <= arg && arg <= hi; 12982 // } 12983 // ... 12984 // EXPECT_THAT(3, InClosedRange(4, 6)); 12985 // EXPECT_THAT(3, Not(InClosedRange(2, 4))); 12986 // 12987 // would generate two failures that contain the text: 12988 // 12989 // Expected: is in range [4, 6] 12990 // ... 12991 // Expected: is not in range [2, 4] 12992 // 12993 // If you specify "" as the description, the failure message will 12994 // contain the sequence of words in the matcher name followed by the 12995 // parameter values printed as a tuple. For example, 12996 // 12997 // MATCHER_P2(InClosedRange, low, hi, "") { ... } 12998 // ... 12999 // EXPECT_THAT(3, InClosedRange(4, 6)); 13000 // EXPECT_THAT(3, Not(InClosedRange(2, 4))); 13001 // 13002 // would generate two failures that contain the text: 13003 // 13004 // Expected: in closed range (4, 6) 13005 // ... 13006 // Expected: not (in closed range (2, 4)) 13007 // 13008 // Types of Matcher Parameters 13009 // =========================== 13010 // 13011 // For the purpose of typing, you can view 13012 // 13013 // MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... } 13014 // 13015 // as shorthand for 13016 // 13017 // template <typename p1_type, ..., typename pk_type> 13018 // FooMatcherPk<p1_type, ..., pk_type> 13019 // Foo(p1_type p1, ..., pk_type pk) { ... } 13020 // 13021 // When you write Foo(v1, ..., vk), the compiler infers the types of 13022 // the parameters v1, ..., and vk for you. If you are not happy with 13023 // the result of the type inference, you can specify the types by 13024 // explicitly instantiating the template, as in Foo<long, bool>(5, 13025 // false). As said earlier, you don't get to (or need to) specify 13026 // 'arg_type' as that's determined by the context in which the matcher 13027 // is used. You can assign the result of expression Foo(p1, ..., pk) 13028 // to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This 13029 // can be useful when composing matchers. 13030 // 13031 // While you can instantiate a matcher template with reference types, 13032 // passing the parameters by pointer usually makes your code more 13033 // readable. If, however, you still want to pass a parameter by 13034 // reference, be aware that in the failure message generated by the 13035 // matcher you will see the value of the referenced object but not its 13036 // address. 13037 // 13038 // Explaining Match Results 13039 // ======================== 13040 // 13041 // Sometimes the matcher description alone isn't enough to explain why 13042 // the match has failed or succeeded. For example, when expecting a 13043 // long string, it can be very helpful to also print the diff between 13044 // the expected string and the actual one. To achieve that, you can 13045 // optionally stream additional information to a special variable 13046 // named result_listener, whose type is a pointer to class 13047 // MatchResultListener: 13048 // 13049 // MATCHER_P(EqualsLongString, str, "") { 13050 // if (arg == str) return true; 13051 // 13052 // *result_listener << "the difference: " 13053 /// << DiffStrings(str, arg); 13054 // return false; 13055 // } 13056 // 13057 // Overloading Matchers 13058 // ==================== 13059 // 13060 // You can overload matchers with different numbers of parameters: 13061 // 13062 // MATCHER_P(Blah, a, description_string1) { ... } 13063 // MATCHER_P2(Blah, a, b, description_string2) { ... } 13064 // 13065 // Caveats 13066 // ======= 13067 // 13068 // When defining a new matcher, you should also consider implementing 13069 // MatcherInterface or using MakePolymorphicMatcher(). These 13070 // approaches require more work than the MATCHER* macros, but also 13071 // give you more control on the types of the value being matched and 13072 // the matcher parameters, which may leads to better compiler error 13073 // messages when the matcher is used wrong. They also allow 13074 // overloading matchers based on parameter types (as opposed to just 13075 // based on the number of parameters). 13076 // 13077 // MATCHER*() can only be used in a namespace scope. The reason is 13078 // that C++ doesn't yet allow function-local types to be used to 13079 // instantiate templates. The up-coming C++0x standard will fix this. 13080 // Once that's done, we'll consider supporting using MATCHER*() inside 13081 // a function. 13082 // 13083 // More Information 13084 // ================ 13085 // 13086 // To learn more about using these macros, please search for 'MATCHER' 13087 // on http://code.google.com/p/googlemock/wiki/CookBook. 13088 13089 #define MATCHER(name, description)\ 13090 class name##Matcher {\ 13091 public:\ 13092 template <typename arg_type>\ 13093 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ 13094 public:\ 13095 gmock_Impl()\ 13096 {}\ 13097 virtual bool MatchAndExplain(\ 13098 arg_type arg, ::testing::MatchResultListener* result_listener) const;\ 13099 virtual void DescribeTo(::std::ostream* gmock_os) const {\ 13100 *gmock_os << FormatDescription(false);\ 13101 }\ 13102 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ 13103 *gmock_os << FormatDescription(true);\ 13104 }\ 13105 private:\ 13106 ::testing::internal::string FormatDescription(bool negation) const {\ 13107 const ::testing::internal::string gmock_description = (description);\ 13108 if (!gmock_description.empty())\ 13109 return gmock_description;\ 13110 return ::testing::internal::FormatMatcherDescription(\ 13111 negation, #name, \ 13112 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ 13113 ::std::tr1::tuple<>()));\ 13114 }\ 13115 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 13116 };\ 13117 template <typename arg_type>\ 13118 operator ::testing::Matcher<arg_type>() const {\ 13119 return ::testing::Matcher<arg_type>(\ 13120 new gmock_Impl<arg_type>());\ 13121 }\ 13122 name##Matcher() {\ 13123 }\ 13124 private:\ 13125 GTEST_DISALLOW_ASSIGN_(name##Matcher);\ 13126 };\ 13127 inline name##Matcher name() {\ 13128 return name##Matcher();\ 13129 }\ 13130 template <typename arg_type>\ 13131 bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\ 13132 arg_type arg, \ 13133 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ 13134 const 13135 13136 #define MATCHER_P(name, p0, description)\ 13137 template <typename p0##_type>\ 13138 class name##MatcherP {\ 13139 public:\ 13140 template <typename arg_type>\ 13141 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ 13142 public:\ 13143 explicit gmock_Impl(p0##_type gmock_p0)\ 13144 : p0(gmock_p0) {}\ 13145 virtual bool MatchAndExplain(\ 13146 arg_type arg, ::testing::MatchResultListener* result_listener) const;\ 13147 virtual void DescribeTo(::std::ostream* gmock_os) const {\ 13148 *gmock_os << FormatDescription(false);\ 13149 }\ 13150 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ 13151 *gmock_os << FormatDescription(true);\ 13152 }\ 13153 p0##_type p0;\ 13154 private:\ 13155 ::testing::internal::string FormatDescription(bool negation) const {\ 13156 const ::testing::internal::string gmock_description = (description);\ 13157 if (!gmock_description.empty())\ 13158 return gmock_description;\ 13159 return ::testing::internal::FormatMatcherDescription(\ 13160 negation, #name, \ 13161 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ 13162 ::std::tr1::tuple<p0##_type>(p0)));\ 13163 }\ 13164 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 13165 };\ 13166 template <typename arg_type>\ 13167 operator ::testing::Matcher<arg_type>() const {\ 13168 return ::testing::Matcher<arg_type>(\ 13169 new gmock_Impl<arg_type>(p0));\ 13170 }\ 13171 name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\ 13172 }\ 13173 p0##_type p0;\ 13174 private:\ 13175 GTEST_DISALLOW_ASSIGN_(name##MatcherP);\ 13176 };\ 13177 template <typename p0##_type>\ 13178 inline name##MatcherP<p0##_type> name(p0##_type p0) {\ 13179 return name##MatcherP<p0##_type>(p0);\ 13180 }\ 13181 template <typename p0##_type>\ 13182 template <typename arg_type>\ 13183 bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ 13184 arg_type arg, \ 13185 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ 13186 const 13187 13188 #define MATCHER_P2(name, p0, p1, description)\ 13189 template <typename p0##_type, typename p1##_type>\ 13190 class name##MatcherP2 {\ 13191 public:\ 13192 template <typename arg_type>\ 13193 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ 13194 public:\ 13195 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\ 13196 : p0(gmock_p0), p1(gmock_p1) {}\ 13197 virtual bool MatchAndExplain(\ 13198 arg_type arg, ::testing::MatchResultListener* result_listener) const;\ 13199 virtual void DescribeTo(::std::ostream* gmock_os) const {\ 13200 *gmock_os << FormatDescription(false);\ 13201 }\ 13202 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ 13203 *gmock_os << FormatDescription(true);\ 13204 }\ 13205 p0##_type p0;\ 13206 p1##_type p1;\ 13207 private:\ 13208 ::testing::internal::string FormatDescription(bool negation) const {\ 13209 const ::testing::internal::string gmock_description = (description);\ 13210 if (!gmock_description.empty())\ 13211 return gmock_description;\ 13212 return ::testing::internal::FormatMatcherDescription(\ 13213 negation, #name, \ 13214 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ 13215 ::std::tr1::tuple<p0##_type, p1##_type>(p0, p1)));\ 13216 }\ 13217 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 13218 };\ 13219 template <typename arg_type>\ 13220 operator ::testing::Matcher<arg_type>() const {\ 13221 return ::testing::Matcher<arg_type>(\ 13222 new gmock_Impl<arg_type>(p0, p1));\ 13223 }\ 13224 name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ 13225 p1(gmock_p1) {\ 13226 }\ 13227 p0##_type p0;\ 13228 p1##_type p1;\ 13229 private:\ 13230 GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\ 13231 };\ 13232 template <typename p0##_type, typename p1##_type>\ 13233 inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \ 13234 p1##_type p1) {\ 13235 return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\ 13236 }\ 13237 template <typename p0##_type, typename p1##_type>\ 13238 template <typename arg_type>\ 13239 bool name##MatcherP2<p0##_type, \ 13240 p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ 13241 arg_type arg, \ 13242 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ 13243 const 13244 13245 #define MATCHER_P3(name, p0, p1, p2, description)\ 13246 template <typename p0##_type, typename p1##_type, typename p2##_type>\ 13247 class name##MatcherP3 {\ 13248 public:\ 13249 template <typename arg_type>\ 13250 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ 13251 public:\ 13252 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\ 13253 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ 13254 virtual bool MatchAndExplain(\ 13255 arg_type arg, ::testing::MatchResultListener* result_listener) const;\ 13256 virtual void DescribeTo(::std::ostream* gmock_os) const {\ 13257 *gmock_os << FormatDescription(false);\ 13258 }\ 13259 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ 13260 *gmock_os << FormatDescription(true);\ 13261 }\ 13262 p0##_type p0;\ 13263 p1##_type p1;\ 13264 p2##_type p2;\ 13265 private:\ 13266 ::testing::internal::string FormatDescription(bool negation) const {\ 13267 const ::testing::internal::string gmock_description = (description);\ 13268 if (!gmock_description.empty())\ 13269 return gmock_description;\ 13270 return ::testing::internal::FormatMatcherDescription(\ 13271 negation, #name, \ 13272 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ 13273 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \ 13274 p2)));\ 13275 }\ 13276 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 13277 };\ 13278 template <typename arg_type>\ 13279 operator ::testing::Matcher<arg_type>() const {\ 13280 return ::testing::Matcher<arg_type>(\ 13281 new gmock_Impl<arg_type>(p0, p1, p2));\ 13282 }\ 13283 name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \ 13284 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\ 13285 }\ 13286 p0##_type p0;\ 13287 p1##_type p1;\ 13288 p2##_type p2;\ 13289 private:\ 13290 GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\ 13291 };\ 13292 template <typename p0##_type, typename p1##_type, typename p2##_type>\ 13293 inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \ 13294 p1##_type p1, p2##_type p2) {\ 13295 return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\ 13296 }\ 13297 template <typename p0##_type, typename p1##_type, typename p2##_type>\ 13298 template <typename arg_type>\ 13299 bool name##MatcherP3<p0##_type, p1##_type, \ 13300 p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ 13301 arg_type arg, \ 13302 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ 13303 const 13304 13305 #define MATCHER_P4(name, p0, p1, p2, p3, description)\ 13306 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13307 typename p3##_type>\ 13308 class name##MatcherP4 {\ 13309 public:\ 13310 template <typename arg_type>\ 13311 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ 13312 public:\ 13313 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 13314 p3##_type gmock_p3)\ 13315 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\ 13316 virtual bool MatchAndExplain(\ 13317 arg_type arg, ::testing::MatchResultListener* result_listener) const;\ 13318 virtual void DescribeTo(::std::ostream* gmock_os) const {\ 13319 *gmock_os << FormatDescription(false);\ 13320 }\ 13321 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ 13322 *gmock_os << FormatDescription(true);\ 13323 }\ 13324 p0##_type p0;\ 13325 p1##_type p1;\ 13326 p2##_type p2;\ 13327 p3##_type p3;\ 13328 private:\ 13329 ::testing::internal::string FormatDescription(bool negation) const {\ 13330 const ::testing::internal::string gmock_description = (description);\ 13331 if (!gmock_description.empty())\ 13332 return gmock_description;\ 13333 return ::testing::internal::FormatMatcherDescription(\ 13334 negation, #name, \ 13335 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ 13336 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \ 13337 p3##_type>(p0, p1, p2, p3)));\ 13338 }\ 13339 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 13340 };\ 13341 template <typename arg_type>\ 13342 operator ::testing::Matcher<arg_type>() const {\ 13343 return ::testing::Matcher<arg_type>(\ 13344 new gmock_Impl<arg_type>(p0, p1, p2, p3));\ 13345 }\ 13346 name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \ 13347 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ 13348 p2(gmock_p2), p3(gmock_p3) {\ 13349 }\ 13350 p0##_type p0;\ 13351 p1##_type p1;\ 13352 p2##_type p2;\ 13353 p3##_type p3;\ 13354 private:\ 13355 GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\ 13356 };\ 13357 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13358 typename p3##_type>\ 13359 inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \ 13360 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ 13361 p3##_type p3) {\ 13362 return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \ 13363 p1, p2, p3);\ 13364 }\ 13365 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13366 typename p3##_type>\ 13367 template <typename arg_type>\ 13368 bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \ 13369 p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ 13370 arg_type arg, \ 13371 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ 13372 const 13373 13374 #define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\ 13375 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13376 typename p3##_type, typename p4##_type>\ 13377 class name##MatcherP5 {\ 13378 public:\ 13379 template <typename arg_type>\ 13380 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ 13381 public:\ 13382 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 13383 p3##_type gmock_p3, p4##_type gmock_p4)\ 13384 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ 13385 p4(gmock_p4) {}\ 13386 virtual bool MatchAndExplain(\ 13387 arg_type arg, ::testing::MatchResultListener* result_listener) const;\ 13388 virtual void DescribeTo(::std::ostream* gmock_os) const {\ 13389 *gmock_os << FormatDescription(false);\ 13390 }\ 13391 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ 13392 *gmock_os << FormatDescription(true);\ 13393 }\ 13394 p0##_type p0;\ 13395 p1##_type p1;\ 13396 p2##_type p2;\ 13397 p3##_type p3;\ 13398 p4##_type p4;\ 13399 private:\ 13400 ::testing::internal::string FormatDescription(bool negation) const {\ 13401 const ::testing::internal::string gmock_description = (description);\ 13402 if (!gmock_description.empty())\ 13403 return gmock_description;\ 13404 return ::testing::internal::FormatMatcherDescription(\ 13405 negation, #name, \ 13406 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ 13407 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ 13408 p4##_type>(p0, p1, p2, p3, p4)));\ 13409 }\ 13410 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 13411 };\ 13412 template <typename arg_type>\ 13413 operator ::testing::Matcher<arg_type>() const {\ 13414 return ::testing::Matcher<arg_type>(\ 13415 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4));\ 13416 }\ 13417 name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \ 13418 p2##_type gmock_p2, p3##_type gmock_p3, \ 13419 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 13420 p3(gmock_p3), p4(gmock_p4) {\ 13421 }\ 13422 p0##_type p0;\ 13423 p1##_type p1;\ 13424 p2##_type p2;\ 13425 p3##_type p3;\ 13426 p4##_type p4;\ 13427 private:\ 13428 GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\ 13429 };\ 13430 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13431 typename p3##_type, typename p4##_type>\ 13432 inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \ 13433 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ 13434 p4##_type p4) {\ 13435 return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \ 13436 p4##_type>(p0, p1, p2, p3, p4);\ 13437 }\ 13438 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13439 typename p3##_type, typename p4##_type>\ 13440 template <typename arg_type>\ 13441 bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \ 13442 p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ 13443 arg_type arg, \ 13444 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ 13445 const 13446 13447 #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\ 13448 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13449 typename p3##_type, typename p4##_type, typename p5##_type>\ 13450 class name##MatcherP6 {\ 13451 public:\ 13452 template <typename arg_type>\ 13453 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ 13454 public:\ 13455 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 13456 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\ 13457 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ 13458 p4(gmock_p4), p5(gmock_p5) {}\ 13459 virtual bool MatchAndExplain(\ 13460 arg_type arg, ::testing::MatchResultListener* result_listener) const;\ 13461 virtual void DescribeTo(::std::ostream* gmock_os) const {\ 13462 *gmock_os << FormatDescription(false);\ 13463 }\ 13464 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ 13465 *gmock_os << FormatDescription(true);\ 13466 }\ 13467 p0##_type p0;\ 13468 p1##_type p1;\ 13469 p2##_type p2;\ 13470 p3##_type p3;\ 13471 p4##_type p4;\ 13472 p5##_type p5;\ 13473 private:\ 13474 ::testing::internal::string FormatDescription(bool negation) const {\ 13475 const ::testing::internal::string gmock_description = (description);\ 13476 if (!gmock_description.empty())\ 13477 return gmock_description;\ 13478 return ::testing::internal::FormatMatcherDescription(\ 13479 negation, #name, \ 13480 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ 13481 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ 13482 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\ 13483 }\ 13484 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 13485 };\ 13486 template <typename arg_type>\ 13487 operator ::testing::Matcher<arg_type>() const {\ 13488 return ::testing::Matcher<arg_type>(\ 13489 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5));\ 13490 }\ 13491 name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \ 13492 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ 13493 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 13494 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\ 13495 }\ 13496 p0##_type p0;\ 13497 p1##_type p1;\ 13498 p2##_type p2;\ 13499 p3##_type p3;\ 13500 p4##_type p4;\ 13501 p5##_type p5;\ 13502 private:\ 13503 GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\ 13504 };\ 13505 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13506 typename p3##_type, typename p4##_type, typename p5##_type>\ 13507 inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \ 13508 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ 13509 p3##_type p3, p4##_type p4, p5##_type p5) {\ 13510 return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \ 13511 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\ 13512 }\ 13513 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13514 typename p3##_type, typename p4##_type, typename p5##_type>\ 13515 template <typename arg_type>\ 13516 bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 13517 p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ 13518 arg_type arg, \ 13519 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ 13520 const 13521 13522 #define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\ 13523 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13524 typename p3##_type, typename p4##_type, typename p5##_type, \ 13525 typename p6##_type>\ 13526 class name##MatcherP7 {\ 13527 public:\ 13528 template <typename arg_type>\ 13529 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ 13530 public:\ 13531 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 13532 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 13533 p6##_type gmock_p6)\ 13534 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ 13535 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ 13536 virtual bool MatchAndExplain(\ 13537 arg_type arg, ::testing::MatchResultListener* result_listener) const;\ 13538 virtual void DescribeTo(::std::ostream* gmock_os) const {\ 13539 *gmock_os << FormatDescription(false);\ 13540 }\ 13541 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ 13542 *gmock_os << FormatDescription(true);\ 13543 }\ 13544 p0##_type p0;\ 13545 p1##_type p1;\ 13546 p2##_type p2;\ 13547 p3##_type p3;\ 13548 p4##_type p4;\ 13549 p5##_type p5;\ 13550 p6##_type p6;\ 13551 private:\ 13552 ::testing::internal::string FormatDescription(bool negation) const {\ 13553 const ::testing::internal::string gmock_description = (description);\ 13554 if (!gmock_description.empty())\ 13555 return gmock_description;\ 13556 return ::testing::internal::FormatMatcherDescription(\ 13557 negation, #name, \ 13558 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ 13559 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ 13560 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \ 13561 p6)));\ 13562 }\ 13563 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 13564 };\ 13565 template <typename arg_type>\ 13566 operator ::testing::Matcher<arg_type>() const {\ 13567 return ::testing::Matcher<arg_type>(\ 13568 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6));\ 13569 }\ 13570 name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \ 13571 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ 13572 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \ 13573 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ 13574 p6(gmock_p6) {\ 13575 }\ 13576 p0##_type p0;\ 13577 p1##_type p1;\ 13578 p2##_type p2;\ 13579 p3##_type p3;\ 13580 p4##_type p4;\ 13581 p5##_type p5;\ 13582 p6##_type p6;\ 13583 private:\ 13584 GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\ 13585 };\ 13586 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13587 typename p3##_type, typename p4##_type, typename p5##_type, \ 13588 typename p6##_type>\ 13589 inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \ 13590 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \ 13591 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ 13592 p6##_type p6) {\ 13593 return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \ 13594 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\ 13595 }\ 13596 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13597 typename p3##_type, typename p4##_type, typename p5##_type, \ 13598 typename p6##_type>\ 13599 template <typename arg_type>\ 13600 bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 13601 p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ 13602 arg_type arg, \ 13603 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ 13604 const 13605 13606 #define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\ 13607 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13608 typename p3##_type, typename p4##_type, typename p5##_type, \ 13609 typename p6##_type, typename p7##_type>\ 13610 class name##MatcherP8 {\ 13611 public:\ 13612 template <typename arg_type>\ 13613 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ 13614 public:\ 13615 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 13616 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 13617 p6##_type gmock_p6, p7##_type gmock_p7)\ 13618 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ 13619 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\ 13620 virtual bool MatchAndExplain(\ 13621 arg_type arg, ::testing::MatchResultListener* result_listener) const;\ 13622 virtual void DescribeTo(::std::ostream* gmock_os) const {\ 13623 *gmock_os << FormatDescription(false);\ 13624 }\ 13625 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ 13626 *gmock_os << FormatDescription(true);\ 13627 }\ 13628 p0##_type p0;\ 13629 p1##_type p1;\ 13630 p2##_type p2;\ 13631 p3##_type p3;\ 13632 p4##_type p4;\ 13633 p5##_type p5;\ 13634 p6##_type p6;\ 13635 p7##_type p7;\ 13636 private:\ 13637 ::testing::internal::string FormatDescription(bool negation) const {\ 13638 const ::testing::internal::string gmock_description = (description);\ 13639 if (!gmock_description.empty())\ 13640 return gmock_description;\ 13641 return ::testing::internal::FormatMatcherDescription(\ 13642 negation, #name, \ 13643 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ 13644 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ 13645 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \ 13646 p3, p4, p5, p6, p7)));\ 13647 }\ 13648 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 13649 };\ 13650 template <typename arg_type>\ 13651 operator ::testing::Matcher<arg_type>() const {\ 13652 return ::testing::Matcher<arg_type>(\ 13653 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7));\ 13654 }\ 13655 name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \ 13656 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ 13657 p5##_type gmock_p5, p6##_type gmock_p6, \ 13658 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 13659 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ 13660 p7(gmock_p7) {\ 13661 }\ 13662 p0##_type p0;\ 13663 p1##_type p1;\ 13664 p2##_type p2;\ 13665 p3##_type p3;\ 13666 p4##_type p4;\ 13667 p5##_type p5;\ 13668 p6##_type p6;\ 13669 p7##_type p7;\ 13670 private:\ 13671 GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\ 13672 };\ 13673 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13674 typename p3##_type, typename p4##_type, typename p5##_type, \ 13675 typename p6##_type, typename p7##_type>\ 13676 inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \ 13677 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \ 13678 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ 13679 p6##_type p6, p7##_type p7) {\ 13680 return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \ 13681 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \ 13682 p6, p7);\ 13683 }\ 13684 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13685 typename p3##_type, typename p4##_type, typename p5##_type, \ 13686 typename p6##_type, typename p7##_type>\ 13687 template <typename arg_type>\ 13688 bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 13689 p5##_type, p6##_type, \ 13690 p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ 13691 arg_type arg, \ 13692 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ 13693 const 13694 13695 #define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\ 13696 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13697 typename p3##_type, typename p4##_type, typename p5##_type, \ 13698 typename p6##_type, typename p7##_type, typename p8##_type>\ 13699 class name##MatcherP9 {\ 13700 public:\ 13701 template <typename arg_type>\ 13702 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ 13703 public:\ 13704 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 13705 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 13706 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\ 13707 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ 13708 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ 13709 p8(gmock_p8) {}\ 13710 virtual bool MatchAndExplain(\ 13711 arg_type arg, ::testing::MatchResultListener* result_listener) const;\ 13712 virtual void DescribeTo(::std::ostream* gmock_os) const {\ 13713 *gmock_os << FormatDescription(false);\ 13714 }\ 13715 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ 13716 *gmock_os << FormatDescription(true);\ 13717 }\ 13718 p0##_type p0;\ 13719 p1##_type p1;\ 13720 p2##_type p2;\ 13721 p3##_type p3;\ 13722 p4##_type p4;\ 13723 p5##_type p5;\ 13724 p6##_type p6;\ 13725 p7##_type p7;\ 13726 p8##_type p8;\ 13727 private:\ 13728 ::testing::internal::string FormatDescription(bool negation) const {\ 13729 const ::testing::internal::string gmock_description = (description);\ 13730 if (!gmock_description.empty())\ 13731 return gmock_description;\ 13732 return ::testing::internal::FormatMatcherDescription(\ 13733 negation, #name, \ 13734 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ 13735 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ 13736 p4##_type, p5##_type, p6##_type, p7##_type, \ 13737 p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\ 13738 }\ 13739 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 13740 };\ 13741 template <typename arg_type>\ 13742 operator ::testing::Matcher<arg_type>() const {\ 13743 return ::testing::Matcher<arg_type>(\ 13744 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\ 13745 }\ 13746 name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \ 13747 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ 13748 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ 13749 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ 13750 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ 13751 p8(gmock_p8) {\ 13752 }\ 13753 p0##_type p0;\ 13754 p1##_type p1;\ 13755 p2##_type p2;\ 13756 p3##_type p3;\ 13757 p4##_type p4;\ 13758 p5##_type p5;\ 13759 p6##_type p6;\ 13760 p7##_type p7;\ 13761 p8##_type p8;\ 13762 private:\ 13763 GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\ 13764 };\ 13765 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13766 typename p3##_type, typename p4##_type, typename p5##_type, \ 13767 typename p6##_type, typename p7##_type, typename p8##_type>\ 13768 inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \ 13769 p4##_type, p5##_type, p6##_type, p7##_type, \ 13770 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ 13771 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ 13772 p8##_type p8) {\ 13773 return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \ 13774 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \ 13775 p3, p4, p5, p6, p7, p8);\ 13776 }\ 13777 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13778 typename p3##_type, typename p4##_type, typename p5##_type, \ 13779 typename p6##_type, typename p7##_type, typename p8##_type>\ 13780 template <typename arg_type>\ 13781 bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 13782 p5##_type, p6##_type, p7##_type, \ 13783 p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ 13784 arg_type arg, \ 13785 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ 13786 const 13787 13788 #define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\ 13789 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13790 typename p3##_type, typename p4##_type, typename p5##_type, \ 13791 typename p6##_type, typename p7##_type, typename p8##_type, \ 13792 typename p9##_type>\ 13793 class name##MatcherP10 {\ 13794 public:\ 13795 template <typename arg_type>\ 13796 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ 13797 public:\ 13798 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 13799 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 13800 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ 13801 p9##_type gmock_p9)\ 13802 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ 13803 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ 13804 p8(gmock_p8), p9(gmock_p9) {}\ 13805 virtual bool MatchAndExplain(\ 13806 arg_type arg, ::testing::MatchResultListener* result_listener) const;\ 13807 virtual void DescribeTo(::std::ostream* gmock_os) const {\ 13808 *gmock_os << FormatDescription(false);\ 13809 }\ 13810 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ 13811 *gmock_os << FormatDescription(true);\ 13812 }\ 13813 p0##_type p0;\ 13814 p1##_type p1;\ 13815 p2##_type p2;\ 13816 p3##_type p3;\ 13817 p4##_type p4;\ 13818 p5##_type p5;\ 13819 p6##_type p6;\ 13820 p7##_type p7;\ 13821 p8##_type p8;\ 13822 p9##_type p9;\ 13823 private:\ 13824 ::testing::internal::string FormatDescription(bool negation) const {\ 13825 const ::testing::internal::string gmock_description = (description);\ 13826 if (!gmock_description.empty())\ 13827 return gmock_description;\ 13828 return ::testing::internal::FormatMatcherDescription(\ 13829 negation, #name, \ 13830 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ 13831 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ 13832 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ 13833 p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\ 13834 }\ 13835 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 13836 };\ 13837 template <typename arg_type>\ 13838 operator ::testing::Matcher<arg_type>() const {\ 13839 return ::testing::Matcher<arg_type>(\ 13840 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\ 13841 }\ 13842 name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \ 13843 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ 13844 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ 13845 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \ 13846 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ 13847 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\ 13848 }\ 13849 p0##_type p0;\ 13850 p1##_type p1;\ 13851 p2##_type p2;\ 13852 p3##_type p3;\ 13853 p4##_type p4;\ 13854 p5##_type p5;\ 13855 p6##_type p6;\ 13856 p7##_type p7;\ 13857 p8##_type p8;\ 13858 p9##_type p9;\ 13859 private:\ 13860 GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\ 13861 };\ 13862 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13863 typename p3##_type, typename p4##_type, typename p5##_type, \ 13864 typename p6##_type, typename p7##_type, typename p8##_type, \ 13865 typename p9##_type>\ 13866 inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \ 13867 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ 13868 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ 13869 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ 13870 p9##_type p9) {\ 13871 return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \ 13872 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \ 13873 p1, p2, p3, p4, p5, p6, p7, p8, p9);\ 13874 }\ 13875 template <typename p0##_type, typename p1##_type, typename p2##_type, \ 13876 typename p3##_type, typename p4##_type, typename p5##_type, \ 13877 typename p6##_type, typename p7##_type, typename p8##_type, \ 13878 typename p9##_type>\ 13879 template <typename arg_type>\ 13880 bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \ 13881 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ 13882 p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ 13883 arg_type arg, \ 13884 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ 13885 const 13886 13887 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ 13888 // Copyright 2007, Google Inc. 13889 // All rights reserved. 13890 // 13891 // Redistribution and use in source and binary forms, with or without 13892 // modification, are permitted provided that the following conditions are 13893 // met: 13894 // 13895 // * Redistributions of source code must retain the above copyright 13896 // notice, this list of conditions and the following disclaimer. 13897 // * Redistributions in binary form must reproduce the above 13898 // copyright notice, this list of conditions and the following disclaimer 13899 // in the documentation and/or other materials provided with the 13900 // distribution. 13901 // * Neither the name of Google Inc. nor the names of its 13902 // contributors may be used to endorse or promote products derived from 13903 // this software without specific prior written permission. 13904 // 13905 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 13906 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 13907 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 13908 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 13909 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 13910 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 13911 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13912 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13913 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 13914 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 13915 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13916 // 13917 // Author: wan@google.com (Zhanyong Wan) 13918 13919 // Google Mock - a framework for writing C++ mock classes. 13920 // 13921 // This file implements some actions that depend on gmock-generated-actions.h. 13922 13923 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ 13924 #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ 13925 13926 #include <algorithm> 13927 13928 13929 namespace testing { 13930 namespace internal { 13931 13932 // Implements the Invoke(f) action. The template argument 13933 // FunctionImpl is the implementation type of f, which can be either a 13934 // function pointer or a functor. Invoke(f) can be used as an 13935 // Action<F> as long as f's type is compatible with F (i.e. f can be 13936 // assigned to a tr1::function<F>). 13937 template <typename FunctionImpl> 13938 class InvokeAction { 13939 public: 13940 // The c'tor makes a copy of function_impl (either a function 13941 // pointer or a functor). 13942 explicit InvokeAction(FunctionImpl function_impl) 13943 : function_impl_(function_impl) {} 13944 13945 template <typename Result, typename ArgumentTuple> 13946 Result Perform(const ArgumentTuple& args) { 13947 return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args); 13948 } 13949 13950 private: 13951 FunctionImpl function_impl_; 13952 13953 GTEST_DISALLOW_ASSIGN_(InvokeAction); 13954 }; 13955 13956 // Implements the Invoke(object_ptr, &Class::Method) action. 13957 template <class Class, typename MethodPtr> 13958 class InvokeMethodAction { 13959 public: 13960 InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr) 13961 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} 13962 13963 template <typename Result, typename ArgumentTuple> 13964 Result Perform(const ArgumentTuple& args) const { 13965 return InvokeHelper<Result, ArgumentTuple>::InvokeMethod( 13966 obj_ptr_, method_ptr_, args); 13967 } 13968 13969 private: 13970 Class* const obj_ptr_; 13971 const MethodPtr method_ptr_; 13972 13973 GTEST_DISALLOW_ASSIGN_(InvokeMethodAction); 13974 }; 13975 13976 } // namespace internal 13977 13978 // Various overloads for Invoke(). 13979 13980 // Creates an action that invokes 'function_impl' with the mock 13981 // function's arguments. 13982 template <typename FunctionImpl> 13983 PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke( 13984 FunctionImpl function_impl) { 13985 return MakePolymorphicAction( 13986 internal::InvokeAction<FunctionImpl>(function_impl)); 13987 } 13988 13989 // Creates an action that invokes the given method on the given object 13990 // with the mock function's arguments. 13991 template <class Class, typename MethodPtr> 13992 PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke( 13993 Class* obj_ptr, MethodPtr method_ptr) { 13994 return MakePolymorphicAction( 13995 internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr)); 13996 } 13997 13998 // WithoutArgs(inner_action) can be used in a mock function with a 13999 // non-empty argument list to perform inner_action, which takes no 14000 // argument. In other words, it adapts an action accepting no 14001 // argument to one that accepts (and ignores) arguments. 14002 template <typename InnerAction> 14003 inline internal::WithArgsAction<InnerAction> 14004 WithoutArgs(const InnerAction& action) { 14005 return internal::WithArgsAction<InnerAction>(action); 14006 } 14007 14008 // WithArg<k>(an_action) creates an action that passes the k-th 14009 // (0-based) argument of the mock function to an_action and performs 14010 // it. It adapts an action accepting one argument to one that accepts 14011 // multiple arguments. For convenience, we also provide 14012 // WithArgs<k>(an_action) (defined below) as a synonym. 14013 template <int k, typename InnerAction> 14014 inline internal::WithArgsAction<InnerAction, k> 14015 WithArg(const InnerAction& action) { 14016 return internal::WithArgsAction<InnerAction, k>(action); 14017 } 14018 14019 // The ACTION*() macros trigger warning C4100 (unreferenced formal 14020 // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in 14021 // the macro definition, as the warnings are generated when the macro 14022 // is expanded and macro expansion cannot contain #pragma. Therefore 14023 // we suppress them here. 14024 #ifdef _MSC_VER 14025 # pragma warning(push) 14026 # pragma warning(disable:4100) 14027 #endif 14028 14029 // Action ReturnArg<k>() returns the k-th argument of the mock function. 14030 ACTION_TEMPLATE(ReturnArg, 14031 HAS_1_TEMPLATE_PARAMS(int, k), 14032 AND_0_VALUE_PARAMS()) { 14033 return std::tr1::get<k>(args); 14034 } 14035 14036 // Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the 14037 // mock function to *pointer. 14038 ACTION_TEMPLATE(SaveArg, 14039 HAS_1_TEMPLATE_PARAMS(int, k), 14040 AND_1_VALUE_PARAMS(pointer)) { 14041 *pointer = ::std::tr1::get<k>(args); 14042 } 14043 14044 // Action SaveArgPointee<k>(pointer) saves the value pointed to 14045 // by the k-th (0-based) argument of the mock function to *pointer. 14046 ACTION_TEMPLATE(SaveArgPointee, 14047 HAS_1_TEMPLATE_PARAMS(int, k), 14048 AND_1_VALUE_PARAMS(pointer)) { 14049 *pointer = *::std::tr1::get<k>(args); 14050 } 14051 14052 // Action SetArgReferee<k>(value) assigns 'value' to the variable 14053 // referenced by the k-th (0-based) argument of the mock function. 14054 ACTION_TEMPLATE(SetArgReferee, 14055 HAS_1_TEMPLATE_PARAMS(int, k), 14056 AND_1_VALUE_PARAMS(value)) { 14057 typedef typename ::std::tr1::tuple_element<k, args_type>::type argk_type; 14058 // Ensures that argument #k is a reference. If you get a compiler 14059 // error on the next line, you are using SetArgReferee<k>(value) in 14060 // a mock function whose k-th (0-based) argument is not a reference. 14061 GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value, 14062 SetArgReferee_must_be_used_with_a_reference_argument); 14063 ::std::tr1::get<k>(args) = value; 14064 } 14065 14066 // Action SetArrayArgument<k>(first, last) copies the elements in 14067 // source range [first, last) to the array pointed to by the k-th 14068 // (0-based) argument, which can be either a pointer or an 14069 // iterator. The action does not take ownership of the elements in the 14070 // source range. 14071 ACTION_TEMPLATE(SetArrayArgument, 14072 HAS_1_TEMPLATE_PARAMS(int, k), 14073 AND_2_VALUE_PARAMS(first, last)) { 14074 // Microsoft compiler deprecates ::std::copy, so we want to suppress warning 14075 // 4996 (Function call with parameters that may be unsafe) there. 14076 #ifdef _MSC_VER 14077 # pragma warning(push) // Saves the current warning state. 14078 # pragma warning(disable:4996) // Temporarily disables warning 4996. 14079 #endif 14080 ::std::copy(first, last, ::std::tr1::get<k>(args)); 14081 #ifdef _MSC_VER 14082 # pragma warning(pop) // Restores the warning state. 14083 #endif 14084 } 14085 14086 // Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock 14087 // function. 14088 ACTION_TEMPLATE(DeleteArg, 14089 HAS_1_TEMPLATE_PARAMS(int, k), 14090 AND_0_VALUE_PARAMS()) { 14091 delete ::std::tr1::get<k>(args); 14092 } 14093 14094 // This action returns the value pointed to by 'pointer'. 14095 ACTION_P(ReturnPointee, pointer) { return *pointer; } 14096 14097 // Action Throw(exception) can be used in a mock function of any type 14098 // to throw the given exception. Any copyable value can be thrown. 14099 #if GTEST_HAS_EXCEPTIONS 14100 14101 // Suppresses the 'unreachable code' warning that VC generates in opt modes. 14102 # ifdef _MSC_VER 14103 # pragma warning(push) // Saves the current warning state. 14104 # pragma warning(disable:4702) // Temporarily disables warning 4702. 14105 # endif 14106 ACTION_P(Throw, exception) { throw exception; } 14107 # ifdef _MSC_VER 14108 # pragma warning(pop) // Restores the warning state. 14109 # endif 14110 14111 #endif // GTEST_HAS_EXCEPTIONS 14112 14113 #ifdef _MSC_VER 14114 # pragma warning(pop) 14115 #endif 14116 14117 } // namespace testing 14118 14119 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ 14120 // Copyright 2013, Google Inc. 14121 // All rights reserved. 14122 // 14123 // Redistribution and use in source and binary forms, with or without 14124 // modification, are permitted provided that the following conditions are 14125 // met: 14126 // 14127 // * Redistributions of source code must retain the above copyright 14128 // notice, this list of conditions and the following disclaimer. 14129 // * Redistributions in binary form must reproduce the above 14130 // copyright notice, this list of conditions and the following disclaimer 14131 // in the documentation and/or other materials provided with the 14132 // distribution. 14133 // * Neither the name of Google Inc. nor the names of its 14134 // contributors may be used to endorse or promote products derived from 14135 // this software without specific prior written permission. 14136 // 14137 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 14138 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 14139 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 14140 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 14141 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 14142 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 14143 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 14144 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14145 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14146 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 14147 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14148 // 14149 // Author: marcus.boerger@google.com (Marcus Boerger) 14150 14151 // Google Mock - a framework for writing C++ mock classes. 14152 // 14153 // This file implements some matchers that depend on gmock-generated-matchers.h. 14154 // 14155 // Note that tests are implemented in gmock-matchers_test.cc rather than 14156 // gmock-more-matchers-test.cc. 14157 14158 #ifndef GMOCK_GMOCK_MORE_MATCHERS_H_ 14159 #define GMOCK_GMOCK_MORE_MATCHERS_H_ 14160 14161 14162 namespace testing { 14163 14164 // Defines a matcher that matches an empty container. The container must 14165 // support both size() and empty(), which all STL-like containers provide. 14166 MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { 14167 if (arg.empty()) { 14168 return true; 14169 } 14170 *result_listener << "whose size is " << arg.size(); 14171 return false; 14172 } 14173 14174 } // namespace testing 14175 14176 #endif // GMOCK_GMOCK_MORE_MATCHERS_H_ 14177 14178 namespace testing { 14179 14180 // Declares Google Mock flags that we want a user to use programmatically. 14181 GMOCK_DECLARE_bool_(catch_leaked_mocks); 14182 GMOCK_DECLARE_string_(verbose); 14183 14184 // Initializes Google Mock. This must be called before running the 14185 // tests. In particular, it parses the command line for the flags 14186 // that Google Mock recognizes. Whenever a Google Mock flag is seen, 14187 // it is removed from argv, and *argc is decremented. 14188 // 14189 // No value is returned. Instead, the Google Mock flag variables are 14190 // updated. 14191 // 14192 // Since Google Test is needed for Google Mock to work, this function 14193 // also initializes Google Test and parses its flags, if that hasn't 14194 // been done. 14195 GTEST_API_ void InitGoogleMock(int* argc, char** argv); 14196 14197 // This overloaded version can be used in Windows programs compiled in 14198 // UNICODE mode. 14199 GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv); 14200 14201 } // namespace testing 14202 14203 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_ 14204