Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 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 | // This file implements the following syntax: |
| 40 | // |
| 41 | // ON_CALL(mock_object.Method(...)) |
| 42 | // .With(...) ? |
| 43 | // .WillByDefault(...); |
| 44 | // |
| 45 | // where With() is optional and WillByDefault() must appear exactly |
| 46 | // once. |
| 47 | // |
| 48 | // EXPECT_CALL(mock_object.Method(...)) |
| 49 | // .With(...) ? |
| 50 | // .Times(...) ? |
| 51 | // .InSequence(...) * |
| 52 | // .WillOnce(...) * |
| 53 | // .WillRepeatedly(...) ? |
| 54 | // .RetiresOnSaturation() ? ; |
| 55 | // |
| 56 | // where all clauses are optional and WillOnce() can be repeated. |
| 57 | |
| 58 | // Copyright 2007, Google Inc. |
| 59 | // All rights reserved. |
| 60 | // |
| 61 | // Redistribution and use in source and binary forms, with or without |
| 62 | // modification, are permitted provided that the following conditions are |
| 63 | // met: |
| 64 | // |
| 65 | // * Redistributions of source code must retain the above copyright |
| 66 | // notice, this list of conditions and the following disclaimer. |
| 67 | // * Redistributions in binary form must reproduce the above |
| 68 | // copyright notice, this list of conditions and the following disclaimer |
| 69 | // in the documentation and/or other materials provided with the |
| 70 | // distribution. |
| 71 | // * Neither the name of Google Inc. nor the names of its |
| 72 | // contributors may be used to endorse or promote products derived from |
| 73 | // this software without specific prior written permission. |
| 74 | // |
| 75 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 76 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 77 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 78 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 79 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 80 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 81 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 82 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 83 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 84 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 85 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 86 | // |
| 87 | // Author: wan@google.com (Zhanyong Wan) |
| 88 | |
| 89 | // Google Mock - a framework for writing C++ mock classes. |
| 90 | // |
| 91 | // This file implements some commonly used actions. |
| 92 | |
| 93 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ |
| 94 | #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ |
| 95 | |
| 96 | #include <algorithm> |
| 97 | #include <string> |
| 98 | |
| 99 | #ifndef _WIN32_WCE |
| 100 | # include <errno.h> |
| 101 | #endif |
| 102 | |
| 103 | // Copyright 2007, Google Inc. |
| 104 | // All rights reserved. |
| 105 | // |
| 106 | // Redistribution and use in source and binary forms, with or without |
| 107 | // modification, are permitted provided that the following conditions are |
| 108 | // met: |
| 109 | // |
| 110 | // * Redistributions of source code must retain the above copyright |
| 111 | // notice, this list of conditions and the following disclaimer. |
| 112 | // * Redistributions in binary form must reproduce the above |
| 113 | // copyright notice, this list of conditions and the following disclaimer |
| 114 | // in the documentation and/or other materials provided with the |
| 115 | // distribution. |
| 116 | // * Neither the name of Google Inc. nor the names of its |
| 117 | // contributors may be used to endorse or promote products derived from |
| 118 | // this software without specific prior written permission. |
| 119 | // |
| 120 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 121 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 122 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 123 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 124 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 125 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 126 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 127 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 128 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 129 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 130 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 131 | // |
| 132 | // Author: wan@google.com (Zhanyong Wan) |
| 133 | |
| 134 | // Google Mock - a framework for writing C++ mock classes. |
| 135 | // |
| 136 | // This file defines some utilities useful for implementing Google |
| 137 | // Mock. They are subject to change without notice, so please DO NOT |
| 138 | // USE THEM IN USER CODE. |
| 139 | |
| 140 | #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ |
| 141 | #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ |
| 142 | |
| 143 | #include <stdio.h> |
| 144 | #include <ostream> // NOLINT |
| 145 | #include <string> |
| 146 | |
| 147 | // This file was GENERATED by a script. DO NOT EDIT BY HAND!!! |
| 148 | |
| 149 | // Copyright 2007, Google Inc. |
| 150 | // All rights reserved. |
| 151 | // |
| 152 | // Redistribution and use in source and binary forms, with or without |
| 153 | // modification, are permitted provided that the following conditions are |
| 154 | // met: |
| 155 | // |
| 156 | // * Redistributions of source code must retain the above copyright |
| 157 | // notice, this list of conditions and the following disclaimer. |
| 158 | // * Redistributions in binary form must reproduce the above |
| 159 | // copyright notice, this list of conditions and the following disclaimer |
| 160 | // in the documentation and/or other materials provided with the |
| 161 | // distribution. |
| 162 | // * Neither the name of Google Inc. nor the names of its |
| 163 | // contributors may be used to endorse or promote products derived from |
| 164 | // this software without specific prior written permission. |
| 165 | // |
| 166 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 167 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 168 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 169 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 170 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 171 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 172 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 173 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 174 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 175 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 176 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 177 | // |
| 178 | // Author: wan@google.com (Zhanyong Wan) |
| 179 | |
| 180 | // Google Mock - a framework for writing C++ mock classes. |
| 181 | // |
| 182 | // This file contains template meta-programming utility classes needed |
| 183 | // for implementing Google Mock. |
| 184 | |
| 185 | #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ |
| 186 | #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ |
| 187 | |
| 188 | // Copyright 2008, Google Inc. |
| 189 | // All rights reserved. |
| 190 | // |
| 191 | // Redistribution and use in source and binary forms, with or without |
| 192 | // modification, are permitted provided that the following conditions are |
| 193 | // met: |
| 194 | // |
| 195 | // * Redistributions of source code must retain the above copyright |
| 196 | // notice, this list of conditions and the following disclaimer. |
| 197 | // * Redistributions in binary form must reproduce the above |
| 198 | // copyright notice, this list of conditions and the following disclaimer |
| 199 | // in the documentation and/or other materials provided with the |
| 200 | // distribution. |
| 201 | // * Neither the name of Google Inc. nor the names of its |
| 202 | // contributors may be used to endorse or promote products derived from |
| 203 | // this software without specific prior written permission. |
| 204 | // |
| 205 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 206 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 207 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 208 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 209 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 210 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 211 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 212 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 213 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 214 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 215 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 216 | // |
| 217 | // Author: vadimb@google.com (Vadim Berman) |
| 218 | // |
| 219 | // Low-level types and utilities for porting Google Mock to various |
| 220 | // platforms. They are subject to change without notice. DO NOT USE |
| 221 | // THEM IN USER CODE. |
| 222 | |
| 223 | #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ |
| 224 | #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ |
| 225 | |
| 226 | #include <assert.h> |
| 227 | #include <stdlib.h> |
| 228 | #include <iostream> |
| 229 | |
| 230 | // Most of the types needed for porting Google Mock are also required |
| 231 | // for Google Test and are defined in gtest-port.h. |
| 232 | #include "gtest/gtest.h" |
| 233 | |
| 234 | // To avoid conditional compilation everywhere, we make it |
| 235 | // gmock-port.h's responsibility to #include the header implementing |
| 236 | // tr1/tuple. gmock-port.h does this via gtest-port.h, which is |
| 237 | // guaranteed to pull in the tuple header. |
| 238 | |
| 239 | // For MS Visual C++, check the compiler version. At least VS 2003 is |
| 240 | // required to compile Google Mock. |
| 241 | #if defined(_MSC_VER) && _MSC_VER < 1310 |
| 242 | # error "At least Visual C++ 2003 (7.1) is required to compile Google Mock." |
| 243 | #endif |
| 244 | |
| 245 | // Macro for referencing flags. This is public as we want the user to |
| 246 | // use this syntax to reference Google Mock flags. |
| 247 | #define GMOCK_FLAG(name) FLAGS_gmock_##name |
| 248 | |
| 249 | // Macros for declaring flags. |
| 250 | #define GMOCK_DECLARE_bool_(name) extern bool GMOCK_FLAG(name) |
| 251 | #define GMOCK_DECLARE_int32_(name) \ |
| 252 | extern ::testing::internal::Int32 GMOCK_FLAG(name) |
| 253 | #define GMOCK_DECLARE_string_(name) \ |
| 254 | extern ::testing::internal::String GMOCK_FLAG(name) |
| 255 | |
| 256 | // Macros for defining flags. |
| 257 | #define GMOCK_DEFINE_bool_(name, default_val, doc) \ |
| 258 | bool GMOCK_FLAG(name) = (default_val) |
| 259 | #define GMOCK_DEFINE_int32_(name, default_val, doc) \ |
| 260 | ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val) |
| 261 | #define GMOCK_DEFINE_string_(name, default_val, doc) \ |
| 262 | ::testing::internal::String GMOCK_FLAG(name) = (default_val) |
| 263 | |
| 264 | #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ |
| 265 | |
| 266 | namespace testing { |
| 267 | |
| 268 | template <typename T> |
| 269 | class Matcher; |
| 270 | |
| 271 | namespace internal { |
| 272 | |
| 273 | // An IgnoredValue object can be implicitly constructed from ANY value. |
| 274 | // This is used in implementing the IgnoreResult(a) action. |
| 275 | class IgnoredValue { |
| 276 | public: |
| 277 | // This constructor template allows any value to be implicitly |
| 278 | // converted to IgnoredValue. The object has no data member and |
| 279 | // doesn't try to remember anything about the argument. We |
| 280 | // deliberately omit the 'explicit' keyword in order to allow the |
| 281 | // conversion to be implicit. |
| 282 | template <typename T> |
| 283 | IgnoredValue(const T&) {} |
| 284 | }; |
| 285 | |
| 286 | // MatcherTuple<T>::type is a tuple type where each field is a Matcher |
| 287 | // for the corresponding field in tuple type T. |
| 288 | template <typename Tuple> |
| 289 | struct MatcherTuple; |
| 290 | |
| 291 | template <> |
| 292 | struct MatcherTuple< ::std::tr1::tuple<> > { |
| 293 | typedef ::std::tr1::tuple< > type; |
| 294 | }; |
| 295 | |
| 296 | template <typename A1> |
| 297 | struct MatcherTuple< ::std::tr1::tuple<A1> > { |
| 298 | typedef ::std::tr1::tuple<Matcher<A1> > type; |
| 299 | }; |
| 300 | |
| 301 | template <typename A1, typename A2> |
| 302 | struct MatcherTuple< ::std::tr1::tuple<A1, A2> > { |
| 303 | typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2> > type; |
| 304 | }; |
| 305 | |
| 306 | template <typename A1, typename A2, typename A3> |
| 307 | struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3> > { |
| 308 | typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3> > type; |
| 309 | }; |
| 310 | |
| 311 | template <typename A1, typename A2, typename A3, typename A4> |
| 312 | struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4> > { |
| 313 | typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, |
| 314 | Matcher<A4> > type; |
| 315 | }; |
| 316 | |
| 317 | template <typename A1, typename A2, typename A3, typename A4, typename A5> |
| 318 | struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5> > { |
| 319 | typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, |
| 320 | Matcher<A5> > type; |
| 321 | }; |
| 322 | |
| 323 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 324 | typename A6> |
| 325 | struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > { |
| 326 | typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, |
| 327 | Matcher<A5>, Matcher<A6> > type; |
| 328 | }; |
| 329 | |
| 330 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 331 | typename A6, typename A7> |
| 332 | struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > { |
| 333 | typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, |
| 334 | Matcher<A5>, Matcher<A6>, Matcher<A7> > type; |
| 335 | }; |
| 336 | |
| 337 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 338 | typename A6, typename A7, typename A8> |
| 339 | struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > { |
| 340 | typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, |
| 341 | Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8> > type; |
| 342 | }; |
| 343 | |
| 344 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 345 | typename A6, typename A7, typename A8, typename A9> |
| 346 | struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > { |
| 347 | typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, |
| 348 | Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9> > type; |
| 349 | }; |
| 350 | |
| 351 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 352 | typename A6, typename A7, typename A8, typename A9, typename A10> |
| 353 | struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, |
| 354 | A10> > { |
| 355 | typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, |
| 356 | Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9>, |
| 357 | Matcher<A10> > type; |
| 358 | }; |
| 359 | |
| 360 | // Template struct Function<F>, where F must be a function type, contains |
| 361 | // the following typedefs: |
| 362 | // |
| 363 | // Result: the function's return type. |
| 364 | // ArgumentN: the type of the N-th argument, where N starts with 1. |
| 365 | // ArgumentTuple: the tuple type consisting of all parameters of F. |
| 366 | // ArgumentMatcherTuple: the tuple type consisting of Matchers for all |
| 367 | // parameters of F. |
| 368 | // MakeResultVoid: the function type obtained by substituting void |
| 369 | // for the return type of F. |
| 370 | // MakeResultIgnoredValue: |
| 371 | // the function type obtained by substituting Something |
| 372 | // for the return type of F. |
| 373 | template <typename F> |
| 374 | struct Function; |
| 375 | |
| 376 | template <typename R> |
| 377 | struct Function<R()> { |
| 378 | typedef R Result; |
| 379 | typedef ::std::tr1::tuple<> ArgumentTuple; |
| 380 | typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; |
| 381 | typedef void MakeResultVoid(); |
| 382 | typedef IgnoredValue MakeResultIgnoredValue(); |
| 383 | }; |
| 384 | |
| 385 | template <typename R, typename A1> |
| 386 | struct Function<R(A1)> |
| 387 | : Function<R()> { |
| 388 | typedef A1 Argument1; |
| 389 | typedef ::std::tr1::tuple<A1> ArgumentTuple; |
| 390 | typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; |
| 391 | typedef void MakeResultVoid(A1); |
| 392 | typedef IgnoredValue MakeResultIgnoredValue(A1); |
| 393 | }; |
| 394 | |
| 395 | template <typename R, typename A1, typename A2> |
| 396 | struct Function<R(A1, A2)> |
| 397 | : Function<R(A1)> { |
| 398 | typedef A2 Argument2; |
| 399 | typedef ::std::tr1::tuple<A1, A2> ArgumentTuple; |
| 400 | typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; |
| 401 | typedef void MakeResultVoid(A1, A2); |
| 402 | typedef IgnoredValue MakeResultIgnoredValue(A1, A2); |
| 403 | }; |
| 404 | |
| 405 | template <typename R, typename A1, typename A2, typename A3> |
| 406 | struct Function<R(A1, A2, A3)> |
| 407 | : Function<R(A1, A2)> { |
| 408 | typedef A3 Argument3; |
| 409 | typedef ::std::tr1::tuple<A1, A2, A3> ArgumentTuple; |
| 410 | typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; |
| 411 | typedef void MakeResultVoid(A1, A2, A3); |
| 412 | typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3); |
| 413 | }; |
| 414 | |
| 415 | template <typename R, typename A1, typename A2, typename A3, typename A4> |
| 416 | struct Function<R(A1, A2, A3, A4)> |
| 417 | : Function<R(A1, A2, A3)> { |
| 418 | typedef A4 Argument4; |
| 419 | typedef ::std::tr1::tuple<A1, A2, A3, A4> ArgumentTuple; |
| 420 | typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; |
| 421 | typedef void MakeResultVoid(A1, A2, A3, A4); |
| 422 | typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4); |
| 423 | }; |
| 424 | |
| 425 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 426 | typename A5> |
| 427 | struct Function<R(A1, A2, A3, A4, A5)> |
| 428 | : Function<R(A1, A2, A3, A4)> { |
| 429 | typedef A5 Argument5; |
| 430 | typedef ::std::tr1::tuple<A1, A2, A3, A4, A5> ArgumentTuple; |
| 431 | typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; |
| 432 | typedef void MakeResultVoid(A1, A2, A3, A4, A5); |
| 433 | typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5); |
| 434 | }; |
| 435 | |
| 436 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 437 | typename A5, typename A6> |
| 438 | struct Function<R(A1, A2, A3, A4, A5, A6)> |
| 439 | : Function<R(A1, A2, A3, A4, A5)> { |
| 440 | typedef A6 Argument6; |
| 441 | typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> ArgumentTuple; |
| 442 | typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; |
| 443 | typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6); |
| 444 | typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6); |
| 445 | }; |
| 446 | |
| 447 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 448 | typename A5, typename A6, typename A7> |
| 449 | struct Function<R(A1, A2, A3, A4, A5, A6, A7)> |
| 450 | : Function<R(A1, A2, A3, A4, A5, A6)> { |
| 451 | typedef A7 Argument7; |
| 452 | typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> ArgumentTuple; |
| 453 | typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; |
| 454 | typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7); |
| 455 | typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7); |
| 456 | }; |
| 457 | |
| 458 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 459 | typename A5, typename A6, typename A7, typename A8> |
| 460 | struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> |
| 461 | : Function<R(A1, A2, A3, A4, A5, A6, A7)> { |
| 462 | typedef A8 Argument8; |
| 463 | typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> ArgumentTuple; |
| 464 | typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; |
| 465 | typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8); |
| 466 | typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8); |
| 467 | }; |
| 468 | |
| 469 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 470 | typename A5, typename A6, typename A7, typename A8, typename A9> |
| 471 | struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> |
| 472 | : Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> { |
| 473 | typedef A9 Argument9; |
| 474 | typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> ArgumentTuple; |
| 475 | typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; |
| 476 | typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9); |
| 477 | typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8, |
| 478 | A9); |
| 479 | }; |
| 480 | |
| 481 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 482 | typename A5, typename A6, typename A7, typename A8, typename A9, |
| 483 | typename A10> |
| 484 | struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> |
| 485 | : Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> { |
| 486 | typedef A10 Argument10; |
| 487 | typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, |
| 488 | A10> ArgumentTuple; |
| 489 | typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; |
| 490 | typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); |
| 491 | typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8, |
| 492 | A9, A10); |
| 493 | }; |
| 494 | |
| 495 | } // namespace internal |
| 496 | |
| 497 | } // namespace testing |
| 498 | |
| 499 | #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ |
| 500 | |
| 501 | namespace testing { |
| 502 | namespace internal { |
| 503 | |
| 504 | // Converts an identifier name to a space-separated list of lower-case |
| 505 | // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is |
| 506 | // treated as one word. For example, both "FooBar123" and |
| 507 | // "foo_bar_123" are converted to "foo bar 123". |
| 508 | string ConvertIdentifierNameToWords(const char* id_name); |
| 509 | |
| 510 | // PointeeOf<Pointer>::type is the type of a value pointed to by a |
| 511 | // Pointer, which can be either a smart pointer or a raw pointer. The |
| 512 | // following default implementation is for the case where Pointer is a |
| 513 | // smart pointer. |
| 514 | template <typename Pointer> |
| 515 | struct PointeeOf { |
| 516 | // Smart pointer classes define type element_type as the type of |
| 517 | // their pointees. |
| 518 | typedef typename Pointer::element_type type; |
| 519 | }; |
| 520 | // This specialization is for the raw pointer case. |
| 521 | template <typename T> |
| 522 | struct PointeeOf<T*> { typedef T type; }; // NOLINT |
| 523 | |
| 524 | // GetRawPointer(p) returns the raw pointer underlying p when p is a |
| 525 | // smart pointer, or returns p itself when p is already a raw pointer. |
| 526 | // The following default implementation is for the smart pointer case. |
| 527 | template <typename Pointer> |
| 528 | inline typename Pointer::element_type* GetRawPointer(const Pointer& p) { |
| 529 | return p.get(); |
| 530 | } |
| 531 | // This overloaded version is for the raw pointer case. |
| 532 | template <typename Element> |
| 533 | inline Element* GetRawPointer(Element* p) { return p; } |
| 534 | |
| 535 | // This comparator allows linked_ptr to be stored in sets. |
| 536 | template <typename T> |
| 537 | struct LinkedPtrLessThan { |
| 538 | bool operator()(const ::testing::internal::linked_ptr<T>& lhs, |
| 539 | const ::testing::internal::linked_ptr<T>& rhs) const { |
| 540 | return lhs.get() < rhs.get(); |
| 541 | } |
| 542 | }; |
| 543 | |
| 544 | // Symbian compilation can be done with wchar_t being either a native |
| 545 | // type or a typedef. Using Google Mock with OpenC without wchar_t |
| 546 | // should require the definition of _STLP_NO_WCHAR_T. |
| 547 | // |
| 548 | // MSVC treats wchar_t as a native type usually, but treats it as the |
| 549 | // same as unsigned short when the compiler option /Zc:wchar_t- is |
| 550 | // specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t |
| 551 | // is a native type. |
| 552 | #if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \ |
| 553 | (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)) |
| 554 | // wchar_t is a typedef. |
| 555 | #else |
| 556 | # define GMOCK_WCHAR_T_IS_NATIVE_ 1 |
| 557 | #endif |
| 558 | |
| 559 | // signed wchar_t and unsigned wchar_t are NOT in the C++ standard. |
| 560 | // Using them is a bad practice and not portable. So DON'T use them. |
| 561 | // |
| 562 | // Still, Google Mock is designed to work even if the user uses signed |
| 563 | // wchar_t or unsigned wchar_t (obviously, assuming the compiler |
| 564 | // supports them). |
| 565 | // |
| 566 | // To gcc, |
| 567 | // wchar_t == signed wchar_t != unsigned wchar_t == unsigned int |
| 568 | #ifdef __GNUC__ |
| 569 | // signed/unsigned wchar_t are valid types. |
| 570 | # define GMOCK_HAS_SIGNED_WCHAR_T_ 1 |
| 571 | #endif |
| 572 | |
| 573 | // In what follows, we use the term "kind" to indicate whether a type |
| 574 | // is bool, an integer type (excluding bool), a floating-point type, |
| 575 | // or none of them. This categorization is useful for determining |
| 576 | // when a matcher argument type can be safely converted to another |
| 577 | // type in the implementation of SafeMatcherCast. |
| 578 | enum TypeKind { |
| 579 | kBool, kInteger, kFloatingPoint, kOther |
| 580 | }; |
| 581 | |
| 582 | // KindOf<T>::value is the kind of type T. |
| 583 | template <typename T> struct KindOf { |
| 584 | enum { value = kOther }; // The default kind. |
| 585 | }; |
| 586 | |
| 587 | // This macro declares that the kind of 'type' is 'kind'. |
| 588 | #define GMOCK_DECLARE_KIND_(type, kind) \ |
| 589 | template <> struct KindOf<type> { enum { value = kind }; } |
| 590 | |
| 591 | GMOCK_DECLARE_KIND_(bool, kBool); |
| 592 | |
| 593 | // All standard integer types. |
| 594 | GMOCK_DECLARE_KIND_(char, kInteger); |
| 595 | GMOCK_DECLARE_KIND_(signed char, kInteger); |
| 596 | GMOCK_DECLARE_KIND_(unsigned char, kInteger); |
| 597 | GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT |
| 598 | GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT |
| 599 | GMOCK_DECLARE_KIND_(int, kInteger); |
| 600 | GMOCK_DECLARE_KIND_(unsigned int, kInteger); |
| 601 | GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT |
| 602 | GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT |
| 603 | |
| 604 | #if GMOCK_WCHAR_T_IS_NATIVE_ |
| 605 | GMOCK_DECLARE_KIND_(wchar_t, kInteger); |
| 606 | #endif |
| 607 | |
| 608 | // Non-standard integer types. |
| 609 | GMOCK_DECLARE_KIND_(Int64, kInteger); |
| 610 | GMOCK_DECLARE_KIND_(UInt64, kInteger); |
| 611 | |
| 612 | // All standard floating-point types. |
| 613 | GMOCK_DECLARE_KIND_(float, kFloatingPoint); |
| 614 | GMOCK_DECLARE_KIND_(double, kFloatingPoint); |
| 615 | GMOCK_DECLARE_KIND_(long double, kFloatingPoint); |
| 616 | |
| 617 | #undef GMOCK_DECLARE_KIND_ |
| 618 | |
| 619 | // Evaluates to the kind of 'type'. |
| 620 | #define GMOCK_KIND_OF_(type) \ |
| 621 | static_cast< ::testing::internal::TypeKind>( \ |
| 622 | ::testing::internal::KindOf<type>::value) |
| 623 | |
| 624 | // Evaluates to true iff integer type T is signed. |
| 625 | #define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0) |
| 626 | |
| 627 | // LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value |
| 628 | // is true iff arithmetic type From can be losslessly converted to |
| 629 | // arithmetic type To. |
| 630 | // |
| 631 | // It's the user's responsibility to ensure that both From and To are |
| 632 | // raw (i.e. has no CV modifier, is not a pointer, and is not a |
| 633 | // reference) built-in arithmetic types, kFromKind is the kind of |
| 634 | // From, and kToKind is the kind of To; the value is |
| 635 | // implementation-defined when the above pre-condition is violated. |
| 636 | template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To> |
| 637 | struct LosslessArithmeticConvertibleImpl : public false_type {}; |
| 638 | |
| 639 | // Converting bool to bool is lossless. |
| 640 | template <> |
| 641 | struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool> |
| 642 | : public true_type {}; // NOLINT |
| 643 | |
| 644 | // Converting bool to any integer type is lossless. |
| 645 | template <typename To> |
| 646 | struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To> |
| 647 | : public true_type {}; // NOLINT |
| 648 | |
| 649 | // Converting bool to any floating-point type is lossless. |
| 650 | template <typename To> |
| 651 | struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To> |
| 652 | : public true_type {}; // NOLINT |
| 653 | |
| 654 | // Converting an integer to bool is lossy. |
| 655 | template <typename From> |
| 656 | struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool> |
| 657 | : public false_type {}; // NOLINT |
| 658 | |
| 659 | // Converting an integer to another non-bool integer is lossless iff |
| 660 | // the target type's range encloses the source type's range. |
| 661 | template <typename From, typename To> |
| 662 | struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To> |
| 663 | : public bool_constant< |
| 664 | // When converting from a smaller size to a larger size, we are |
| 665 | // fine as long as we are not converting from signed to unsigned. |
| 666 | ((sizeof(From) < sizeof(To)) && |
| 667 | (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) || |
| 668 | // When converting between the same size, the signedness must match. |
| 669 | ((sizeof(From) == sizeof(To)) && |
| 670 | (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT |
| 671 | |
| 672 | #undef GMOCK_IS_SIGNED_ |
| 673 | |
| 674 | // Converting an integer to a floating-point type may be lossy, since |
| 675 | // the format of a floating-point number is implementation-defined. |
| 676 | template <typename From, typename To> |
| 677 | struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To> |
| 678 | : public false_type {}; // NOLINT |
| 679 | |
| 680 | // Converting a floating-point to bool is lossy. |
| 681 | template <typename From> |
| 682 | struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool> |
| 683 | : public false_type {}; // NOLINT |
| 684 | |
| 685 | // Converting a floating-point to an integer is lossy. |
| 686 | template <typename From, typename To> |
| 687 | struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To> |
| 688 | : public false_type {}; // NOLINT |
| 689 | |
| 690 | // Converting a floating-point to another floating-point is lossless |
| 691 | // iff the target type is at least as big as the source type. |
| 692 | template <typename From, typename To> |
| 693 | struct LosslessArithmeticConvertibleImpl< |
| 694 | kFloatingPoint, From, kFloatingPoint, To> |
| 695 | : public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT |
| 696 | |
| 697 | // LosslessArithmeticConvertible<From, To>::value is true iff arithmetic |
| 698 | // type From can be losslessly converted to arithmetic type To. |
| 699 | // |
| 700 | // It's the user's responsibility to ensure that both From and To are |
| 701 | // raw (i.e. has no CV modifier, is not a pointer, and is not a |
| 702 | // reference) built-in arithmetic types; the value is |
| 703 | // implementation-defined when the above pre-condition is violated. |
| 704 | template <typename From, typename To> |
| 705 | struct LosslessArithmeticConvertible |
| 706 | : public LosslessArithmeticConvertibleImpl< |
| 707 | GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT |
| 708 | |
| 709 | // This interface knows how to report a Google Mock failure (either |
| 710 | // non-fatal or fatal). |
| 711 | class FailureReporterInterface { |
| 712 | public: |
| 713 | // The type of a failure (either non-fatal or fatal). |
| 714 | enum FailureType { |
| 715 | NONFATAL, FATAL |
| 716 | }; |
| 717 | |
| 718 | virtual ~FailureReporterInterface() {} |
| 719 | |
| 720 | // Reports a failure that occurred at the given source file location. |
| 721 | virtual void ReportFailure(FailureType type, const char* file, int line, |
| 722 | const string& message) = 0; |
| 723 | }; |
| 724 | |
| 725 | // Returns the failure reporter used by Google Mock. |
| 726 | FailureReporterInterface* GetFailureReporter(); |
| 727 | |
| 728 | // Asserts that condition is true; aborts the process with the given |
| 729 | // message if condition is false. We cannot use LOG(FATAL) or CHECK() |
| 730 | // as Google Mock might be used to mock the log sink itself. We |
| 731 | // inline this function to prevent it from showing up in the stack |
| 732 | // trace. |
| 733 | inline void Assert(bool condition, const char* file, int line, |
| 734 | const string& msg) { |
| 735 | if (!condition) { |
| 736 | GetFailureReporter()->ReportFailure(FailureReporterInterface::FATAL, |
| 737 | file, line, msg); |
| 738 | } |
| 739 | } |
| 740 | inline void Assert(bool condition, const char* file, int line) { |
| 741 | Assert(condition, file, line, "Assertion failed."); |
| 742 | } |
| 743 | |
| 744 | // Verifies that condition is true; generates a non-fatal failure if |
| 745 | // condition is false. |
| 746 | inline void Expect(bool condition, const char* file, int line, |
| 747 | const string& msg) { |
| 748 | if (!condition) { |
| 749 | GetFailureReporter()->ReportFailure(FailureReporterInterface::NONFATAL, |
| 750 | file, line, msg); |
| 751 | } |
| 752 | } |
| 753 | inline void Expect(bool condition, const char* file, int line) { |
| 754 | Expect(condition, file, line, "Expectation failed."); |
| 755 | } |
| 756 | |
| 757 | // Severity level of a log. |
| 758 | enum LogSeverity { |
| 759 | INFO = 0, |
| 760 | WARNING = 1 |
| 761 | }; |
| 762 | |
| 763 | // Valid values for the --gmock_verbose flag. |
| 764 | |
| 765 | // All logs (informational and warnings) are printed. |
| 766 | const char kInfoVerbosity[] = "info"; |
| 767 | // Only warnings are printed. |
| 768 | const char kWarningVerbosity[] = "warning"; |
| 769 | // No logs are printed. |
| 770 | const char kErrorVerbosity[] = "error"; |
| 771 | |
| 772 | // Returns true iff a log with the given severity is visible according |
| 773 | // to the --gmock_verbose flag. |
| 774 | bool LogIsVisible(LogSeverity severity); |
| 775 | |
| 776 | // Prints the given message to stdout iff 'severity' >= the level |
| 777 | // specified by the --gmock_verbose flag. If stack_frames_to_skip >= |
| 778 | // 0, also prints the stack trace excluding the top |
| 779 | // stack_frames_to_skip frames. In opt mode, any positive |
| 780 | // stack_frames_to_skip is treated as 0, since we don't know which |
| 781 | // function calls will be inlined by the compiler and need to be |
| 782 | // conservative. |
| 783 | void Log(LogSeverity severity, const string& message, int stack_frames_to_skip); |
| 784 | |
| 785 | // TODO(wan@google.com): group all type utilities together. |
| 786 | |
| 787 | // Type traits. |
| 788 | |
| 789 | // is_reference<T>::value is non-zero iff T is a reference type. |
| 790 | template <typename T> struct is_reference : public false_type {}; |
| 791 | template <typename T> struct is_reference<T&> : public true_type {}; |
| 792 | |
| 793 | // type_equals<T1, T2>::value is non-zero iff T1 and T2 are the same type. |
| 794 | template <typename T1, typename T2> struct type_equals : public false_type {}; |
| 795 | template <typename T> struct type_equals<T, T> : public true_type {}; |
| 796 | |
| 797 | // remove_reference<T>::type removes the reference from type T, if any. |
| 798 | template <typename T> struct remove_reference { typedef T type; }; // NOLINT |
| 799 | template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT |
| 800 | |
| 801 | // Invalid<T>() returns an invalid value of type T. This is useful |
| 802 | // when a value of type T is needed for compilation, but the statement |
| 803 | // will not really be executed (or we don't care if the statement |
| 804 | // crashes). |
| 805 | template <typename T> |
| 806 | inline T Invalid() { |
| 807 | return *static_cast<typename remove_reference<T>::type*>(NULL); |
| 808 | } |
| 809 | template <> |
| 810 | inline void Invalid<void>() {} |
| 811 | |
| 812 | // Given a raw type (i.e. having no top-level reference or const |
| 813 | // modifier) RawContainer that's either an STL-style container or a |
| 814 | // native array, class StlContainerView<RawContainer> has the |
| 815 | // following members: |
| 816 | // |
| 817 | // - type is a type that provides an STL-style container view to |
| 818 | // (i.e. implements the STL container concept for) RawContainer; |
| 819 | // - const_reference is a type that provides a reference to a const |
| 820 | // RawContainer; |
| 821 | // - ConstReference(raw_container) returns a const reference to an STL-style |
| 822 | // container view to raw_container, which is a RawContainer. |
| 823 | // - Copy(raw_container) returns an STL-style container view of a |
| 824 | // copy of raw_container, which is a RawContainer. |
| 825 | // |
| 826 | // This generic version is used when RawContainer itself is already an |
| 827 | // STL-style container. |
| 828 | template <class RawContainer> |
| 829 | class StlContainerView { |
| 830 | public: |
| 831 | typedef RawContainer type; |
| 832 | typedef const type& const_reference; |
| 833 | |
| 834 | static const_reference ConstReference(const RawContainer& container) { |
| 835 | // Ensures that RawContainer is not a const type. |
| 836 | testing::StaticAssertTypeEq<RawContainer, |
| 837 | GTEST_REMOVE_CONST_(RawContainer)>(); |
| 838 | return container; |
| 839 | } |
| 840 | static type Copy(const RawContainer& container) { return container; } |
| 841 | }; |
| 842 | |
| 843 | // This specialization is used when RawContainer is a native array type. |
| 844 | template <typename Element, size_t N> |
| 845 | class StlContainerView<Element[N]> { |
| 846 | public: |
| 847 | typedef GTEST_REMOVE_CONST_(Element) RawElement; |
| 848 | typedef internal::NativeArray<RawElement> type; |
| 849 | // NativeArray<T> can represent a native array either by value or by |
| 850 | // reference (selected by a constructor argument), so 'const type' |
| 851 | // can be used to reference a const native array. We cannot |
| 852 | // 'typedef const type& const_reference' here, as that would mean |
| 853 | // ConstReference() has to return a reference to a local variable. |
| 854 | typedef const type const_reference; |
| 855 | |
| 856 | static const_reference ConstReference(const Element (&array)[N]) { |
| 857 | // Ensures that Element is not a const type. |
| 858 | testing::StaticAssertTypeEq<Element, RawElement>(); |
| 859 | #if GTEST_OS_SYMBIAN |
| 860 | // The Nokia Symbian compiler confuses itself in template instantiation |
| 861 | // for this call without the cast to Element*: |
| 862 | // function call '[testing::internal::NativeArray<char *>].NativeArray( |
| 863 | // {lval} const char *[4], long, testing::internal::RelationToSource)' |
| 864 | // does not match |
| 865 | // 'testing::internal::NativeArray<char *>::NativeArray( |
| 866 | // char *const *, unsigned int, testing::internal::RelationToSource)' |
| 867 | // (instantiating: 'testing::internal::ContainsMatcherImpl |
| 868 | // <const char * (&)[4]>::Matches(const char * (&)[4]) const') |
| 869 | // (instantiating: 'testing::internal::StlContainerView<char *[4]>:: |
| 870 | // ConstReference(const char * (&)[4])') |
| 871 | // (and though the N parameter type is mismatched in the above explicit |
| 872 | // conversion of it doesn't help - only the conversion of the array). |
| 873 | return type(const_cast<Element*>(&array[0]), N, kReference); |
| 874 | #else |
| 875 | return type(array, N, kReference); |
| 876 | #endif // GTEST_OS_SYMBIAN |
| 877 | } |
| 878 | static type Copy(const Element (&array)[N]) { |
| 879 | #if GTEST_OS_SYMBIAN |
| 880 | return type(const_cast<Element*>(&array[0]), N, kCopy); |
| 881 | #else |
| 882 | return type(array, N, kCopy); |
| 883 | #endif // GTEST_OS_SYMBIAN |
| 884 | } |
| 885 | }; |
| 886 | |
| 887 | // This specialization is used when RawContainer is a native array |
| 888 | // represented as a (pointer, size) tuple. |
| 889 | template <typename ElementPointer, typename Size> |
| 890 | class StlContainerView< ::std::tr1::tuple<ElementPointer, Size> > { |
| 891 | public: |
| 892 | typedef GTEST_REMOVE_CONST_( |
| 893 | typename internal::PointeeOf<ElementPointer>::type) RawElement; |
| 894 | typedef internal::NativeArray<RawElement> type; |
| 895 | typedef const type const_reference; |
| 896 | |
| 897 | static const_reference ConstReference( |
| 898 | const ::std::tr1::tuple<ElementPointer, Size>& array) { |
| 899 | using ::std::tr1::get; |
| 900 | return type(get<0>(array), get<1>(array), kReference); |
| 901 | } |
| 902 | static type Copy(const ::std::tr1::tuple<ElementPointer, Size>& array) { |
| 903 | using ::std::tr1::get; |
| 904 | return type(get<0>(array), get<1>(array), kCopy); |
| 905 | } |
| 906 | }; |
| 907 | |
| 908 | // The following specialization prevents the user from instantiating |
| 909 | // StlContainer with a reference type. |
| 910 | template <typename T> class StlContainerView<T&>; |
| 911 | |
| 912 | } // namespace internal |
| 913 | } // namespace testing |
| 914 | |
| 915 | #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ |
| 916 | |
| 917 | namespace testing { |
| 918 | |
| 919 | // To implement an action Foo, define: |
| 920 | // 1. a class FooAction that implements the ActionInterface interface, and |
| 921 | // 2. a factory function that creates an Action object from a |
| 922 | // const FooAction*. |
| 923 | // |
| 924 | // The two-level delegation design follows that of Matcher, providing |
| 925 | // consistency for extension developers. It also eases ownership |
| 926 | // management as Action objects can now be copied like plain values. |
| 927 | |
| 928 | namespace internal { |
| 929 | |
| 930 | template <typename F1, typename F2> |
| 931 | class ActionAdaptor; |
| 932 | |
| 933 | // BuiltInDefaultValue<T>::Get() returns the "built-in" default |
| 934 | // value for type T, which is NULL when T is a pointer type, 0 when T |
| 935 | // is a numeric type, false when T is bool, or "" when T is string or |
| 936 | // std::string. For any other type T, this value is undefined and the |
| 937 | // function will abort the process. |
| 938 | template <typename T> |
| 939 | class BuiltInDefaultValue { |
| 940 | public: |
| 941 | // This function returns true iff type T has a built-in default value. |
| 942 | static bool Exists() { return false; } |
| 943 | static T Get() { |
| 944 | Assert(false, __FILE__, __LINE__, |
| 945 | "Default action undefined for the function return type."); |
| 946 | return internal::Invalid<T>(); |
| 947 | // The above statement will never be reached, but is required in |
| 948 | // order for this function to compile. |
| 949 | } |
| 950 | }; |
| 951 | |
| 952 | // This partial specialization says that we use the same built-in |
| 953 | // default value for T and const T. |
| 954 | template <typename T> |
| 955 | class BuiltInDefaultValue<const T> { |
| 956 | public: |
| 957 | static bool Exists() { return BuiltInDefaultValue<T>::Exists(); } |
| 958 | static T Get() { return BuiltInDefaultValue<T>::Get(); } |
| 959 | }; |
| 960 | |
| 961 | // This partial specialization defines the default values for pointer |
| 962 | // types. |
| 963 | template <typename T> |
| 964 | class BuiltInDefaultValue<T*> { |
| 965 | public: |
| 966 | static bool Exists() { return true; } |
| 967 | static T* Get() { return NULL; } |
| 968 | }; |
| 969 | |
| 970 | // The following specializations define the default values for |
| 971 | // specific types we care about. |
| 972 | #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \ |
| 973 | template <> \ |
| 974 | class BuiltInDefaultValue<type> { \ |
| 975 | public: \ |
| 976 | static bool Exists() { return true; } \ |
| 977 | static type Get() { return value; } \ |
| 978 | } |
| 979 | |
| 980 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT |
| 981 | #if GTEST_HAS_GLOBAL_STRING |
| 982 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, ""); |
| 983 | #endif // GTEST_HAS_GLOBAL_STRING |
| 984 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, ""); |
| 985 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false); |
| 986 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0'); |
| 987 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0'); |
| 988 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0'); |
| 989 | |
| 990 | // There's no need for a default action for signed wchar_t, as that |
| 991 | // type is the same as wchar_t for gcc, and invalid for MSVC. |
| 992 | // |
| 993 | // There's also no need for a default action for unsigned wchar_t, as |
| 994 | // that type is the same as unsigned int for gcc, and invalid for |
| 995 | // MSVC. |
| 996 | #if GMOCK_WCHAR_T_IS_NATIVE_ |
| 997 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT |
| 998 | #endif |
| 999 | |
| 1000 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT |
| 1001 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT |
| 1002 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U); |
| 1003 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0); |
| 1004 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT |
| 1005 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT |
| 1006 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0); |
| 1007 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0); |
| 1008 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0); |
| 1009 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0); |
| 1010 | |
| 1011 | #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_ |
| 1012 | |
| 1013 | } // namespace internal |
| 1014 | |
| 1015 | // When an unexpected function call is encountered, Google Mock will |
| 1016 | // let it return a default value if the user has specified one for its |
| 1017 | // return type, or if the return type has a built-in default value; |
| 1018 | // otherwise Google Mock won't know what value to return and will have |
| 1019 | // to abort the process. |
| 1020 | // |
| 1021 | // The DefaultValue<T> class allows a user to specify the |
| 1022 | // default value for a type T that is both copyable and publicly |
| 1023 | // destructible (i.e. anything that can be used as a function return |
| 1024 | // type). The usage is: |
| 1025 | // |
| 1026 | // // Sets the default value for type T to be foo. |
| 1027 | // DefaultValue<T>::Set(foo); |
| 1028 | template <typename T> |
| 1029 | class DefaultValue { |
| 1030 | public: |
| 1031 | // Sets the default value for type T; requires T to be |
| 1032 | // copy-constructable and have a public destructor. |
| 1033 | static void Set(T x) { |
| 1034 | delete value_; |
| 1035 | value_ = new T(x); |
| 1036 | } |
| 1037 | |
| 1038 | // Unsets the default value for type T. |
| 1039 | static void Clear() { |
| 1040 | delete value_; |
| 1041 | value_ = NULL; |
| 1042 | } |
| 1043 | |
| 1044 | // Returns true iff the user has set the default value for type T. |
| 1045 | static bool IsSet() { return value_ != NULL; } |
| 1046 | |
| 1047 | // Returns true if T has a default return value set by the user or there |
| 1048 | // exists a built-in default value. |
| 1049 | static bool Exists() { |
| 1050 | return IsSet() || internal::BuiltInDefaultValue<T>::Exists(); |
| 1051 | } |
| 1052 | |
| 1053 | // Returns the default value for type T if the user has set one; |
| 1054 | // otherwise returns the built-in default value if there is one; |
| 1055 | // otherwise aborts the process. |
| 1056 | static T Get() { |
| 1057 | return value_ == NULL ? |
| 1058 | internal::BuiltInDefaultValue<T>::Get() : *value_; |
| 1059 | } |
| 1060 | private: |
| 1061 | static const T* value_; |
| 1062 | }; |
| 1063 | |
| 1064 | // This partial specialization allows a user to set default values for |
| 1065 | // reference types. |
| 1066 | template <typename T> |
| 1067 | class DefaultValue<T&> { |
| 1068 | public: |
| 1069 | // Sets the default value for type T&. |
| 1070 | static void Set(T& x) { // NOLINT |
| 1071 | address_ = &x; |
| 1072 | } |
| 1073 | |
| 1074 | // Unsets the default value for type T&. |
| 1075 | static void Clear() { |
| 1076 | address_ = NULL; |
| 1077 | } |
| 1078 | |
| 1079 | // Returns true iff the user has set the default value for type T&. |
| 1080 | static bool IsSet() { return address_ != NULL; } |
| 1081 | |
| 1082 | // Returns true if T has a default return value set by the user or there |
| 1083 | // exists a built-in default value. |
| 1084 | static bool Exists() { |
| 1085 | return IsSet() || internal::BuiltInDefaultValue<T&>::Exists(); |
| 1086 | } |
| 1087 | |
| 1088 | // Returns the default value for type T& if the user has set one; |
| 1089 | // otherwise returns the built-in default value if there is one; |
| 1090 | // otherwise aborts the process. |
| 1091 | static T& Get() { |
| 1092 | return address_ == NULL ? |
| 1093 | internal::BuiltInDefaultValue<T&>::Get() : *address_; |
| 1094 | } |
| 1095 | private: |
| 1096 | static T* address_; |
| 1097 | }; |
| 1098 | |
| 1099 | // This specialization allows DefaultValue<void>::Get() to |
| 1100 | // compile. |
| 1101 | template <> |
| 1102 | class DefaultValue<void> { |
| 1103 | public: |
| 1104 | static bool Exists() { return true; } |
| 1105 | static void Get() {} |
| 1106 | }; |
| 1107 | |
| 1108 | // Points to the user-set default value for type T. |
| 1109 | template <typename T> |
| 1110 | const T* DefaultValue<T>::value_ = NULL; |
| 1111 | |
| 1112 | // Points to the user-set default value for type T&. |
| 1113 | template <typename T> |
| 1114 | T* DefaultValue<T&>::address_ = NULL; |
| 1115 | |
| 1116 | // Implement this interface to define an action for function type F. |
| 1117 | template <typename F> |
| 1118 | class ActionInterface { |
| 1119 | public: |
| 1120 | typedef typename internal::Function<F>::Result Result; |
| 1121 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 1122 | |
| 1123 | ActionInterface() {} |
| 1124 | virtual ~ActionInterface() {} |
| 1125 | |
| 1126 | // Performs the action. This method is not const, as in general an |
| 1127 | // action can have side effects and be stateful. For example, a |
| 1128 | // get-the-next-element-from-the-collection action will need to |
| 1129 | // remember the current element. |
| 1130 | virtual Result Perform(const ArgumentTuple& args) = 0; |
| 1131 | |
| 1132 | private: |
| 1133 | GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface); |
| 1134 | }; |
| 1135 | |
| 1136 | // An Action<F> is a copyable and IMMUTABLE (except by assignment) |
| 1137 | // object that represents an action to be taken when a mock function |
| 1138 | // of type F is called. The implementation of Action<T> is just a |
| 1139 | // linked_ptr to const ActionInterface<T>, so copying is fairly cheap. |
| 1140 | // Don't inherit from Action! |
| 1141 | // |
| 1142 | // You can view an object implementing ActionInterface<F> as a |
| 1143 | // concrete action (including its current state), and an Action<F> |
| 1144 | // object as a handle to it. |
| 1145 | template <typename F> |
| 1146 | class Action { |
| 1147 | public: |
| 1148 | typedef typename internal::Function<F>::Result Result; |
| 1149 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 1150 | |
| 1151 | // Constructs a null Action. Needed for storing Action objects in |
| 1152 | // STL containers. |
| 1153 | Action() : impl_(NULL) {} |
| 1154 | |
| 1155 | // Constructs an Action from its implementation. A NULL impl is |
| 1156 | // used to represent the "do-default" action. |
| 1157 | explicit Action(ActionInterface<F>* impl) : impl_(impl) {} |
| 1158 | |
| 1159 | // Copy constructor. |
| 1160 | Action(const Action& action) : impl_(action.impl_) {} |
| 1161 | |
| 1162 | // This constructor allows us to turn an Action<Func> object into an |
| 1163 | // Action<F>, as long as F's arguments can be implicitly converted |
| 1164 | // to Func's and Func's return type can be implicitly converted to |
| 1165 | // F's. |
| 1166 | template <typename Func> |
| 1167 | explicit Action(const Action<Func>& action); |
| 1168 | |
| 1169 | // Returns true iff this is the DoDefault() action. |
| 1170 | bool IsDoDefault() const { return impl_.get() == NULL; } |
| 1171 | |
| 1172 | // Performs the action. Note that this method is const even though |
| 1173 | // the corresponding method in ActionInterface is not. The reason |
| 1174 | // is that a const Action<F> means that it cannot be re-bound to |
| 1175 | // another concrete action, not that the concrete action it binds to |
| 1176 | // cannot change state. (Think of the difference between a const |
| 1177 | // pointer and a pointer to const.) |
| 1178 | Result Perform(const ArgumentTuple& args) const { |
| 1179 | internal::Assert( |
| 1180 | !IsDoDefault(), __FILE__, __LINE__, |
| 1181 | "You are using DoDefault() inside a composite action like " |
| 1182 | "DoAll() or WithArgs(). This is not supported for technical " |
| 1183 | "reasons. Please instead spell out the default action, or " |
| 1184 | "assign the default action to an Action variable and use " |
| 1185 | "the variable in various places."); |
| 1186 | return impl_->Perform(args); |
| 1187 | } |
| 1188 | |
| 1189 | private: |
| 1190 | template <typename F1, typename F2> |
| 1191 | friend class internal::ActionAdaptor; |
| 1192 | |
| 1193 | internal::linked_ptr<ActionInterface<F> > impl_; |
| 1194 | }; |
| 1195 | |
| 1196 | // The PolymorphicAction class template makes it easy to implement a |
| 1197 | // polymorphic action (i.e. an action that can be used in mock |
| 1198 | // functions of than one type, e.g. Return()). |
| 1199 | // |
| 1200 | // To define a polymorphic action, a user first provides a COPYABLE |
| 1201 | // implementation class that has a Perform() method template: |
| 1202 | // |
| 1203 | // class FooAction { |
| 1204 | // public: |
| 1205 | // template <typename Result, typename ArgumentTuple> |
| 1206 | // Result Perform(const ArgumentTuple& args) const { |
| 1207 | // // Processes the arguments and returns a result, using |
| 1208 | // // tr1::get<N>(args) to get the N-th (0-based) argument in the tuple. |
| 1209 | // } |
| 1210 | // ... |
| 1211 | // }; |
| 1212 | // |
| 1213 | // Then the user creates the polymorphic action using |
| 1214 | // MakePolymorphicAction(object) where object has type FooAction. See |
| 1215 | // the definition of Return(void) and SetArgumentPointee<N>(value) for |
| 1216 | // complete examples. |
| 1217 | template <typename Impl> |
| 1218 | class PolymorphicAction { |
| 1219 | public: |
| 1220 | explicit PolymorphicAction(const Impl& impl) : impl_(impl) {} |
| 1221 | |
| 1222 | template <typename F> |
| 1223 | operator Action<F>() const { |
| 1224 | return Action<F>(new MonomorphicImpl<F>(impl_)); |
| 1225 | } |
| 1226 | |
| 1227 | private: |
| 1228 | template <typename F> |
| 1229 | class MonomorphicImpl : public ActionInterface<F> { |
| 1230 | public: |
| 1231 | typedef typename internal::Function<F>::Result Result; |
| 1232 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 1233 | |
| 1234 | explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} |
| 1235 | |
| 1236 | virtual Result Perform(const ArgumentTuple& args) { |
| 1237 | return impl_.template Perform<Result>(args); |
| 1238 | } |
| 1239 | |
| 1240 | private: |
| 1241 | Impl impl_; |
| 1242 | |
| 1243 | GTEST_DISALLOW_ASSIGN_(MonomorphicImpl); |
| 1244 | }; |
| 1245 | |
| 1246 | Impl impl_; |
| 1247 | |
| 1248 | GTEST_DISALLOW_ASSIGN_(PolymorphicAction); |
| 1249 | }; |
| 1250 | |
| 1251 | // Creates an Action from its implementation and returns it. The |
| 1252 | // created Action object owns the implementation. |
| 1253 | template <typename F> |
| 1254 | Action<F> MakeAction(ActionInterface<F>* impl) { |
| 1255 | return Action<F>(impl); |
| 1256 | } |
| 1257 | |
| 1258 | // Creates a polymorphic action from its implementation. This is |
| 1259 | // easier to use than the PolymorphicAction<Impl> constructor as it |
| 1260 | // doesn't require you to explicitly write the template argument, e.g. |
| 1261 | // |
| 1262 | // MakePolymorphicAction(foo); |
| 1263 | // vs |
| 1264 | // PolymorphicAction<TypeOfFoo>(foo); |
| 1265 | template <typename Impl> |
| 1266 | inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) { |
| 1267 | return PolymorphicAction<Impl>(impl); |
| 1268 | } |
| 1269 | |
| 1270 | namespace internal { |
| 1271 | |
| 1272 | // Allows an Action<F2> object to pose as an Action<F1>, as long as F2 |
| 1273 | // and F1 are compatible. |
| 1274 | template <typename F1, typename F2> |
| 1275 | class ActionAdaptor : public ActionInterface<F1> { |
| 1276 | public: |
| 1277 | typedef typename internal::Function<F1>::Result Result; |
| 1278 | typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple; |
| 1279 | |
| 1280 | explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {} |
| 1281 | |
| 1282 | virtual Result Perform(const ArgumentTuple& args) { |
| 1283 | return impl_->Perform(args); |
| 1284 | } |
| 1285 | |
| 1286 | private: |
| 1287 | const internal::linked_ptr<ActionInterface<F2> > impl_; |
| 1288 | |
| 1289 | GTEST_DISALLOW_ASSIGN_(ActionAdaptor); |
| 1290 | }; |
| 1291 | |
| 1292 | // Implements the polymorphic Return(x) action, which can be used in |
| 1293 | // any function that returns the type of x, regardless of the argument |
| 1294 | // types. |
| 1295 | // |
| 1296 | // Note: The value passed into Return must be converted into |
| 1297 | // Function<F>::Result when this action is cast to Action<F> rather than |
| 1298 | // when that action is performed. This is important in scenarios like |
| 1299 | // |
| 1300 | // MOCK_METHOD1(Method, T(U)); |
| 1301 | // ... |
| 1302 | // { |
| 1303 | // Foo foo; |
| 1304 | // X x(&foo); |
| 1305 | // EXPECT_CALL(mock, Method(_)).WillOnce(Return(x)); |
| 1306 | // } |
| 1307 | // |
| 1308 | // In the example above the variable x holds reference to foo which leaves |
| 1309 | // scope and gets destroyed. If copying X just copies a reference to foo, |
| 1310 | // that copy will be left with a hanging reference. If conversion to T |
| 1311 | // makes a copy of foo, the above code is safe. To support that scenario, we |
| 1312 | // need to make sure that the type conversion happens inside the EXPECT_CALL |
| 1313 | // statement, and conversion of the result of Return to Action<T(U)> is a |
| 1314 | // good place for that. |
| 1315 | // |
| 1316 | template <typename R> |
| 1317 | class ReturnAction { |
| 1318 | public: |
| 1319 | // Constructs a ReturnAction object from the value to be returned. |
| 1320 | // 'value' is passed by value instead of by const reference in order |
| 1321 | // to allow Return("string literal") to compile. |
| 1322 | explicit ReturnAction(R value) : value_(value) {} |
| 1323 | |
| 1324 | // This template type conversion operator allows Return(x) to be |
| 1325 | // used in ANY function that returns x's type. |
| 1326 | template <typename F> |
| 1327 | operator Action<F>() const { |
| 1328 | // Assert statement belongs here because this is the best place to verify |
| 1329 | // conditions on F. It produces the clearest error messages |
| 1330 | // in most compilers. |
| 1331 | // Impl really belongs in this scope as a local class but can't |
| 1332 | // because MSVC produces duplicate symbols in different translation units |
| 1333 | // in this case. Until MS fixes that bug we put Impl into the class scope |
| 1334 | // and put the typedef both here (for use in assert statement) and |
| 1335 | // in the Impl class. But both definitions must be the same. |
| 1336 | typedef typename Function<F>::Result Result; |
| 1337 | GTEST_COMPILE_ASSERT_( |
| 1338 | !internal::is_reference<Result>::value, |
| 1339 | use_ReturnRef_instead_of_Return_to_return_a_reference); |
| 1340 | return Action<F>(new Impl<F>(value_)); |
| 1341 | } |
| 1342 | |
| 1343 | private: |
| 1344 | // Implements the Return(x) action for a particular function type F. |
| 1345 | template <typename F> |
| 1346 | class Impl : public ActionInterface<F> { |
| 1347 | public: |
| 1348 | typedef typename Function<F>::Result Result; |
| 1349 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 1350 | |
| 1351 | // The implicit cast is necessary when Result has more than one |
| 1352 | // single-argument constructor (e.g. Result is std::vector<int>) and R |
| 1353 | // has a type conversion operator template. In that case, value_(value) |
| 1354 | // won't compile as the compiler doesn't known which constructor of |
| 1355 | // Result to call. ImplicitCast_ forces the compiler to convert R to |
| 1356 | // Result without considering explicit constructors, thus resolving the |
| 1357 | // ambiguity. value_ is then initialized using its copy constructor. |
| 1358 | explicit Impl(R value) |
| 1359 | : value_(::testing::internal::ImplicitCast_<Result>(value)) {} |
| 1360 | |
| 1361 | virtual Result Perform(const ArgumentTuple&) { return value_; } |
| 1362 | |
| 1363 | private: |
| 1364 | GTEST_COMPILE_ASSERT_(!internal::is_reference<Result>::value, |
| 1365 | Result_cannot_be_a_reference_type); |
| 1366 | Result value_; |
| 1367 | |
| 1368 | GTEST_DISALLOW_ASSIGN_(Impl); |
| 1369 | }; |
| 1370 | |
| 1371 | R value_; |
| 1372 | |
| 1373 | GTEST_DISALLOW_ASSIGN_(ReturnAction); |
| 1374 | }; |
| 1375 | |
| 1376 | // Implements the ReturnNull() action. |
| 1377 | class ReturnNullAction { |
| 1378 | public: |
| 1379 | // Allows ReturnNull() to be used in any pointer-returning function. |
| 1380 | template <typename Result, typename ArgumentTuple> |
| 1381 | static Result Perform(const ArgumentTuple&) { |
| 1382 | GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value, |
| 1383 | ReturnNull_can_be_used_to_return_a_pointer_only); |
| 1384 | return NULL; |
| 1385 | } |
| 1386 | }; |
| 1387 | |
| 1388 | // Implements the Return() action. |
| 1389 | class ReturnVoidAction { |
| 1390 | public: |
| 1391 | // Allows Return() to be used in any void-returning function. |
| 1392 | template <typename Result, typename ArgumentTuple> |
| 1393 | static void Perform(const ArgumentTuple&) { |
| 1394 | CompileAssertTypesEqual<void, Result>(); |
| 1395 | } |
| 1396 | }; |
| 1397 | |
| 1398 | // Implements the polymorphic ReturnRef(x) action, which can be used |
| 1399 | // in any function that returns a reference to the type of x, |
| 1400 | // regardless of the argument types. |
| 1401 | template <typename T> |
| 1402 | class ReturnRefAction { |
| 1403 | public: |
| 1404 | // Constructs a ReturnRefAction object from the reference to be returned. |
| 1405 | explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT |
| 1406 | |
| 1407 | // This template type conversion operator allows ReturnRef(x) to be |
| 1408 | // used in ANY function that returns a reference to x's type. |
| 1409 | template <typename F> |
| 1410 | operator Action<F>() const { |
| 1411 | typedef typename Function<F>::Result Result; |
| 1412 | // Asserts that the function return type is a reference. This |
| 1413 | // catches the user error of using ReturnRef(x) when Return(x) |
| 1414 | // should be used, and generates some helpful error message. |
| 1415 | GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value, |
| 1416 | use_Return_instead_of_ReturnRef_to_return_a_value); |
| 1417 | return Action<F>(new Impl<F>(ref_)); |
| 1418 | } |
| 1419 | |
| 1420 | private: |
| 1421 | // Implements the ReturnRef(x) action for a particular function type F. |
| 1422 | template <typename F> |
| 1423 | class Impl : public ActionInterface<F> { |
| 1424 | public: |
| 1425 | typedef typename Function<F>::Result Result; |
| 1426 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 1427 | |
| 1428 | explicit Impl(T& ref) : ref_(ref) {} // NOLINT |
| 1429 | |
| 1430 | virtual Result Perform(const ArgumentTuple&) { |
| 1431 | return ref_; |
| 1432 | } |
| 1433 | |
| 1434 | private: |
| 1435 | T& ref_; |
| 1436 | |
| 1437 | GTEST_DISALLOW_ASSIGN_(Impl); |
| 1438 | }; |
| 1439 | |
| 1440 | T& ref_; |
| 1441 | |
| 1442 | GTEST_DISALLOW_ASSIGN_(ReturnRefAction); |
| 1443 | }; |
| 1444 | |
| 1445 | // Implements the polymorphic ReturnRefOfCopy(x) action, which can be |
| 1446 | // used in any function that returns a reference to the type of x, |
| 1447 | // regardless of the argument types. |
| 1448 | template <typename T> |
| 1449 | class ReturnRefOfCopyAction { |
| 1450 | public: |
| 1451 | // Constructs a ReturnRefOfCopyAction object from the reference to |
| 1452 | // be returned. |
| 1453 | explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT |
| 1454 | |
| 1455 | // This template type conversion operator allows ReturnRefOfCopy(x) to be |
| 1456 | // used in ANY function that returns a reference to x's type. |
| 1457 | template <typename F> |
| 1458 | operator Action<F>() const { |
| 1459 | typedef typename Function<F>::Result Result; |
| 1460 | // Asserts that the function return type is a reference. This |
| 1461 | // catches the user error of using ReturnRefOfCopy(x) when Return(x) |
| 1462 | // should be used, and generates some helpful error message. |
| 1463 | GTEST_COMPILE_ASSERT_( |
| 1464 | internal::is_reference<Result>::value, |
| 1465 | use_Return_instead_of_ReturnRefOfCopy_to_return_a_value); |
| 1466 | return Action<F>(new Impl<F>(value_)); |
| 1467 | } |
| 1468 | |
| 1469 | private: |
| 1470 | // Implements the ReturnRefOfCopy(x) action for a particular function type F. |
| 1471 | template <typename F> |
| 1472 | class Impl : public ActionInterface<F> { |
| 1473 | public: |
| 1474 | typedef typename Function<F>::Result Result; |
| 1475 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 1476 | |
| 1477 | explicit Impl(const T& value) : value_(value) {} // NOLINT |
| 1478 | |
| 1479 | virtual Result Perform(const ArgumentTuple&) { |
| 1480 | return value_; |
| 1481 | } |
| 1482 | |
| 1483 | private: |
| 1484 | T value_; |
| 1485 | |
| 1486 | GTEST_DISALLOW_ASSIGN_(Impl); |
| 1487 | }; |
| 1488 | |
| 1489 | const T value_; |
| 1490 | |
| 1491 | GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction); |
| 1492 | }; |
| 1493 | |
| 1494 | // Implements the polymorphic DoDefault() action. |
| 1495 | class DoDefaultAction { |
| 1496 | public: |
| 1497 | // This template type conversion operator allows DoDefault() to be |
| 1498 | // used in any function. |
| 1499 | template <typename F> |
| 1500 | operator Action<F>() const { return Action<F>(NULL); } |
| 1501 | }; |
| 1502 | |
| 1503 | // Implements the Assign action to set a given pointer referent to a |
| 1504 | // particular value. |
| 1505 | template <typename T1, typename T2> |
| 1506 | class AssignAction { |
| 1507 | public: |
| 1508 | AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {} |
| 1509 | |
| 1510 | template <typename Result, typename ArgumentTuple> |
| 1511 | void Perform(const ArgumentTuple& /* args */) const { |
| 1512 | *ptr_ = value_; |
| 1513 | } |
| 1514 | |
| 1515 | private: |
| 1516 | T1* const ptr_; |
| 1517 | const T2 value_; |
| 1518 | |
| 1519 | GTEST_DISALLOW_ASSIGN_(AssignAction); |
| 1520 | }; |
| 1521 | |
| 1522 | #if !GTEST_OS_WINDOWS_MOBILE |
| 1523 | |
| 1524 | // Implements the SetErrnoAndReturn action to simulate return from |
| 1525 | // various system calls and libc functions. |
| 1526 | template <typename T> |
| 1527 | class SetErrnoAndReturnAction { |
| 1528 | public: |
| 1529 | SetErrnoAndReturnAction(int errno_value, T result) |
| 1530 | : errno_(errno_value), |
| 1531 | result_(result) {} |
| 1532 | template <typename Result, typename ArgumentTuple> |
| 1533 | Result Perform(const ArgumentTuple& /* args */) const { |
| 1534 | errno = errno_; |
| 1535 | return result_; |
| 1536 | } |
| 1537 | |
| 1538 | private: |
| 1539 | const int errno_; |
| 1540 | const T result_; |
| 1541 | |
| 1542 | GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction); |
| 1543 | }; |
| 1544 | |
| 1545 | #endif // !GTEST_OS_WINDOWS_MOBILE |
| 1546 | |
| 1547 | // Implements the SetArgumentPointee<N>(x) action for any function |
| 1548 | // whose N-th argument (0-based) is a pointer to x's type. The |
| 1549 | // template parameter kIsProto is true iff type A is ProtocolMessage, |
| 1550 | // proto2::Message, or a sub-class of those. |
| 1551 | template <size_t N, typename A, bool kIsProto> |
| 1552 | class SetArgumentPointeeAction { |
| 1553 | public: |
| 1554 | // Constructs an action that sets the variable pointed to by the |
| 1555 | // N-th function argument to 'value'. |
| 1556 | explicit SetArgumentPointeeAction(const A& value) : value_(value) {} |
| 1557 | |
| 1558 | template <typename Result, typename ArgumentTuple> |
| 1559 | void Perform(const ArgumentTuple& args) const { |
| 1560 | CompileAssertTypesEqual<void, Result>(); |
| 1561 | *::std::tr1::get<N>(args) = value_; |
| 1562 | } |
| 1563 | |
| 1564 | private: |
| 1565 | const A value_; |
| 1566 | |
| 1567 | GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction); |
| 1568 | }; |
| 1569 | |
| 1570 | template <size_t N, typename Proto> |
| 1571 | class SetArgumentPointeeAction<N, Proto, true> { |
| 1572 | public: |
| 1573 | // Constructs an action that sets the variable pointed to by the |
| 1574 | // N-th function argument to 'proto'. Both ProtocolMessage and |
| 1575 | // proto2::Message have the CopyFrom() method, so the same |
| 1576 | // implementation works for both. |
| 1577 | explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) { |
| 1578 | proto_->CopyFrom(proto); |
| 1579 | } |
| 1580 | |
| 1581 | template <typename Result, typename ArgumentTuple> |
| 1582 | void Perform(const ArgumentTuple& args) const { |
| 1583 | CompileAssertTypesEqual<void, Result>(); |
| 1584 | ::std::tr1::get<N>(args)->CopyFrom(*proto_); |
| 1585 | } |
| 1586 | |
| 1587 | private: |
| 1588 | const internal::linked_ptr<Proto> proto_; |
| 1589 | |
| 1590 | GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction); |
| 1591 | }; |
| 1592 | |
| 1593 | // Implements the InvokeWithoutArgs(f) action. The template argument |
| 1594 | // FunctionImpl is the implementation type of f, which can be either a |
| 1595 | // function pointer or a functor. InvokeWithoutArgs(f) can be used as an |
| 1596 | // Action<F> as long as f's type is compatible with F (i.e. f can be |
| 1597 | // assigned to a tr1::function<F>). |
| 1598 | template <typename FunctionImpl> |
| 1599 | class InvokeWithoutArgsAction { |
| 1600 | public: |
| 1601 | // The c'tor makes a copy of function_impl (either a function |
| 1602 | // pointer or a functor). |
| 1603 | explicit InvokeWithoutArgsAction(FunctionImpl function_impl) |
| 1604 | : function_impl_(function_impl) {} |
| 1605 | |
| 1606 | // Allows InvokeWithoutArgs(f) to be used as any action whose type is |
| 1607 | // compatible with f. |
| 1608 | template <typename Result, typename ArgumentTuple> |
| 1609 | Result Perform(const ArgumentTuple&) { return function_impl_(); } |
| 1610 | |
| 1611 | private: |
| 1612 | FunctionImpl function_impl_; |
| 1613 | |
| 1614 | GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction); |
| 1615 | }; |
| 1616 | |
| 1617 | // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action. |
| 1618 | template <class Class, typename MethodPtr> |
| 1619 | class InvokeMethodWithoutArgsAction { |
| 1620 | public: |
| 1621 | InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr) |
| 1622 | : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} |
| 1623 | |
| 1624 | template <typename Result, typename ArgumentTuple> |
| 1625 | Result Perform(const ArgumentTuple&) const { |
| 1626 | return (obj_ptr_->*method_ptr_)(); |
| 1627 | } |
| 1628 | |
| 1629 | private: |
| 1630 | Class* const obj_ptr_; |
| 1631 | const MethodPtr method_ptr_; |
| 1632 | |
| 1633 | GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction); |
| 1634 | }; |
| 1635 | |
| 1636 | // Implements the IgnoreResult(action) action. |
| 1637 | template <typename A> |
| 1638 | class IgnoreResultAction { |
| 1639 | public: |
| 1640 | explicit IgnoreResultAction(const A& action) : action_(action) {} |
| 1641 | |
| 1642 | template <typename F> |
| 1643 | operator Action<F>() const { |
| 1644 | // Assert statement belongs here because this is the best place to verify |
| 1645 | // conditions on F. It produces the clearest error messages |
| 1646 | // in most compilers. |
| 1647 | // Impl really belongs in this scope as a local class but can't |
| 1648 | // because MSVC produces duplicate symbols in different translation units |
| 1649 | // in this case. Until MS fixes that bug we put Impl into the class scope |
| 1650 | // and put the typedef both here (for use in assert statement) and |
| 1651 | // in the Impl class. But both definitions must be the same. |
| 1652 | typedef typename internal::Function<F>::Result Result; |
| 1653 | |
| 1654 | // Asserts at compile time that F returns void. |
| 1655 | CompileAssertTypesEqual<void, Result>(); |
| 1656 | |
| 1657 | return Action<F>(new Impl<F>(action_)); |
| 1658 | } |
| 1659 | |
| 1660 | private: |
| 1661 | template <typename F> |
| 1662 | class Impl : public ActionInterface<F> { |
| 1663 | public: |
| 1664 | typedef typename internal::Function<F>::Result Result; |
| 1665 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 1666 | |
| 1667 | explicit Impl(const A& action) : action_(action) {} |
| 1668 | |
| 1669 | virtual void Perform(const ArgumentTuple& args) { |
| 1670 | // Performs the action and ignores its result. |
| 1671 | action_.Perform(args); |
| 1672 | } |
| 1673 | |
| 1674 | private: |
| 1675 | // Type OriginalFunction is the same as F except that its return |
| 1676 | // type is IgnoredValue. |
| 1677 | typedef typename internal::Function<F>::MakeResultIgnoredValue |
| 1678 | OriginalFunction; |
| 1679 | |
| 1680 | const Action<OriginalFunction> action_; |
| 1681 | |
| 1682 | GTEST_DISALLOW_ASSIGN_(Impl); |
| 1683 | }; |
| 1684 | |
| 1685 | const A action_; |
| 1686 | |
| 1687 | GTEST_DISALLOW_ASSIGN_(IgnoreResultAction); |
| 1688 | }; |
| 1689 | |
| 1690 | // A ReferenceWrapper<T> object represents a reference to type T, |
| 1691 | // which can be either const or not. It can be explicitly converted |
| 1692 | // from, and implicitly converted to, a T&. Unlike a reference, |
| 1693 | // ReferenceWrapper<T> can be copied and can survive template type |
| 1694 | // inference. This is used to support by-reference arguments in the |
| 1695 | // InvokeArgument<N>(...) action. The idea was from "reference |
| 1696 | // wrappers" in tr1, which we don't have in our source tree yet. |
| 1697 | template <typename T> |
| 1698 | class ReferenceWrapper { |
| 1699 | public: |
| 1700 | // Constructs a ReferenceWrapper<T> object from a T&. |
| 1701 | explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT |
| 1702 | |
| 1703 | // Allows a ReferenceWrapper<T> object to be implicitly converted to |
| 1704 | // a T&. |
| 1705 | operator T&() const { return *pointer_; } |
| 1706 | private: |
| 1707 | T* pointer_; |
| 1708 | }; |
| 1709 | |
| 1710 | // Allows the expression ByRef(x) to be printed as a reference to x. |
| 1711 | template <typename T> |
| 1712 | void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) { |
| 1713 | T& value = ref; |
| 1714 | UniversalPrinter<T&>::Print(value, os); |
| 1715 | } |
| 1716 | |
| 1717 | // Does two actions sequentially. Used for implementing the DoAll(a1, |
| 1718 | // a2, ...) action. |
| 1719 | template <typename Action1, typename Action2> |
| 1720 | class DoBothAction { |
| 1721 | public: |
| 1722 | DoBothAction(Action1 action1, Action2 action2) |
| 1723 | : action1_(action1), action2_(action2) {} |
| 1724 | |
| 1725 | // This template type conversion operator allows DoAll(a1, ..., a_n) |
| 1726 | // to be used in ANY function of compatible type. |
| 1727 | template <typename F> |
| 1728 | operator Action<F>() const { |
| 1729 | return Action<F>(new Impl<F>(action1_, action2_)); |
| 1730 | } |
| 1731 | |
| 1732 | private: |
| 1733 | // Implements the DoAll(...) action for a particular function type F. |
| 1734 | template <typename F> |
| 1735 | class Impl : public ActionInterface<F> { |
| 1736 | public: |
| 1737 | typedef typename Function<F>::Result Result; |
| 1738 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 1739 | typedef typename Function<F>::MakeResultVoid VoidResult; |
| 1740 | |
| 1741 | Impl(const Action<VoidResult>& action1, const Action<F>& action2) |
| 1742 | : action1_(action1), action2_(action2) {} |
| 1743 | |
| 1744 | virtual Result Perform(const ArgumentTuple& args) { |
| 1745 | action1_.Perform(args); |
| 1746 | return action2_.Perform(args); |
| 1747 | } |
| 1748 | |
| 1749 | private: |
| 1750 | const Action<VoidResult> action1_; |
| 1751 | const Action<F> action2_; |
| 1752 | |
| 1753 | GTEST_DISALLOW_ASSIGN_(Impl); |
| 1754 | }; |
| 1755 | |
| 1756 | Action1 action1_; |
| 1757 | Action2 action2_; |
| 1758 | |
| 1759 | GTEST_DISALLOW_ASSIGN_(DoBothAction); |
| 1760 | }; |
| 1761 | |
| 1762 | } // namespace internal |
| 1763 | |
| 1764 | // An Unused object can be implicitly constructed from ANY value. |
| 1765 | // This is handy when defining actions that ignore some or all of the |
| 1766 | // mock function arguments. For example, given |
| 1767 | // |
| 1768 | // MOCK_METHOD3(Foo, double(const string& label, double x, double y)); |
| 1769 | // MOCK_METHOD3(Bar, double(int index, double x, double y)); |
| 1770 | // |
| 1771 | // instead of |
| 1772 | // |
| 1773 | // double DistanceToOriginWithLabel(const string& label, double x, double y) { |
| 1774 | // return sqrt(x*x + y*y); |
| 1775 | // } |
| 1776 | // double DistanceToOriginWithIndex(int index, double x, double y) { |
| 1777 | // return sqrt(x*x + y*y); |
| 1778 | // } |
| 1779 | // ... |
| 1780 | // EXEPCT_CALL(mock, Foo("abc", _, _)) |
| 1781 | // .WillOnce(Invoke(DistanceToOriginWithLabel)); |
| 1782 | // EXEPCT_CALL(mock, Bar(5, _, _)) |
| 1783 | // .WillOnce(Invoke(DistanceToOriginWithIndex)); |
| 1784 | // |
| 1785 | // you could write |
| 1786 | // |
| 1787 | // // We can declare any uninteresting argument as Unused. |
| 1788 | // double DistanceToOrigin(Unused, double x, double y) { |
| 1789 | // return sqrt(x*x + y*y); |
| 1790 | // } |
| 1791 | // ... |
| 1792 | // EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin)); |
| 1793 | // EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin)); |
| 1794 | typedef internal::IgnoredValue Unused; |
| 1795 | |
| 1796 | // This constructor allows us to turn an Action<From> object into an |
| 1797 | // Action<To>, as long as To's arguments can be implicitly converted |
| 1798 | // to From's and From's return type cann be implicitly converted to |
| 1799 | // To's. |
| 1800 | template <typename To> |
| 1801 | template <typename From> |
| 1802 | Action<To>::Action(const Action<From>& from) |
| 1803 | : impl_(new internal::ActionAdaptor<To, From>(from)) {} |
| 1804 | |
| 1805 | // Creates an action that returns 'value'. 'value' is passed by value |
| 1806 | // instead of const reference - otherwise Return("string literal") |
| 1807 | // will trigger a compiler error about using array as initializer. |
| 1808 | template <typename R> |
| 1809 | internal::ReturnAction<R> Return(R value) { |
| 1810 | return internal::ReturnAction<R>(value); |
| 1811 | } |
| 1812 | |
| 1813 | // Creates an action that returns NULL. |
| 1814 | inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() { |
| 1815 | return MakePolymorphicAction(internal::ReturnNullAction()); |
| 1816 | } |
| 1817 | |
| 1818 | // Creates an action that returns from a void function. |
| 1819 | inline PolymorphicAction<internal::ReturnVoidAction> Return() { |
| 1820 | return MakePolymorphicAction(internal::ReturnVoidAction()); |
| 1821 | } |
| 1822 | |
| 1823 | // Creates an action that returns the reference to a variable. |
| 1824 | template <typename R> |
| 1825 | inline internal::ReturnRefAction<R> ReturnRef(R& x) { // NOLINT |
| 1826 | return internal::ReturnRefAction<R>(x); |
| 1827 | } |
| 1828 | |
| 1829 | // Creates an action that returns the reference to a copy of the |
| 1830 | // argument. The copy is created when the action is constructed and |
| 1831 | // lives as long as the action. |
| 1832 | template <typename R> |
| 1833 | inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) { |
| 1834 | return internal::ReturnRefOfCopyAction<R>(x); |
| 1835 | } |
| 1836 | |
| 1837 | // Creates an action that does the default action for the give mock function. |
| 1838 | inline internal::DoDefaultAction DoDefault() { |
| 1839 | return internal::DoDefaultAction(); |
| 1840 | } |
| 1841 | |
| 1842 | // Creates an action that sets the variable pointed by the N-th |
| 1843 | // (0-based) function argument to 'value'. |
| 1844 | template <size_t N, typename T> |
| 1845 | PolymorphicAction< |
| 1846 | internal::SetArgumentPointeeAction< |
| 1847 | N, T, internal::IsAProtocolMessage<T>::value> > |
| 1848 | SetArgPointee(const T& x) { |
| 1849 | return MakePolymorphicAction(internal::SetArgumentPointeeAction< |
| 1850 | N, T, internal::IsAProtocolMessage<T>::value>(x)); |
| 1851 | } |
| 1852 | |
| 1853 | #if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) |
| 1854 | // This overload allows SetArgPointee() to accept a string literal. |
| 1855 | // GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish |
| 1856 | // this overload from the templated version and emit a compile error. |
| 1857 | template <size_t N> |
| 1858 | PolymorphicAction< |
| 1859 | internal::SetArgumentPointeeAction<N, const char*, false> > |
| 1860 | SetArgPointee(const char* p) { |
| 1861 | return MakePolymorphicAction(internal::SetArgumentPointeeAction< |
| 1862 | N, const char*, false>(p)); |
| 1863 | } |
| 1864 | |
| 1865 | template <size_t N> |
| 1866 | PolymorphicAction< |
| 1867 | internal::SetArgumentPointeeAction<N, const wchar_t*, false> > |
| 1868 | SetArgPointee(const wchar_t* p) { |
| 1869 | return MakePolymorphicAction(internal::SetArgumentPointeeAction< |
| 1870 | N, const wchar_t*, false>(p)); |
| 1871 | } |
| 1872 | #endif |
| 1873 | |
| 1874 | // The following version is DEPRECATED. |
| 1875 | template <size_t N, typename T> |
| 1876 | PolymorphicAction< |
| 1877 | internal::SetArgumentPointeeAction< |
| 1878 | N, T, internal::IsAProtocolMessage<T>::value> > |
| 1879 | SetArgumentPointee(const T& x) { |
| 1880 | return MakePolymorphicAction(internal::SetArgumentPointeeAction< |
| 1881 | N, T, internal::IsAProtocolMessage<T>::value>(x)); |
| 1882 | } |
| 1883 | |
| 1884 | // Creates an action that sets a pointer referent to a given value. |
| 1885 | template <typename T1, typename T2> |
| 1886 | PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) { |
| 1887 | return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val)); |
| 1888 | } |
| 1889 | |
| 1890 | #if !GTEST_OS_WINDOWS_MOBILE |
| 1891 | |
| 1892 | // Creates an action that sets errno and returns the appropriate error. |
| 1893 | template <typename T> |
| 1894 | PolymorphicAction<internal::SetErrnoAndReturnAction<T> > |
| 1895 | SetErrnoAndReturn(int errval, T result) { |
| 1896 | return MakePolymorphicAction( |
| 1897 | internal::SetErrnoAndReturnAction<T>(errval, result)); |
| 1898 | } |
| 1899 | |
| 1900 | #endif // !GTEST_OS_WINDOWS_MOBILE |
| 1901 | |
| 1902 | // Various overloads for InvokeWithoutArgs(). |
| 1903 | |
| 1904 | // Creates an action that invokes 'function_impl' with no argument. |
| 1905 | template <typename FunctionImpl> |
| 1906 | PolymorphicAction<internal::InvokeWithoutArgsAction<FunctionImpl> > |
| 1907 | InvokeWithoutArgs(FunctionImpl function_impl) { |
| 1908 | return MakePolymorphicAction( |
| 1909 | internal::InvokeWithoutArgsAction<FunctionImpl>(function_impl)); |
| 1910 | } |
| 1911 | |
| 1912 | // Creates an action that invokes the given method on the given object |
| 1913 | // with no argument. |
| 1914 | template <class Class, typename MethodPtr> |
| 1915 | PolymorphicAction<internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> > |
| 1916 | InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) { |
| 1917 | return MakePolymorphicAction( |
| 1918 | internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>( |
| 1919 | obj_ptr, method_ptr)); |
| 1920 | } |
| 1921 | |
| 1922 | // Creates an action that performs an_action and throws away its |
| 1923 | // result. In other words, it changes the return type of an_action to |
| 1924 | // void. an_action MUST NOT return void, or the code won't compile. |
| 1925 | template <typename A> |
| 1926 | inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) { |
| 1927 | return internal::IgnoreResultAction<A>(an_action); |
| 1928 | } |
| 1929 | |
| 1930 | // Creates a reference wrapper for the given L-value. If necessary, |
| 1931 | // you can explicitly specify the type of the reference. For example, |
| 1932 | // suppose 'derived' is an object of type Derived, ByRef(derived) |
| 1933 | // would wrap a Derived&. If you want to wrap a const Base& instead, |
| 1934 | // where Base is a base class of Derived, just write: |
| 1935 | // |
| 1936 | // ByRef<const Base>(derived) |
| 1937 | template <typename T> |
| 1938 | inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT |
| 1939 | return internal::ReferenceWrapper<T>(l_value); |
| 1940 | } |
| 1941 | |
| 1942 | } // namespace testing |
| 1943 | |
| 1944 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ |
| 1945 | // Copyright 2007, Google Inc. |
| 1946 | // All rights reserved. |
| 1947 | // |
| 1948 | // Redistribution and use in source and binary forms, with or without |
| 1949 | // modification, are permitted provided that the following conditions are |
| 1950 | // met: |
| 1951 | // |
| 1952 | // * Redistributions of source code must retain the above copyright |
| 1953 | // notice, this list of conditions and the following disclaimer. |
| 1954 | // * Redistributions in binary form must reproduce the above |
| 1955 | // copyright notice, this list of conditions and the following disclaimer |
| 1956 | // in the documentation and/or other materials provided with the |
| 1957 | // distribution. |
| 1958 | // * Neither the name of Google Inc. nor the names of its |
| 1959 | // contributors may be used to endorse or promote products derived from |
| 1960 | // this software without specific prior written permission. |
| 1961 | // |
| 1962 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 1963 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 1964 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 1965 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 1966 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 1967 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 1968 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 1969 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 1970 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 1971 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 1972 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 1973 | // |
| 1974 | // Author: wan@google.com (Zhanyong Wan) |
| 1975 | |
| 1976 | // Google Mock - a framework for writing C++ mock classes. |
| 1977 | // |
| 1978 | // This file implements some commonly used cardinalities. More |
| 1979 | // cardinalities can be defined by the user implementing the |
| 1980 | // CardinalityInterface interface if necessary. |
| 1981 | |
| 1982 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ |
| 1983 | #define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ |
| 1984 | |
| 1985 | #include <limits.h> |
| 1986 | #include <ostream> // NOLINT |
| 1987 | |
| 1988 | namespace testing { |
| 1989 | |
| 1990 | // To implement a cardinality Foo, define: |
| 1991 | // 1. a class FooCardinality that implements the |
| 1992 | // CardinalityInterface interface, and |
| 1993 | // 2. a factory function that creates a Cardinality object from a |
| 1994 | // const FooCardinality*. |
| 1995 | // |
| 1996 | // The two-level delegation design follows that of Matcher, providing |
| 1997 | // consistency for extension developers. It also eases ownership |
| 1998 | // management as Cardinality objects can now be copied like plain values. |
| 1999 | |
| 2000 | // The implementation of a cardinality. |
| 2001 | class CardinalityInterface { |
| 2002 | public: |
| 2003 | virtual ~CardinalityInterface() {} |
| 2004 | |
| 2005 | // Conservative estimate on the lower/upper bound of the number of |
| 2006 | // calls allowed. |
| 2007 | virtual int ConservativeLowerBound() const { return 0; } |
| 2008 | virtual int ConservativeUpperBound() const { return INT_MAX; } |
| 2009 | |
| 2010 | // Returns true iff call_count calls will satisfy this cardinality. |
| 2011 | virtual bool IsSatisfiedByCallCount(int call_count) const = 0; |
| 2012 | |
| 2013 | // Returns true iff call_count calls will saturate this cardinality. |
| 2014 | virtual bool IsSaturatedByCallCount(int call_count) const = 0; |
| 2015 | |
| 2016 | // Describes self to an ostream. |
| 2017 | virtual void DescribeTo(::std::ostream* os) const = 0; |
| 2018 | }; |
| 2019 | |
| 2020 | // A Cardinality is a copyable and IMMUTABLE (except by assignment) |
| 2021 | // object that specifies how many times a mock function is expected to |
| 2022 | // be called. The implementation of Cardinality is just a linked_ptr |
| 2023 | // to const CardinalityInterface, so copying is fairly cheap. |
| 2024 | // Don't inherit from Cardinality! |
| 2025 | class Cardinality { |
| 2026 | public: |
| 2027 | // Constructs a null cardinality. Needed for storing Cardinality |
| 2028 | // objects in STL containers. |
| 2029 | Cardinality() {} |
| 2030 | |
| 2031 | // Constructs a Cardinality from its implementation. |
| 2032 | explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {} |
| 2033 | |
| 2034 | // Conservative estimate on the lower/upper bound of the number of |
| 2035 | // calls allowed. |
| 2036 | int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); } |
| 2037 | int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); } |
| 2038 | |
| 2039 | // Returns true iff call_count calls will satisfy this cardinality. |
| 2040 | bool IsSatisfiedByCallCount(int call_count) const { |
| 2041 | return impl_->IsSatisfiedByCallCount(call_count); |
| 2042 | } |
| 2043 | |
| 2044 | // Returns true iff call_count calls will saturate this cardinality. |
| 2045 | bool IsSaturatedByCallCount(int call_count) const { |
| 2046 | return impl_->IsSaturatedByCallCount(call_count); |
| 2047 | } |
| 2048 | |
| 2049 | // Returns true iff call_count calls will over-saturate this |
| 2050 | // cardinality, i.e. exceed the maximum number of allowed calls. |
| 2051 | bool IsOverSaturatedByCallCount(int call_count) const { |
| 2052 | return impl_->IsSaturatedByCallCount(call_count) && |
| 2053 | !impl_->IsSatisfiedByCallCount(call_count); |
| 2054 | } |
| 2055 | |
| 2056 | // Describes self to an ostream |
| 2057 | void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } |
| 2058 | |
| 2059 | // Describes the given actual call count to an ostream. |
| 2060 | static void DescribeActualCallCountTo(int actual_call_count, |
| 2061 | ::std::ostream* os); |
| 2062 | private: |
| 2063 | internal::linked_ptr<const CardinalityInterface> impl_; |
| 2064 | }; |
| 2065 | |
| 2066 | // Creates a cardinality that allows at least n calls. |
| 2067 | Cardinality AtLeast(int n); |
| 2068 | |
| 2069 | // Creates a cardinality that allows at most n calls. |
| 2070 | Cardinality AtMost(int n); |
| 2071 | |
| 2072 | // Creates a cardinality that allows any number of calls. |
| 2073 | Cardinality AnyNumber(); |
| 2074 | |
| 2075 | // Creates a cardinality that allows between min and max calls. |
| 2076 | Cardinality Between(int min, int max); |
| 2077 | |
| 2078 | // Creates a cardinality that allows exactly n calls. |
| 2079 | Cardinality Exactly(int n); |
| 2080 | |
| 2081 | // Creates a cardinality from its implementation. |
| 2082 | inline Cardinality MakeCardinality(const CardinalityInterface* c) { |
| 2083 | return Cardinality(c); |
| 2084 | } |
| 2085 | |
| 2086 | } // namespace testing |
| 2087 | |
| 2088 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ |
| 2089 | // This file was GENERATED by a script. DO NOT EDIT BY HAND!!! |
| 2090 | |
| 2091 | // Copyright 2007, Google Inc. |
| 2092 | // All rights reserved. |
| 2093 | // |
| 2094 | // Redistribution and use in source and binary forms, with or without |
| 2095 | // modification, are permitted provided that the following conditions are |
| 2096 | // met: |
| 2097 | // |
| 2098 | // * Redistributions of source code must retain the above copyright |
| 2099 | // notice, this list of conditions and the following disclaimer. |
| 2100 | // * Redistributions in binary form must reproduce the above |
| 2101 | // copyright notice, this list of conditions and the following disclaimer |
| 2102 | // in the documentation and/or other materials provided with the |
| 2103 | // distribution. |
| 2104 | // * Neither the name of Google Inc. nor the names of its |
| 2105 | // contributors may be used to endorse or promote products derived from |
| 2106 | // this software without specific prior written permission. |
| 2107 | // |
| 2108 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 2109 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 2110 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 2111 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 2112 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 2113 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 2114 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 2115 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 2116 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 2117 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 2118 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 2119 | // |
| 2120 | // Author: wan@google.com (Zhanyong Wan) |
| 2121 | |
| 2122 | // Google Mock - a framework for writing C++ mock classes. |
| 2123 | // |
| 2124 | // This file implements some commonly used variadic actions. |
| 2125 | |
| 2126 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ |
| 2127 | #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ |
| 2128 | |
| 2129 | |
| 2130 | namespace testing { |
| 2131 | namespace internal { |
| 2132 | |
| 2133 | // InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary |
| 2134 | // function or method with the unpacked values, where F is a function |
| 2135 | // type that takes N arguments. |
| 2136 | template <typename Result, typename ArgumentTuple> |
| 2137 | class InvokeHelper; |
| 2138 | |
| 2139 | template <typename R> |
| 2140 | class InvokeHelper<R, ::std::tr1::tuple<> > { |
| 2141 | public: |
| 2142 | template <typename Function> |
| 2143 | static R Invoke(Function function, const ::std::tr1::tuple<>&) { |
| 2144 | return function(); |
| 2145 | } |
| 2146 | |
| 2147 | template <class Class, typename MethodPtr> |
| 2148 | static R InvokeMethod(Class* obj_ptr, |
| 2149 | MethodPtr method_ptr, |
| 2150 | const ::std::tr1::tuple<>&) { |
| 2151 | return (obj_ptr->*method_ptr)(); |
| 2152 | } |
| 2153 | }; |
| 2154 | |
| 2155 | template <typename R, typename A1> |
| 2156 | class InvokeHelper<R, ::std::tr1::tuple<A1> > { |
| 2157 | public: |
| 2158 | template <typename Function> |
| 2159 | static R Invoke(Function function, const ::std::tr1::tuple<A1>& args) { |
| 2160 | using ::std::tr1::get; |
| 2161 | return function(get<0>(args)); |
| 2162 | } |
| 2163 | |
| 2164 | template <class Class, typename MethodPtr> |
| 2165 | static R InvokeMethod(Class* obj_ptr, |
| 2166 | MethodPtr method_ptr, |
| 2167 | const ::std::tr1::tuple<A1>& args) { |
| 2168 | using ::std::tr1::get; |
| 2169 | return (obj_ptr->*method_ptr)(get<0>(args)); |
| 2170 | } |
| 2171 | }; |
| 2172 | |
| 2173 | template <typename R, typename A1, typename A2> |
| 2174 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2> > { |
| 2175 | public: |
| 2176 | template <typename Function> |
| 2177 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2>& args) { |
| 2178 | using ::std::tr1::get; |
| 2179 | return function(get<0>(args), get<1>(args)); |
| 2180 | } |
| 2181 | |
| 2182 | template <class Class, typename MethodPtr> |
| 2183 | static R InvokeMethod(Class* obj_ptr, |
| 2184 | MethodPtr method_ptr, |
| 2185 | const ::std::tr1::tuple<A1, A2>& args) { |
| 2186 | using ::std::tr1::get; |
| 2187 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args)); |
| 2188 | } |
| 2189 | }; |
| 2190 | |
| 2191 | template <typename R, typename A1, typename A2, typename A3> |
| 2192 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3> > { |
| 2193 | public: |
| 2194 | template <typename Function> |
| 2195 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, |
| 2196 | A3>& args) { |
| 2197 | using ::std::tr1::get; |
| 2198 | return function(get<0>(args), get<1>(args), get<2>(args)); |
| 2199 | } |
| 2200 | |
| 2201 | template <class Class, typename MethodPtr> |
| 2202 | static R InvokeMethod(Class* obj_ptr, |
| 2203 | MethodPtr method_ptr, |
| 2204 | const ::std::tr1::tuple<A1, A2, A3>& args) { |
| 2205 | using ::std::tr1::get; |
| 2206 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args)); |
| 2207 | } |
| 2208 | }; |
| 2209 | |
| 2210 | template <typename R, typename A1, typename A2, typename A3, typename A4> |
| 2211 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4> > { |
| 2212 | public: |
| 2213 | template <typename Function> |
| 2214 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, |
| 2215 | A4>& args) { |
| 2216 | using ::std::tr1::get; |
| 2217 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args)); |
| 2218 | } |
| 2219 | |
| 2220 | template <class Class, typename MethodPtr> |
| 2221 | static R InvokeMethod(Class* obj_ptr, |
| 2222 | MethodPtr method_ptr, |
| 2223 | const ::std::tr1::tuple<A1, A2, A3, A4>& args) { |
| 2224 | using ::std::tr1::get; |
| 2225 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 2226 | get<3>(args)); |
| 2227 | } |
| 2228 | }; |
| 2229 | |
| 2230 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 2231 | typename A5> |
| 2232 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5> > { |
| 2233 | public: |
| 2234 | template <typename Function> |
| 2235 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 2236 | A5>& args) { |
| 2237 | using ::std::tr1::get; |
| 2238 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 2239 | get<4>(args)); |
| 2240 | } |
| 2241 | |
| 2242 | template <class Class, typename MethodPtr> |
| 2243 | static R InvokeMethod(Class* obj_ptr, |
| 2244 | MethodPtr method_ptr, |
| 2245 | const ::std::tr1::tuple<A1, A2, A3, A4, A5>& args) { |
| 2246 | using ::std::tr1::get; |
| 2247 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 2248 | get<3>(args), get<4>(args)); |
| 2249 | } |
| 2250 | }; |
| 2251 | |
| 2252 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 2253 | typename A5, typename A6> |
| 2254 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > { |
| 2255 | public: |
| 2256 | template <typename Function> |
| 2257 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 2258 | A5, A6>& args) { |
| 2259 | using ::std::tr1::get; |
| 2260 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 2261 | get<4>(args), get<5>(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, A5, A6>& 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), get<4>(args), get<5>(args)); |
| 2271 | } |
| 2272 | }; |
| 2273 | |
| 2274 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 2275 | typename A5, typename A6, typename A7> |
| 2276 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > { |
| 2277 | public: |
| 2278 | template <typename Function> |
| 2279 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 2280 | A5, A6, A7>& 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), get<5>(args), get<6>(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, A6, |
| 2290 | A7>& args) { |
| 2291 | using ::std::tr1::get; |
| 2292 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 2293 | get<3>(args), get<4>(args), get<5>(args), get<6>(args)); |
| 2294 | } |
| 2295 | }; |
| 2296 | |
| 2297 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 2298 | typename A5, typename A6, typename A7, typename A8> |
| 2299 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > { |
| 2300 | public: |
| 2301 | template <typename Function> |
| 2302 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 2303 | A5, A6, A7, A8>& args) { |
| 2304 | using ::std::tr1::get; |
| 2305 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 2306 | get<4>(args), get<5>(args), get<6>(args), get<7>(args)); |
| 2307 | } |
| 2308 | |
| 2309 | template <class Class, typename MethodPtr> |
| 2310 | static R InvokeMethod(Class* obj_ptr, |
| 2311 | MethodPtr method_ptr, |
| 2312 | const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, |
| 2313 | A8>& args) { |
| 2314 | using ::std::tr1::get; |
| 2315 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 2316 | get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args)); |
| 2317 | } |
| 2318 | }; |
| 2319 | |
| 2320 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 2321 | typename A5, typename A6, typename A7, typename A8, typename A9> |
| 2322 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > { |
| 2323 | public: |
| 2324 | template <typename Function> |
| 2325 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 2326 | A5, A6, A7, A8, A9>& args) { |
| 2327 | using ::std::tr1::get; |
| 2328 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 2329 | get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args)); |
| 2330 | } |
| 2331 | |
| 2332 | template <class Class, typename MethodPtr> |
| 2333 | static R InvokeMethod(Class* obj_ptr, |
| 2334 | MethodPtr method_ptr, |
| 2335 | const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, |
| 2336 | A9>& args) { |
| 2337 | using ::std::tr1::get; |
| 2338 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 2339 | get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), |
| 2340 | get<8>(args)); |
| 2341 | } |
| 2342 | }; |
| 2343 | |
| 2344 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 2345 | typename A5, typename A6, typename A7, typename A8, typename A9, |
| 2346 | typename A10> |
| 2347 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, |
| 2348 | A10> > { |
| 2349 | public: |
| 2350 | template <typename Function> |
| 2351 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 2352 | A5, A6, A7, A8, A9, A10>& args) { |
| 2353 | using ::std::tr1::get; |
| 2354 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 2355 | get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), |
| 2356 | get<9>(args)); |
| 2357 | } |
| 2358 | |
| 2359 | template <class Class, typename MethodPtr> |
| 2360 | static R InvokeMethod(Class* obj_ptr, |
| 2361 | MethodPtr method_ptr, |
| 2362 | const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, |
| 2363 | A9, A10>& args) { |
| 2364 | using ::std::tr1::get; |
| 2365 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 2366 | get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), |
| 2367 | get<8>(args), get<9>(args)); |
| 2368 | } |
| 2369 | }; |
| 2370 | |
| 2371 | // CallableHelper has static methods for invoking "callables", |
| 2372 | // i.e. function pointers and functors. It uses overloading to |
| 2373 | // provide a uniform interface for invoking different kinds of |
| 2374 | // callables. In particular, you can use: |
| 2375 | // |
| 2376 | // CallableHelper<R>::Call(callable, a1, a2, ..., an) |
| 2377 | // |
| 2378 | // to invoke an n-ary callable, where R is its return type. If an |
| 2379 | // argument, say a2, needs to be passed by reference, you should write |
| 2380 | // ByRef(a2) instead of a2 in the above expression. |
| 2381 | template <typename R> |
| 2382 | class CallableHelper { |
| 2383 | public: |
| 2384 | // Calls a nullary callable. |
| 2385 | template <typename Function> |
| 2386 | static R Call(Function function) { return function(); } |
| 2387 | |
| 2388 | // Calls a unary callable. |
| 2389 | |
| 2390 | // We deliberately pass a1 by value instead of const reference here |
| 2391 | // in case it is a C-string literal. If we had declared the |
| 2392 | // parameter as 'const A1& a1' and write Call(function, "Hi"), the |
| 2393 | // compiler would've thought A1 is 'char[3]', which causes trouble |
| 2394 | // when you need to copy a value of type A1. By declaring the |
| 2395 | // parameter as 'A1 a1', the compiler will correctly infer that A1 |
| 2396 | // is 'const char*' when it sees Call(function, "Hi"). |
| 2397 | // |
| 2398 | // Since this function is defined inline, the compiler can get rid |
| 2399 | // of the copying of the arguments. Therefore the performance won't |
| 2400 | // be hurt. |
| 2401 | template <typename Function, typename A1> |
| 2402 | static R Call(Function function, A1 a1) { return function(a1); } |
| 2403 | |
| 2404 | // Calls a binary callable. |
| 2405 | template <typename Function, typename A1, typename A2> |
| 2406 | static R Call(Function function, A1 a1, A2 a2) { |
| 2407 | return function(a1, a2); |
| 2408 | } |
| 2409 | |
| 2410 | // Calls a ternary callable. |
| 2411 | template <typename Function, typename A1, typename A2, typename A3> |
| 2412 | static R Call(Function function, A1 a1, A2 a2, A3 a3) { |
| 2413 | return function(a1, a2, a3); |
| 2414 | } |
| 2415 | |
| 2416 | // Calls a 4-ary callable. |
| 2417 | template <typename Function, typename A1, typename A2, typename A3, |
| 2418 | typename A4> |
| 2419 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4) { |
| 2420 | return function(a1, a2, a3, a4); |
| 2421 | } |
| 2422 | |
| 2423 | // Calls a 5-ary callable. |
| 2424 | template <typename Function, typename A1, typename A2, typename A3, |
| 2425 | typename A4, typename A5> |
| 2426 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { |
| 2427 | return function(a1, a2, a3, a4, a5); |
| 2428 | } |
| 2429 | |
| 2430 | // Calls a 6-ary callable. |
| 2431 | template <typename Function, typename A1, typename A2, typename A3, |
| 2432 | typename A4, typename A5, typename A6> |
| 2433 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { |
| 2434 | return function(a1, a2, a3, a4, a5, a6); |
| 2435 | } |
| 2436 | |
| 2437 | // Calls a 7-ary callable. |
| 2438 | template <typename Function, typename A1, typename A2, typename A3, |
| 2439 | typename A4, typename A5, typename A6, typename A7> |
| 2440 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, |
| 2441 | A7 a7) { |
| 2442 | return function(a1, a2, a3, a4, a5, a6, a7); |
| 2443 | } |
| 2444 | |
| 2445 | // Calls a 8-ary callable. |
| 2446 | template <typename Function, typename A1, typename A2, typename A3, |
| 2447 | typename A4, typename A5, typename A6, typename A7, typename A8> |
| 2448 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, |
| 2449 | A7 a7, A8 a8) { |
| 2450 | return function(a1, a2, a3, a4, a5, a6, a7, a8); |
| 2451 | } |
| 2452 | |
| 2453 | // Calls a 9-ary callable. |
| 2454 | template <typename Function, typename A1, typename A2, typename A3, |
| 2455 | typename A4, typename A5, typename A6, typename A7, typename A8, |
| 2456 | typename A9> |
| 2457 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, |
| 2458 | A7 a7, A8 a8, A9 a9) { |
| 2459 | return function(a1, a2, a3, a4, a5, a6, a7, a8, a9); |
| 2460 | } |
| 2461 | |
| 2462 | // Calls a 10-ary callable. |
| 2463 | template <typename Function, typename A1, typename A2, typename A3, |
| 2464 | typename A4, typename A5, typename A6, typename A7, typename A8, |
| 2465 | typename A9, typename A10> |
| 2466 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, |
| 2467 | A7 a7, A8 a8, A9 a9, A10 a10) { |
| 2468 | return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); |
| 2469 | } |
| 2470 | |
| 2471 | }; // class CallableHelper |
| 2472 | |
| 2473 | // An INTERNAL macro for extracting the type of a tuple field. It's |
| 2474 | // subject to change without notice - DO NOT USE IN USER CODE! |
| 2475 | #define GMOCK_FIELD_(Tuple, N) \ |
| 2476 | typename ::std::tr1::tuple_element<N, Tuple>::type |
| 2477 | |
| 2478 | // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the |
| 2479 | // type of an n-ary function whose i-th (1-based) argument type is the |
| 2480 | // k{i}-th (0-based) field of ArgumentTuple, which must be a tuple |
| 2481 | // type, and whose return type is Result. For example, |
| 2482 | // SelectArgs<int, ::std::tr1::tuple<bool, char, double, long>, 0, 3>::type |
| 2483 | // is int(bool, long). |
| 2484 | // |
| 2485 | // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args) |
| 2486 | // returns the selected fields (k1, k2, ..., k_n) of args as a tuple. |
| 2487 | // For example, |
| 2488 | // SelectArgs<int, ::std::tr1::tuple<bool, char, double>, 2, 0>::Select( |
| 2489 | // ::std::tr1::make_tuple(true, 'a', 2.5)) |
| 2490 | // returns ::std::tr1::tuple (2.5, true). |
| 2491 | // |
| 2492 | // The numbers in list k1, k2, ..., k_n must be >= 0, where n can be |
| 2493 | // in the range [0, 10]. Duplicates are allowed and they don't have |
| 2494 | // to be in an ascending or descending order. |
| 2495 | |
| 2496 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 2497 | int k4, int k5, int k6, int k7, int k8, int k9, int k10> |
| 2498 | class SelectArgs { |
| 2499 | public: |
| 2500 | typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), |
| 2501 | GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), |
| 2502 | GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), |
| 2503 | GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), |
| 2504 | GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9), |
| 2505 | GMOCK_FIELD_(ArgumentTuple, k10)); |
| 2506 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 2507 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 2508 | using ::std::tr1::get; |
| 2509 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 2510 | get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args), |
| 2511 | get<k8>(args), get<k9>(args), get<k10>(args)); |
| 2512 | } |
| 2513 | }; |
| 2514 | |
| 2515 | template <typename Result, typename ArgumentTuple> |
| 2516 | class SelectArgs<Result, ArgumentTuple, |
| 2517 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { |
| 2518 | public: |
| 2519 | typedef Result type(); |
| 2520 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 2521 | static SelectedArgs Select(const ArgumentTuple& /* args */) { |
| 2522 | using ::std::tr1::get; |
| 2523 | return SelectedArgs(); |
| 2524 | } |
| 2525 | }; |
| 2526 | |
| 2527 | template <typename Result, typename ArgumentTuple, int k1> |
| 2528 | class SelectArgs<Result, ArgumentTuple, |
| 2529 | k1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { |
| 2530 | public: |
| 2531 | typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1)); |
| 2532 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 2533 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 2534 | using ::std::tr1::get; |
| 2535 | return SelectedArgs(get<k1>(args)); |
| 2536 | } |
| 2537 | }; |
| 2538 | |
| 2539 | template <typename Result, typename ArgumentTuple, int k1, int k2> |
| 2540 | class SelectArgs<Result, ArgumentTuple, |
| 2541 | k1, k2, -1, -1, -1, -1, -1, -1, -1, -1> { |
| 2542 | public: |
| 2543 | typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), |
| 2544 | GMOCK_FIELD_(ArgumentTuple, k2)); |
| 2545 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 2546 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 2547 | using ::std::tr1::get; |
| 2548 | return SelectedArgs(get<k1>(args), get<k2>(args)); |
| 2549 | } |
| 2550 | }; |
| 2551 | |
| 2552 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3> |
| 2553 | class SelectArgs<Result, ArgumentTuple, |
| 2554 | k1, k2, k3, -1, -1, -1, -1, -1, -1, -1> { |
| 2555 | public: |
| 2556 | typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), |
| 2557 | GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3)); |
| 2558 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 2559 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 2560 | using ::std::tr1::get; |
| 2561 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args)); |
| 2562 | } |
| 2563 | }; |
| 2564 | |
| 2565 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 2566 | int k4> |
| 2567 | class SelectArgs<Result, ArgumentTuple, |
| 2568 | k1, k2, k3, k4, -1, -1, -1, -1, -1, -1> { |
| 2569 | public: |
| 2570 | typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), |
| 2571 | GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), |
| 2572 | GMOCK_FIELD_(ArgumentTuple, k4)); |
| 2573 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 2574 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 2575 | using ::std::tr1::get; |
| 2576 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 2577 | get<k4>(args)); |
| 2578 | } |
| 2579 | }; |
| 2580 | |
| 2581 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 2582 | int k4, int k5> |
| 2583 | class SelectArgs<Result, ArgumentTuple, |
| 2584 | k1, k2, k3, k4, k5, -1, -1, -1, -1, -1> { |
| 2585 | public: |
| 2586 | typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), |
| 2587 | GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), |
| 2588 | GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5)); |
| 2589 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 2590 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 2591 | using ::std::tr1::get; |
| 2592 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 2593 | get<k4>(args), get<k5>(args)); |
| 2594 | } |
| 2595 | }; |
| 2596 | |
| 2597 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 2598 | int k4, int k5, int k6> |
| 2599 | class SelectArgs<Result, ArgumentTuple, |
| 2600 | k1, k2, k3, k4, k5, k6, -1, -1, -1, -1> { |
| 2601 | public: |
| 2602 | typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), |
| 2603 | GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), |
| 2604 | GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), |
| 2605 | GMOCK_FIELD_(ArgumentTuple, k6)); |
| 2606 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 2607 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 2608 | using ::std::tr1::get; |
| 2609 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 2610 | get<k4>(args), get<k5>(args), get<k6>(args)); |
| 2611 | } |
| 2612 | }; |
| 2613 | |
| 2614 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 2615 | int k4, int k5, int k6, int k7> |
| 2616 | class SelectArgs<Result, ArgumentTuple, |
| 2617 | k1, k2, k3, k4, k5, k6, k7, -1, -1, -1> { |
| 2618 | public: |
| 2619 | typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), |
| 2620 | GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), |
| 2621 | GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), |
| 2622 | GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7)); |
| 2623 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 2624 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 2625 | using ::std::tr1::get; |
| 2626 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 2627 | get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args)); |
| 2628 | } |
| 2629 | }; |
| 2630 | |
| 2631 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 2632 | int k4, int k5, int k6, int k7, int k8> |
| 2633 | class SelectArgs<Result, ArgumentTuple, |
| 2634 | k1, k2, k3, k4, k5, k6, k7, k8, -1, -1> { |
| 2635 | public: |
| 2636 | typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), |
| 2637 | GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), |
| 2638 | GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), |
| 2639 | GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), |
| 2640 | GMOCK_FIELD_(ArgumentTuple, k8)); |
| 2641 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 2642 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 2643 | using ::std::tr1::get; |
| 2644 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 2645 | get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args), |
| 2646 | get<k8>(args)); |
| 2647 | } |
| 2648 | }; |
| 2649 | |
| 2650 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 2651 | int k4, int k5, int k6, int k7, int k8, int k9> |
| 2652 | class SelectArgs<Result, ArgumentTuple, |
| 2653 | k1, k2, k3, k4, k5, k6, k7, k8, k9, -1> { |
| 2654 | public: |
| 2655 | typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), |
| 2656 | GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), |
| 2657 | GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), |
| 2658 | GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), |
| 2659 | GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9)); |
| 2660 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 2661 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 2662 | using ::std::tr1::get; |
| 2663 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 2664 | get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args), |
| 2665 | get<k8>(args), get<k9>(args)); |
| 2666 | } |
| 2667 | }; |
| 2668 | |
| 2669 | #undef GMOCK_FIELD_ |
| 2670 | |
| 2671 | // Implements the WithArgs action. |
| 2672 | template <typename InnerAction, int k1 = -1, int k2 = -1, int k3 = -1, |
| 2673 | int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1, |
| 2674 | int k9 = -1, int k10 = -1> |
| 2675 | class WithArgsAction { |
| 2676 | public: |
| 2677 | explicit WithArgsAction(const InnerAction& action) : action_(action) {} |
| 2678 | |
| 2679 | template <typename F> |
| 2680 | operator Action<F>() const { return MakeAction(new Impl<F>(action_)); } |
| 2681 | |
| 2682 | private: |
| 2683 | template <typename F> |
| 2684 | class Impl : public ActionInterface<F> { |
| 2685 | public: |
| 2686 | typedef typename Function<F>::Result Result; |
| 2687 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 2688 | |
| 2689 | explicit Impl(const InnerAction& action) : action_(action) {} |
| 2690 | |
| 2691 | virtual Result Perform(const ArgumentTuple& args) { |
| 2692 | return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, k4, |
| 2693 | k5, k6, k7, k8, k9, k10>::Select(args)); |
| 2694 | } |
| 2695 | |
| 2696 | private: |
| 2697 | typedef typename SelectArgs<Result, ArgumentTuple, |
| 2698 | k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType; |
| 2699 | |
| 2700 | Action<InnerFunctionType> action_; |
| 2701 | }; |
| 2702 | |
| 2703 | const InnerAction action_; |
| 2704 | |
| 2705 | GTEST_DISALLOW_ASSIGN_(WithArgsAction); |
| 2706 | }; |
| 2707 | |
| 2708 | // A macro from the ACTION* family (defined later in this file) |
| 2709 | // defines an action that can be used in a mock function. Typically, |
| 2710 | // these actions only care about a subset of the arguments of the mock |
| 2711 | // function. For example, if such an action only uses the second |
| 2712 | // argument, it can be used in any mock function that takes >= 2 |
| 2713 | // arguments where the type of the second argument is compatible. |
| 2714 | // |
| 2715 | // Therefore, the action implementation must be prepared to take more |
| 2716 | // arguments than it needs. The ExcessiveArg type is used to |
| 2717 | // represent those excessive arguments. In order to keep the compiler |
| 2718 | // error messages tractable, we define it in the testing namespace |
| 2719 | // instead of testing::internal. However, this is an INTERNAL TYPE |
| 2720 | // and subject to change without notice, so a user MUST NOT USE THIS |
| 2721 | // TYPE DIRECTLY. |
| 2722 | struct ExcessiveArg {}; |
| 2723 | |
| 2724 | // A helper class needed for implementing the ACTION* macros. |
| 2725 | template <typename Result, class Impl> |
| 2726 | class ActionHelper { |
| 2727 | public: |
| 2728 | static Result Perform(Impl* impl, const ::std::tr1::tuple<>& args) { |
| 2729 | using ::std::tr1::get; |
| 2730 | return impl->template gmock_PerformImpl<>(args, ExcessiveArg(), |
| 2731 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 2732 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 2733 | ExcessiveArg()); |
| 2734 | } |
| 2735 | |
| 2736 | template <typename A0> |
| 2737 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0>& args) { |
| 2738 | using ::std::tr1::get; |
| 2739 | return impl->template gmock_PerformImpl<A0>(args, get<0>(args), |
| 2740 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 2741 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 2742 | ExcessiveArg()); |
| 2743 | } |
| 2744 | |
| 2745 | template <typename A0, typename A1> |
| 2746 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1>& args) { |
| 2747 | using ::std::tr1::get; |
| 2748 | return impl->template gmock_PerformImpl<A0, A1>(args, get<0>(args), |
| 2749 | get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 2750 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 2751 | ExcessiveArg()); |
| 2752 | } |
| 2753 | |
| 2754 | template <typename A0, typename A1, typename A2> |
| 2755 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2>& args) { |
| 2756 | using ::std::tr1::get; |
| 2757 | return impl->template gmock_PerformImpl<A0, A1, A2>(args, get<0>(args), |
| 2758 | get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(), |
| 2759 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 2760 | ExcessiveArg()); |
| 2761 | } |
| 2762 | |
| 2763 | template <typename A0, typename A1, typename A2, typename A3> |
| 2764 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, |
| 2765 | A3>& args) { |
| 2766 | using ::std::tr1::get; |
| 2767 | return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args, get<0>(args), |
| 2768 | get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(), |
| 2769 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 2770 | ExcessiveArg()); |
| 2771 | } |
| 2772 | |
| 2773 | template <typename A0, typename A1, typename A2, typename A3, typename A4> |
| 2774 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, |
| 2775 | A4>& args) { |
| 2776 | using ::std::tr1::get; |
| 2777 | return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args, |
| 2778 | get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), |
| 2779 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 2780 | ExcessiveArg()); |
| 2781 | } |
| 2782 | |
| 2783 | template <typename A0, typename A1, typename A2, typename A3, typename A4, |
| 2784 | typename A5> |
| 2785 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, |
| 2786 | A5>& args) { |
| 2787 | using ::std::tr1::get; |
| 2788 | return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args, |
| 2789 | get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), |
| 2790 | get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 2791 | ExcessiveArg()); |
| 2792 | } |
| 2793 | |
| 2794 | template <typename A0, typename A1, typename A2, typename A3, typename A4, |
| 2795 | typename A5, typename A6> |
| 2796 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, |
| 2797 | A5, A6>& args) { |
| 2798 | using ::std::tr1::get; |
| 2799 | return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args, |
| 2800 | get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), |
| 2801 | get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(), |
| 2802 | ExcessiveArg()); |
| 2803 | } |
| 2804 | |
| 2805 | template <typename A0, typename A1, typename A2, typename A3, typename A4, |
| 2806 | typename A5, typename A6, typename A7> |
| 2807 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, |
| 2808 | A5, A6, A7>& args) { |
| 2809 | using ::std::tr1::get; |
| 2810 | return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, |
| 2811 | A7>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 2812 | get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(), |
| 2813 | ExcessiveArg()); |
| 2814 | } |
| 2815 | |
| 2816 | template <typename A0, typename A1, typename A2, typename A3, typename A4, |
| 2817 | typename A5, typename A6, typename A7, typename A8> |
| 2818 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, |
| 2819 | A5, A6, A7, A8>& args) { |
| 2820 | using ::std::tr1::get; |
| 2821 | return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, |
| 2822 | A8>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 2823 | get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), |
| 2824 | ExcessiveArg()); |
| 2825 | } |
| 2826 | |
| 2827 | template <typename A0, typename A1, typename A2, typename A3, typename A4, |
| 2828 | typename A5, typename A6, typename A7, typename A8, typename A9> |
| 2829 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, |
| 2830 | A5, A6, A7, A8, A9>& args) { |
| 2831 | using ::std::tr1::get; |
| 2832 | return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8, |
| 2833 | A9>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 2834 | get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), |
| 2835 | get<9>(args)); |
| 2836 | } |
| 2837 | }; |
| 2838 | |
| 2839 | } // namespace internal |
| 2840 | |
| 2841 | // Various overloads for Invoke(). |
| 2842 | |
| 2843 | // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes |
| 2844 | // the selected arguments of the mock function to an_action and |
| 2845 | // performs it. It serves as an adaptor between actions with |
| 2846 | // different argument lists. C++ doesn't support default arguments for |
| 2847 | // function templates, so we have to overload it. |
| 2848 | template <int k1, typename InnerAction> |
| 2849 | inline internal::WithArgsAction<InnerAction, k1> |
| 2850 | WithArgs(const InnerAction& action) { |
| 2851 | return internal::WithArgsAction<InnerAction, k1>(action); |
| 2852 | } |
| 2853 | |
| 2854 | template <int k1, int k2, typename InnerAction> |
| 2855 | inline internal::WithArgsAction<InnerAction, k1, k2> |
| 2856 | WithArgs(const InnerAction& action) { |
| 2857 | return internal::WithArgsAction<InnerAction, k1, k2>(action); |
| 2858 | } |
| 2859 | |
| 2860 | template <int k1, int k2, int k3, typename InnerAction> |
| 2861 | inline internal::WithArgsAction<InnerAction, k1, k2, k3> |
| 2862 | WithArgs(const InnerAction& action) { |
| 2863 | return internal::WithArgsAction<InnerAction, k1, k2, k3>(action); |
| 2864 | } |
| 2865 | |
| 2866 | template <int k1, int k2, int k3, int k4, typename InnerAction> |
| 2867 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4> |
| 2868 | WithArgs(const InnerAction& action) { |
| 2869 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action); |
| 2870 | } |
| 2871 | |
| 2872 | template <int k1, int k2, int k3, int k4, int k5, typename InnerAction> |
| 2873 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5> |
| 2874 | WithArgs(const InnerAction& action) { |
| 2875 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action); |
| 2876 | } |
| 2877 | |
| 2878 | template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction> |
| 2879 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6> |
| 2880 | WithArgs(const InnerAction& action) { |
| 2881 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action); |
| 2882 | } |
| 2883 | |
| 2884 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, |
| 2885 | typename InnerAction> |
| 2886 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7> |
| 2887 | WithArgs(const InnerAction& action) { |
| 2888 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, |
| 2889 | k7>(action); |
| 2890 | } |
| 2891 | |
| 2892 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, |
| 2893 | typename InnerAction> |
| 2894 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8> |
| 2895 | WithArgs(const InnerAction& action) { |
| 2896 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, |
| 2897 | k8>(action); |
| 2898 | } |
| 2899 | |
| 2900 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, |
| 2901 | int k9, typename InnerAction> |
| 2902 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9> |
| 2903 | WithArgs(const InnerAction& action) { |
| 2904 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, |
| 2905 | k9>(action); |
| 2906 | } |
| 2907 | |
| 2908 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, |
| 2909 | int k9, int k10, typename InnerAction> |
| 2910 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, |
| 2911 | k9, k10> |
| 2912 | WithArgs(const InnerAction& action) { |
| 2913 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, |
| 2914 | k9, k10>(action); |
| 2915 | } |
| 2916 | |
| 2917 | // Creates an action that does actions a1, a2, ..., sequentially in |
| 2918 | // each invocation. |
| 2919 | template <typename Action1, typename Action2> |
| 2920 | inline internal::DoBothAction<Action1, Action2> |
| 2921 | DoAll(Action1 a1, Action2 a2) { |
| 2922 | return internal::DoBothAction<Action1, Action2>(a1, a2); |
| 2923 | } |
| 2924 | |
| 2925 | template <typename Action1, typename Action2, typename Action3> |
| 2926 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 2927 | Action3> > |
| 2928 | DoAll(Action1 a1, Action2 a2, Action3 a3) { |
| 2929 | return DoAll(a1, DoAll(a2, a3)); |
| 2930 | } |
| 2931 | |
| 2932 | template <typename Action1, typename Action2, typename Action3, |
| 2933 | typename Action4> |
| 2934 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 2935 | internal::DoBothAction<Action3, Action4> > > |
| 2936 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) { |
| 2937 | return DoAll(a1, DoAll(a2, a3, a4)); |
| 2938 | } |
| 2939 | |
| 2940 | template <typename Action1, typename Action2, typename Action3, |
| 2941 | typename Action4, typename Action5> |
| 2942 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 2943 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 2944 | Action5> > > > |
| 2945 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) { |
| 2946 | return DoAll(a1, DoAll(a2, a3, a4, a5)); |
| 2947 | } |
| 2948 | |
| 2949 | template <typename Action1, typename Action2, typename Action3, |
| 2950 | typename Action4, typename Action5, typename Action6> |
| 2951 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 2952 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 2953 | internal::DoBothAction<Action5, Action6> > > > > |
| 2954 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) { |
| 2955 | return DoAll(a1, DoAll(a2, a3, a4, a5, a6)); |
| 2956 | } |
| 2957 | |
| 2958 | template <typename Action1, typename Action2, typename Action3, |
| 2959 | typename Action4, typename Action5, typename Action6, typename Action7> |
| 2960 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 2961 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 2962 | internal::DoBothAction<Action5, internal::DoBothAction<Action6, |
| 2963 | Action7> > > > > > |
| 2964 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, |
| 2965 | Action7 a7) { |
| 2966 | return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7)); |
| 2967 | } |
| 2968 | |
| 2969 | template <typename Action1, typename Action2, typename Action3, |
| 2970 | typename Action4, typename Action5, typename Action6, typename Action7, |
| 2971 | typename Action8> |
| 2972 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 2973 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 2974 | internal::DoBothAction<Action5, internal::DoBothAction<Action6, |
| 2975 | internal::DoBothAction<Action7, Action8> > > > > > > |
| 2976 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, |
| 2977 | Action7 a7, Action8 a8) { |
| 2978 | return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8)); |
| 2979 | } |
| 2980 | |
| 2981 | template <typename Action1, typename Action2, typename Action3, |
| 2982 | typename Action4, typename Action5, typename Action6, typename Action7, |
| 2983 | typename Action8, typename Action9> |
| 2984 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 2985 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 2986 | internal::DoBothAction<Action5, internal::DoBothAction<Action6, |
| 2987 | internal::DoBothAction<Action7, internal::DoBothAction<Action8, |
| 2988 | Action9> > > > > > > > |
| 2989 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, |
| 2990 | Action7 a7, Action8 a8, Action9 a9) { |
| 2991 | return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9)); |
| 2992 | } |
| 2993 | |
| 2994 | template <typename Action1, typename Action2, typename Action3, |
| 2995 | typename Action4, typename Action5, typename Action6, typename Action7, |
| 2996 | typename Action8, typename Action9, typename Action10> |
| 2997 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 2998 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 2999 | internal::DoBothAction<Action5, internal::DoBothAction<Action6, |
| 3000 | internal::DoBothAction<Action7, internal::DoBothAction<Action8, |
| 3001 | internal::DoBothAction<Action9, Action10> > > > > > > > > |
| 3002 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, |
| 3003 | Action7 a7, Action8 a8, Action9 a9, Action10 a10) { |
| 3004 | return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10)); |
| 3005 | } |
| 3006 | |
| 3007 | } // namespace testing |
| 3008 | |
| 3009 | // The ACTION* family of macros can be used in a namespace scope to |
| 3010 | // define custom actions easily. The syntax: |
| 3011 | // |
| 3012 | // ACTION(name) { statements; } |
| 3013 | // |
| 3014 | // will define an action with the given name that executes the |
| 3015 | // statements. The value returned by the statements will be used as |
| 3016 | // the return value of the action. Inside the statements, you can |
| 3017 | // refer to the K-th (0-based) argument of the mock function by |
| 3018 | // 'argK', and refer to its type by 'argK_type'. For example: |
| 3019 | // |
| 3020 | // ACTION(IncrementArg1) { |
| 3021 | // arg1_type temp = arg1; |
| 3022 | // return ++(*temp); |
| 3023 | // } |
| 3024 | // |
| 3025 | // allows you to write |
| 3026 | // |
| 3027 | // ...WillOnce(IncrementArg1()); |
| 3028 | // |
| 3029 | // You can also refer to the entire argument tuple and its type by |
| 3030 | // 'args' and 'args_type', and refer to the mock function type and its |
| 3031 | // return type by 'function_type' and 'return_type'. |
| 3032 | // |
| 3033 | // Note that you don't need to specify the types of the mock function |
| 3034 | // arguments. However rest assured that your code is still type-safe: |
| 3035 | // you'll get a compiler error if *arg1 doesn't support the ++ |
| 3036 | // operator, or if the type of ++(*arg1) isn't compatible with the |
| 3037 | // mock function's return type, for example. |
| 3038 | // |
| 3039 | // Sometimes you'll want to parameterize the action. For that you can use |
| 3040 | // another macro: |
| 3041 | // |
| 3042 | // ACTION_P(name, param_name) { statements; } |
| 3043 | // |
| 3044 | // For example: |
| 3045 | // |
| 3046 | // ACTION_P(Add, n) { return arg0 + n; } |
| 3047 | // |
| 3048 | // will allow you to write: |
| 3049 | // |
| 3050 | // ...WillOnce(Add(5)); |
| 3051 | // |
| 3052 | // Note that you don't need to provide the type of the parameter |
| 3053 | // either. If you need to reference the type of a parameter named |
| 3054 | // 'foo', you can write 'foo_type'. For example, in the body of |
| 3055 | // ACTION_P(Add, n) above, you can write 'n_type' to refer to the type |
| 3056 | // of 'n'. |
| 3057 | // |
| 3058 | // We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support |
| 3059 | // multi-parameter actions. |
| 3060 | // |
| 3061 | // For the purpose of typing, you can view |
| 3062 | // |
| 3063 | // ACTION_Pk(Foo, p1, ..., pk) { ... } |
| 3064 | // |
| 3065 | // as shorthand for |
| 3066 | // |
| 3067 | // template <typename p1_type, ..., typename pk_type> |
| 3068 | // FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... } |
| 3069 | // |
| 3070 | // In particular, you can provide the template type arguments |
| 3071 | // explicitly when invoking Foo(), as in Foo<long, bool>(5, false); |
| 3072 | // although usually you can rely on the compiler to infer the types |
| 3073 | // for you automatically. You can assign the result of expression |
| 3074 | // Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ..., |
| 3075 | // pk_type>. This can be useful when composing actions. |
| 3076 | // |
| 3077 | // You can also overload actions with different numbers of parameters: |
| 3078 | // |
| 3079 | // ACTION_P(Plus, a) { ... } |
| 3080 | // ACTION_P2(Plus, a, b) { ... } |
| 3081 | // |
| 3082 | // While it's tempting to always use the ACTION* macros when defining |
| 3083 | // a new action, you should also consider implementing ActionInterface |
| 3084 | // or using MakePolymorphicAction() instead, especially if you need to |
| 3085 | // use the action a lot. While these approaches require more work, |
| 3086 | // they give you more control on the types of the mock function |
| 3087 | // arguments and the action parameters, which in general leads to |
| 3088 | // better compiler error messages that pay off in the long run. They |
| 3089 | // also allow overloading actions based on parameter types (as opposed |
| 3090 | // to just based on the number of parameters). |
| 3091 | // |
| 3092 | // CAVEAT: |
| 3093 | // |
| 3094 | // ACTION*() can only be used in a namespace scope. The reason is |
| 3095 | // that C++ doesn't yet allow function-local types to be used to |
| 3096 | // instantiate templates. The up-coming C++0x standard will fix this. |
| 3097 | // Once that's done, we'll consider supporting using ACTION*() inside |
| 3098 | // a function. |
| 3099 | // |
| 3100 | // MORE INFORMATION: |
| 3101 | // |
| 3102 | // To learn more about using these macros, please search for 'ACTION' |
| 3103 | // on http://code.google.com/p/googlemock/wiki/CookBook. |
| 3104 | |
| 3105 | // An internal macro needed for implementing ACTION*(). |
| 3106 | #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\ |
| 3107 | const args_type& args GTEST_ATTRIBUTE_UNUSED_,\ |
| 3108 | arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_,\ |
| 3109 | arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_,\ |
| 3110 | arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_,\ |
| 3111 | arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_,\ |
| 3112 | arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_,\ |
| 3113 | arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_,\ |
| 3114 | arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_,\ |
| 3115 | arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_,\ |
| 3116 | arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_,\ |
| 3117 | arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_ |
| 3118 | |
| 3119 | // Sometimes you want to give an action explicit template parameters |
| 3120 | // that cannot be inferred from its value parameters. ACTION() and |
| 3121 | // ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that |
| 3122 | // and can be viewed as an extension to ACTION() and ACTION_P*(). |
| 3123 | // |
| 3124 | // The syntax: |
| 3125 | // |
| 3126 | // ACTION_TEMPLATE(ActionName, |
| 3127 | // HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m), |
| 3128 | // AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; } |
| 3129 | // |
| 3130 | // defines an action template that takes m explicit template |
| 3131 | // parameters and n value parameters. name_i is the name of the i-th |
| 3132 | // template parameter, and kind_i specifies whether it's a typename, |
| 3133 | // an integral constant, or a template. p_i is the name of the i-th |
| 3134 | // value parameter. |
| 3135 | // |
| 3136 | // Example: |
| 3137 | // |
| 3138 | // // DuplicateArg<k, T>(output) converts the k-th argument of the mock |
| 3139 | // // function to type T and copies it to *output. |
| 3140 | // ACTION_TEMPLATE(DuplicateArg, |
| 3141 | // HAS_2_TEMPLATE_PARAMS(int, k, typename, T), |
| 3142 | // AND_1_VALUE_PARAMS(output)) { |
| 3143 | // *output = T(std::tr1::get<k>(args)); |
| 3144 | // } |
| 3145 | // ... |
| 3146 | // int n; |
| 3147 | // EXPECT_CALL(mock, Foo(_, _)) |
| 3148 | // .WillOnce(DuplicateArg<1, unsigned char>(&n)); |
| 3149 | // |
| 3150 | // To create an instance of an action template, write: |
| 3151 | // |
| 3152 | // ActionName<t1, ..., t_m>(v1, ..., v_n) |
| 3153 | // |
| 3154 | // where the ts are the template arguments and the vs are the value |
| 3155 | // arguments. The value argument types are inferred by the compiler. |
| 3156 | // If you want to explicitly specify the value argument types, you can |
| 3157 | // provide additional template arguments: |
| 3158 | // |
| 3159 | // ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n) |
| 3160 | // |
| 3161 | // where u_i is the desired type of v_i. |
| 3162 | // |
| 3163 | // ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the |
| 3164 | // number of value parameters, but not on the number of template |
| 3165 | // parameters. Without the restriction, the meaning of the following |
| 3166 | // is unclear: |
| 3167 | // |
| 3168 | // OverloadedAction<int, bool>(x); |
| 3169 | // |
| 3170 | // Are we using a single-template-parameter action where 'bool' refers |
| 3171 | // to the type of x, or are we using a two-template-parameter action |
| 3172 | // where the compiler is asked to infer the type of x? |
| 3173 | // |
| 3174 | // Implementation notes: |
| 3175 | // |
| 3176 | // GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and |
| 3177 | // GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for |
| 3178 | // implementing ACTION_TEMPLATE. The main trick we use is to create |
| 3179 | // new macro invocations when expanding a macro. For example, we have |
| 3180 | // |
| 3181 | // #define ACTION_TEMPLATE(name, template_params, value_params) |
| 3182 | // ... GMOCK_INTERNAL_DECL_##template_params ... |
| 3183 | // |
| 3184 | // which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...) |
| 3185 | // to expand to |
| 3186 | // |
| 3187 | // ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ... |
| 3188 | // |
| 3189 | // Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the |
| 3190 | // preprocessor will continue to expand it to |
| 3191 | // |
| 3192 | // ... typename T ... |
| 3193 | // |
| 3194 | // This technique conforms to the C++ standard and is portable. It |
| 3195 | // allows us to implement action templates using O(N) code, where N is |
| 3196 | // the maximum number of template/value parameters supported. Without |
| 3197 | // using it, we'd have to devote O(N^2) amount of code to implement all |
| 3198 | // combinations of m and n. |
| 3199 | |
| 3200 | // Declares the template parameters. |
| 3201 | #define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0 |
| 3202 | #define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ |
| 3203 | name1) kind0 name0, kind1 name1 |
| 3204 | #define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3205 | kind2, name2) kind0 name0, kind1 name1, kind2 name2 |
| 3206 | #define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3207 | kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \ |
| 3208 | kind3 name3 |
| 3209 | #define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3210 | kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \ |
| 3211 | kind2 name2, kind3 name3, kind4 name4 |
| 3212 | #define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3213 | kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \ |
| 3214 | kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5 |
| 3215 | #define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3216 | kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ |
| 3217 | name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \ |
| 3218 | kind5 name5, kind6 name6 |
| 3219 | #define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3220 | kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ |
| 3221 | kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \ |
| 3222 | kind4 name4, kind5 name5, kind6 name6, kind7 name7 |
| 3223 | #define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3224 | kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ |
| 3225 | kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \ |
| 3226 | kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \ |
| 3227 | kind8 name8 |
| 3228 | #define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ |
| 3229 | name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ |
| 3230 | name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \ |
| 3231 | kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \ |
| 3232 | kind6 name6, kind7 name7, kind8 name8, kind9 name9 |
| 3233 | |
| 3234 | // Lists the template parameters. |
| 3235 | #define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0 |
| 3236 | #define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ |
| 3237 | name1) name0, name1 |
| 3238 | #define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3239 | kind2, name2) name0, name1, name2 |
| 3240 | #define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3241 | kind2, name2, kind3, name3) name0, name1, name2, name3 |
| 3242 | #define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3243 | kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \ |
| 3244 | name4 |
| 3245 | #define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3246 | kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \ |
| 3247 | name2, name3, name4, name5 |
| 3248 | #define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3249 | kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ |
| 3250 | name6) name0, name1, name2, name3, name4, name5, name6 |
| 3251 | #define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3252 | kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ |
| 3253 | kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7 |
| 3254 | #define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
| 3255 | kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ |
| 3256 | kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \ |
| 3257 | name6, name7, name8 |
| 3258 | #define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ |
| 3259 | name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ |
| 3260 | name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \ |
| 3261 | name3, name4, name5, name6, name7, name8, name9 |
| 3262 | |
| 3263 | // Declares the types of value parameters. |
| 3264 | #define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS() |
| 3265 | #define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type |
| 3266 | #define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \ |
| 3267 | typename p0##_type, typename p1##_type |
| 3268 | #define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \ |
| 3269 | typename p0##_type, typename p1##_type, typename p2##_type |
| 3270 | #define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ |
| 3271 | typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3272 | typename p3##_type |
| 3273 | #define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ |
| 3274 | typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3275 | typename p3##_type, typename p4##_type |
| 3276 | #define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ |
| 3277 | typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3278 | typename p3##_type, typename p4##_type, typename p5##_type |
| 3279 | #define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
| 3280 | p6) , typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3281 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 3282 | typename p6##_type |
| 3283 | #define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
| 3284 | p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3285 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 3286 | typename p6##_type, typename p7##_type |
| 3287 | #define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
| 3288 | p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3289 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 3290 | typename p6##_type, typename p7##_type, typename p8##_type |
| 3291 | #define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
| 3292 | p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \ |
| 3293 | typename p2##_type, typename p3##_type, typename p4##_type, \ |
| 3294 | typename p5##_type, typename p6##_type, typename p7##_type, \ |
| 3295 | typename p8##_type, typename p9##_type |
| 3296 | |
| 3297 | // Initializes the value parameters. |
| 3298 | #define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\ |
| 3299 | () |
| 3300 | #define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\ |
| 3301 | (p0##_type gmock_p0) : p0(gmock_p0) |
| 3302 | #define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\ |
| 3303 | (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1) |
| 3304 | #define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\ |
| 3305 | (p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 3306 | p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) |
| 3307 | #define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\ |
| 3308 | (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 3309 | p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 3310 | p3(gmock_p3) |
| 3311 | #define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\ |
| 3312 | (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 3313 | p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \ |
| 3314 | p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) |
| 3315 | #define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\ |
| 3316 | (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 3317 | p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 3318 | p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 3319 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) |
| 3320 | #define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\ |
| 3321 | (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 3322 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 3323 | p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 3324 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) |
| 3325 | #define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\ |
| 3326 | (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 3327 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 3328 | p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), \ |
| 3329 | p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ |
| 3330 | p7(gmock_p7) |
| 3331 | #define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3332 | p7, p8)\ |
| 3333 | (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 3334 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 3335 | p6##_type gmock_p6, p7##_type gmock_p7, \ |
| 3336 | p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 3337 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ |
| 3338 | p8(gmock_p8) |
| 3339 | #define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3340 | p7, p8, p9)\ |
| 3341 | (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 3342 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 3343 | p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ |
| 3344 | p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 3345 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ |
| 3346 | p8(gmock_p8), p9(gmock_p9) |
| 3347 | |
| 3348 | // Declares the fields for storing the value parameters. |
| 3349 | #define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS() |
| 3350 | #define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0; |
| 3351 | #define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \ |
| 3352 | p1##_type p1; |
| 3353 | #define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \ |
| 3354 | p1##_type p1; p2##_type p2; |
| 3355 | #define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \ |
| 3356 | p1##_type p1; p2##_type p2; p3##_type p3; |
| 3357 | #define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ |
| 3358 | p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; |
| 3359 | #define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ |
| 3360 | p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ |
| 3361 | p5##_type p5; |
| 3362 | #define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
| 3363 | p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ |
| 3364 | p5##_type p5; p6##_type p6; |
| 3365 | #define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3366 | p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ |
| 3367 | p5##_type p5; p6##_type p6; p7##_type p7; |
| 3368 | #define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3369 | p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ |
| 3370 | p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; |
| 3371 | #define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3372 | p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ |
| 3373 | p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \ |
| 3374 | p9##_type p9; |
| 3375 | |
| 3376 | // Lists the value parameters. |
| 3377 | #define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS() |
| 3378 | #define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0 |
| 3379 | #define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1 |
| 3380 | #define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2 |
| 3381 | #define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3 |
| 3382 | #define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \ |
| 3383 | p2, p3, p4 |
| 3384 | #define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \ |
| 3385 | p1, p2, p3, p4, p5 |
| 3386 | #define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
| 3387 | p6) p0, p1, p2, p3, p4, p5, p6 |
| 3388 | #define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3389 | p7) p0, p1, p2, p3, p4, p5, p6, p7 |
| 3390 | #define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3391 | p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8 |
| 3392 | #define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3393 | p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 |
| 3394 | |
| 3395 | // Lists the value parameter types. |
| 3396 | #define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS() |
| 3397 | #define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type |
| 3398 | #define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \ |
| 3399 | p1##_type |
| 3400 | #define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \ |
| 3401 | p1##_type, p2##_type |
| 3402 | #define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ |
| 3403 | p0##_type, p1##_type, p2##_type, p3##_type |
| 3404 | #define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ |
| 3405 | p0##_type, p1##_type, p2##_type, p3##_type, p4##_type |
| 3406 | #define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ |
| 3407 | p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type |
| 3408 | #define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
| 3409 | p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \ |
| 3410 | p6##_type |
| 3411 | #define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
| 3412 | p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 3413 | p5##_type, p6##_type, p7##_type |
| 3414 | #define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
| 3415 | p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 3416 | p5##_type, p6##_type, p7##_type, p8##_type |
| 3417 | #define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
| 3418 | p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 3419 | p5##_type, p6##_type, p7##_type, p8##_type, p9##_type |
| 3420 | |
| 3421 | // Declares the value parameters. |
| 3422 | #define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS() |
| 3423 | #define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0 |
| 3424 | #define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \ |
| 3425 | p1##_type p1 |
| 3426 | #define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \ |
| 3427 | p1##_type p1, p2##_type p2 |
| 3428 | #define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \ |
| 3429 | p1##_type p1, p2##_type p2, p3##_type p3 |
| 3430 | #define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ |
| 3431 | p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4 |
| 3432 | #define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ |
| 3433 | p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ |
| 3434 | p5##_type p5 |
| 3435 | #define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
| 3436 | p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ |
| 3437 | p5##_type p5, p6##_type p6 |
| 3438 | #define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3439 | p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ |
| 3440 | p5##_type p5, p6##_type p6, p7##_type p7 |
| 3441 | #define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3442 | p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
| 3443 | p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8 |
| 3444 | #define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3445 | p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
| 3446 | p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ |
| 3447 | p9##_type p9 |
| 3448 | |
| 3449 | // The suffix of the class template implementing the action template. |
| 3450 | #define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS() |
| 3451 | #define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P |
| 3452 | #define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2 |
| 3453 | #define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3 |
| 3454 | #define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4 |
| 3455 | #define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5 |
| 3456 | #define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6 |
| 3457 | #define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7 |
| 3458 | #define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3459 | p7) P8 |
| 3460 | #define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3461 | p7, p8) P9 |
| 3462 | #define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
| 3463 | p7, p8, p9) P10 |
| 3464 | |
| 3465 | // The name of the class template implementing the action template. |
| 3466 | #define GMOCK_ACTION_CLASS_(name, value_params)\ |
| 3467 | GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params) |
| 3468 | |
| 3469 | #define ACTION_TEMPLATE(name, template_params, value_params)\ |
| 3470 | template <GMOCK_INTERNAL_DECL_##template_params\ |
| 3471 | GMOCK_INTERNAL_DECL_TYPE_##value_params>\ |
| 3472 | class GMOCK_ACTION_CLASS_(name, value_params) {\ |
| 3473 | public:\ |
| 3474 | GMOCK_ACTION_CLASS_(name, value_params)\ |
| 3475 | GMOCK_INTERNAL_INIT_##value_params {}\ |
| 3476 | template <typename F>\ |
| 3477 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 3478 | public:\ |
| 3479 | typedef F function_type;\ |
| 3480 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 3481 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 3482 | args_type;\ |
| 3483 | explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\ |
| 3484 | virtual return_type Perform(const args_type& args) {\ |
| 3485 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 3486 | Perform(this, args);\ |
| 3487 | }\ |
| 3488 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3489 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3490 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3491 | typename arg9_type>\ |
| 3492 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 3493 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 3494 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 3495 | arg9_type arg9) const;\ |
| 3496 | GMOCK_INTERNAL_DEFN_##value_params\ |
| 3497 | private:\ |
| 3498 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 3499 | };\ |
| 3500 | template <typename F> operator ::testing::Action<F>() const {\ |
| 3501 | return ::testing::Action<F>(\ |
| 3502 | new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\ |
| 3503 | }\ |
| 3504 | GMOCK_INTERNAL_DEFN_##value_params\ |
| 3505 | private:\ |
| 3506 | GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\ |
| 3507 | };\ |
| 3508 | template <GMOCK_INTERNAL_DECL_##template_params\ |
| 3509 | GMOCK_INTERNAL_DECL_TYPE_##value_params>\ |
| 3510 | inline GMOCK_ACTION_CLASS_(name, value_params)<\ |
| 3511 | GMOCK_INTERNAL_LIST_##template_params\ |
| 3512 | GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\ |
| 3513 | GMOCK_INTERNAL_DECL_##value_params) {\ |
| 3514 | return GMOCK_ACTION_CLASS_(name, value_params)<\ |
| 3515 | GMOCK_INTERNAL_LIST_##template_params\ |
| 3516 | GMOCK_INTERNAL_LIST_TYPE_##value_params>(\ |
| 3517 | GMOCK_INTERNAL_LIST_##value_params);\ |
| 3518 | }\ |
| 3519 | template <GMOCK_INTERNAL_DECL_##template_params\ |
| 3520 | GMOCK_INTERNAL_DECL_TYPE_##value_params>\ |
| 3521 | template <typename F>\ |
| 3522 | template <typename arg0_type, typename arg1_type, typename arg2_type,\ |
| 3523 | typename arg3_type, typename arg4_type, typename arg5_type,\ |
| 3524 | typename arg6_type, typename arg7_type, typename arg8_type,\ |
| 3525 | typename arg9_type>\ |
| 3526 | typename ::testing::internal::Function<F>::Result\ |
| 3527 | GMOCK_ACTION_CLASS_(name, value_params)<\ |
| 3528 | GMOCK_INTERNAL_LIST_##template_params\ |
| 3529 | GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\ |
| 3530 | gmock_PerformImpl(\ |
| 3531 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 3532 | |
| 3533 | #define ACTION(name)\ |
| 3534 | class name##Action {\ |
| 3535 | public:\ |
| 3536 | name##Action() {}\ |
| 3537 | template <typename F>\ |
| 3538 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 3539 | public:\ |
| 3540 | typedef F function_type;\ |
| 3541 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 3542 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 3543 | args_type;\ |
| 3544 | gmock_Impl() {}\ |
| 3545 | virtual return_type Perform(const args_type& args) {\ |
| 3546 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 3547 | Perform(this, args);\ |
| 3548 | }\ |
| 3549 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3550 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3551 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3552 | typename arg9_type>\ |
| 3553 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 3554 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 3555 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 3556 | arg9_type arg9) const;\ |
| 3557 | private:\ |
| 3558 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 3559 | };\ |
| 3560 | template <typename F> operator ::testing::Action<F>() const {\ |
| 3561 | return ::testing::Action<F>(new gmock_Impl<F>());\ |
| 3562 | }\ |
| 3563 | private:\ |
| 3564 | GTEST_DISALLOW_ASSIGN_(name##Action);\ |
| 3565 | };\ |
| 3566 | inline name##Action name() {\ |
| 3567 | return name##Action();\ |
| 3568 | }\ |
| 3569 | template <typename F>\ |
| 3570 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3571 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3572 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3573 | typename arg9_type>\ |
| 3574 | typename ::testing::internal::Function<F>::Result\ |
| 3575 | name##Action::gmock_Impl<F>::gmock_PerformImpl(\ |
| 3576 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 3577 | |
| 3578 | #define ACTION_P(name, p0)\ |
| 3579 | template <typename p0##_type>\ |
| 3580 | class name##ActionP {\ |
| 3581 | public:\ |
| 3582 | name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\ |
| 3583 | template <typename F>\ |
| 3584 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 3585 | public:\ |
| 3586 | typedef F function_type;\ |
| 3587 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 3588 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 3589 | args_type;\ |
| 3590 | explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\ |
| 3591 | virtual return_type Perform(const args_type& args) {\ |
| 3592 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 3593 | Perform(this, args);\ |
| 3594 | }\ |
| 3595 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3596 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3597 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3598 | typename arg9_type>\ |
| 3599 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 3600 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 3601 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 3602 | arg9_type arg9) const;\ |
| 3603 | p0##_type p0;\ |
| 3604 | private:\ |
| 3605 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 3606 | };\ |
| 3607 | template <typename F> operator ::testing::Action<F>() const {\ |
| 3608 | return ::testing::Action<F>(new gmock_Impl<F>(p0));\ |
| 3609 | }\ |
| 3610 | p0##_type p0;\ |
| 3611 | private:\ |
| 3612 | GTEST_DISALLOW_ASSIGN_(name##ActionP);\ |
| 3613 | };\ |
| 3614 | template <typename p0##_type>\ |
| 3615 | inline name##ActionP<p0##_type> name(p0##_type p0) {\ |
| 3616 | return name##ActionP<p0##_type>(p0);\ |
| 3617 | }\ |
| 3618 | template <typename p0##_type>\ |
| 3619 | template <typename F>\ |
| 3620 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3621 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3622 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3623 | typename arg9_type>\ |
| 3624 | typename ::testing::internal::Function<F>::Result\ |
| 3625 | name##ActionP<p0##_type>::gmock_Impl<F>::gmock_PerformImpl(\ |
| 3626 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 3627 | |
| 3628 | #define ACTION_P2(name, p0, p1)\ |
| 3629 | template <typename p0##_type, typename p1##_type>\ |
| 3630 | class name##ActionP2 {\ |
| 3631 | public:\ |
| 3632 | name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ |
| 3633 | p1(gmock_p1) {}\ |
| 3634 | template <typename F>\ |
| 3635 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 3636 | public:\ |
| 3637 | typedef F function_type;\ |
| 3638 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 3639 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 3640 | args_type;\ |
| 3641 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ |
| 3642 | p1(gmock_p1) {}\ |
| 3643 | virtual return_type Perform(const args_type& args) {\ |
| 3644 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 3645 | Perform(this, args);\ |
| 3646 | }\ |
| 3647 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3648 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3649 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3650 | typename arg9_type>\ |
| 3651 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 3652 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 3653 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 3654 | arg9_type arg9) const;\ |
| 3655 | p0##_type p0;\ |
| 3656 | p1##_type p1;\ |
| 3657 | private:\ |
| 3658 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 3659 | };\ |
| 3660 | template <typename F> operator ::testing::Action<F>() const {\ |
| 3661 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\ |
| 3662 | }\ |
| 3663 | p0##_type p0;\ |
| 3664 | p1##_type p1;\ |
| 3665 | private:\ |
| 3666 | GTEST_DISALLOW_ASSIGN_(name##ActionP2);\ |
| 3667 | };\ |
| 3668 | template <typename p0##_type, typename p1##_type>\ |
| 3669 | inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \ |
| 3670 | p1##_type p1) {\ |
| 3671 | return name##ActionP2<p0##_type, p1##_type>(p0, p1);\ |
| 3672 | }\ |
| 3673 | template <typename p0##_type, typename p1##_type>\ |
| 3674 | template <typename F>\ |
| 3675 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3676 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3677 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3678 | typename arg9_type>\ |
| 3679 | typename ::testing::internal::Function<F>::Result\ |
| 3680 | name##ActionP2<p0##_type, p1##_type>::gmock_Impl<F>::gmock_PerformImpl(\ |
| 3681 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 3682 | |
| 3683 | #define ACTION_P3(name, p0, p1, p2)\ |
| 3684 | template <typename p0##_type, typename p1##_type, typename p2##_type>\ |
| 3685 | class name##ActionP3 {\ |
| 3686 | public:\ |
| 3687 | name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 3688 | p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ |
| 3689 | template <typename F>\ |
| 3690 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 3691 | public:\ |
| 3692 | typedef F function_type;\ |
| 3693 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 3694 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 3695 | args_type;\ |
| 3696 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 3697 | p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ |
| 3698 | virtual return_type Perform(const args_type& args) {\ |
| 3699 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 3700 | Perform(this, args);\ |
| 3701 | }\ |
| 3702 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3703 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3704 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3705 | typename arg9_type>\ |
| 3706 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 3707 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 3708 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 3709 | arg9_type arg9) const;\ |
| 3710 | p0##_type p0;\ |
| 3711 | p1##_type p1;\ |
| 3712 | p2##_type p2;\ |
| 3713 | private:\ |
| 3714 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 3715 | };\ |
| 3716 | template <typename F> operator ::testing::Action<F>() const {\ |
| 3717 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\ |
| 3718 | }\ |
| 3719 | p0##_type p0;\ |
| 3720 | p1##_type p1;\ |
| 3721 | p2##_type p2;\ |
| 3722 | private:\ |
| 3723 | GTEST_DISALLOW_ASSIGN_(name##ActionP3);\ |
| 3724 | };\ |
| 3725 | template <typename p0##_type, typename p1##_type, typename p2##_type>\ |
| 3726 | inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \ |
| 3727 | p1##_type p1, p2##_type p2) {\ |
| 3728 | return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\ |
| 3729 | }\ |
| 3730 | template <typename p0##_type, typename p1##_type, typename p2##_type>\ |
| 3731 | template <typename F>\ |
| 3732 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3733 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3734 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3735 | typename arg9_type>\ |
| 3736 | typename ::testing::internal::Function<F>::Result\ |
| 3737 | name##ActionP3<p0##_type, p1##_type, \ |
| 3738 | p2##_type>::gmock_Impl<F>::gmock_PerformImpl(\ |
| 3739 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 3740 | |
| 3741 | #define ACTION_P4(name, p0, p1, p2, p3)\ |
| 3742 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3743 | typename p3##_type>\ |
| 3744 | class name##ActionP4 {\ |
| 3745 | public:\ |
| 3746 | name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 3747 | p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ |
| 3748 | p2(gmock_p2), p3(gmock_p3) {}\ |
| 3749 | template <typename F>\ |
| 3750 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 3751 | public:\ |
| 3752 | typedef F function_type;\ |
| 3753 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 3754 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 3755 | args_type;\ |
| 3756 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 3757 | p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 3758 | p3(gmock_p3) {}\ |
| 3759 | virtual return_type Perform(const args_type& args) {\ |
| 3760 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 3761 | Perform(this, args);\ |
| 3762 | }\ |
| 3763 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3764 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3765 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3766 | typename arg9_type>\ |
| 3767 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 3768 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 3769 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 3770 | arg9_type arg9) const;\ |
| 3771 | p0##_type p0;\ |
| 3772 | p1##_type p1;\ |
| 3773 | p2##_type p2;\ |
| 3774 | p3##_type p3;\ |
| 3775 | private:\ |
| 3776 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 3777 | };\ |
| 3778 | template <typename F> operator ::testing::Action<F>() const {\ |
| 3779 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\ |
| 3780 | }\ |
| 3781 | p0##_type p0;\ |
| 3782 | p1##_type p1;\ |
| 3783 | p2##_type p2;\ |
| 3784 | p3##_type p3;\ |
| 3785 | private:\ |
| 3786 | GTEST_DISALLOW_ASSIGN_(name##ActionP4);\ |
| 3787 | };\ |
| 3788 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3789 | typename p3##_type>\ |
| 3790 | inline name##ActionP4<p0##_type, p1##_type, p2##_type, \ |
| 3791 | p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ |
| 3792 | p3##_type p3) {\ |
| 3793 | return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \ |
| 3794 | p2, p3);\ |
| 3795 | }\ |
| 3796 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3797 | typename p3##_type>\ |
| 3798 | template <typename F>\ |
| 3799 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3800 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3801 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3802 | typename arg9_type>\ |
| 3803 | typename ::testing::internal::Function<F>::Result\ |
| 3804 | name##ActionP4<p0##_type, p1##_type, p2##_type, \ |
| 3805 | p3##_type>::gmock_Impl<F>::gmock_PerformImpl(\ |
| 3806 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 3807 | |
| 3808 | #define ACTION_P5(name, p0, p1, p2, p3, p4)\ |
| 3809 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3810 | typename p3##_type, typename p4##_type>\ |
| 3811 | class name##ActionP5 {\ |
| 3812 | public:\ |
| 3813 | name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 3814 | p2##_type gmock_p2, p3##_type gmock_p3, \ |
| 3815 | p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 3816 | p3(gmock_p3), p4(gmock_p4) {}\ |
| 3817 | template <typename F>\ |
| 3818 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 3819 | public:\ |
| 3820 | typedef F function_type;\ |
| 3821 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 3822 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 3823 | args_type;\ |
| 3824 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 3825 | p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \ |
| 3826 | p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\ |
| 3827 | virtual return_type Perform(const args_type& args) {\ |
| 3828 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 3829 | Perform(this, args);\ |
| 3830 | }\ |
| 3831 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3832 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3833 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3834 | typename arg9_type>\ |
| 3835 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 3836 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 3837 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 3838 | arg9_type arg9) const;\ |
| 3839 | p0##_type p0;\ |
| 3840 | p1##_type p1;\ |
| 3841 | p2##_type p2;\ |
| 3842 | p3##_type p3;\ |
| 3843 | p4##_type p4;\ |
| 3844 | private:\ |
| 3845 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 3846 | };\ |
| 3847 | template <typename F> operator ::testing::Action<F>() const {\ |
| 3848 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\ |
| 3849 | }\ |
| 3850 | p0##_type p0;\ |
| 3851 | p1##_type p1;\ |
| 3852 | p2##_type p2;\ |
| 3853 | p3##_type p3;\ |
| 3854 | p4##_type p4;\ |
| 3855 | private:\ |
| 3856 | GTEST_DISALLOW_ASSIGN_(name##ActionP5);\ |
| 3857 | };\ |
| 3858 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3859 | typename p3##_type, typename p4##_type>\ |
| 3860 | inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 3861 | p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
| 3862 | p4##_type p4) {\ |
| 3863 | return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 3864 | p4##_type>(p0, p1, p2, p3, p4);\ |
| 3865 | }\ |
| 3866 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3867 | typename p3##_type, typename p4##_type>\ |
| 3868 | template <typename F>\ |
| 3869 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3870 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3871 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3872 | typename arg9_type>\ |
| 3873 | typename ::testing::internal::Function<F>::Result\ |
| 3874 | name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 3875 | p4##_type>::gmock_Impl<F>::gmock_PerformImpl(\ |
| 3876 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 3877 | |
| 3878 | #define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\ |
| 3879 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3880 | typename p3##_type, typename p4##_type, typename p5##_type>\ |
| 3881 | class name##ActionP6 {\ |
| 3882 | public:\ |
| 3883 | name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 3884 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 3885 | p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 3886 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ |
| 3887 | template <typename F>\ |
| 3888 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 3889 | public:\ |
| 3890 | typedef F function_type;\ |
| 3891 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 3892 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 3893 | args_type;\ |
| 3894 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 3895 | p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 3896 | p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 3897 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ |
| 3898 | virtual return_type Perform(const args_type& args) {\ |
| 3899 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 3900 | Perform(this, args);\ |
| 3901 | }\ |
| 3902 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3903 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3904 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3905 | typename arg9_type>\ |
| 3906 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 3907 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 3908 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 3909 | arg9_type arg9) const;\ |
| 3910 | p0##_type p0;\ |
| 3911 | p1##_type p1;\ |
| 3912 | p2##_type p2;\ |
| 3913 | p3##_type p3;\ |
| 3914 | p4##_type p4;\ |
| 3915 | p5##_type p5;\ |
| 3916 | private:\ |
| 3917 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 3918 | };\ |
| 3919 | template <typename F> operator ::testing::Action<F>() const {\ |
| 3920 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\ |
| 3921 | }\ |
| 3922 | p0##_type p0;\ |
| 3923 | p1##_type p1;\ |
| 3924 | p2##_type p2;\ |
| 3925 | p3##_type p3;\ |
| 3926 | p4##_type p4;\ |
| 3927 | p5##_type p5;\ |
| 3928 | private:\ |
| 3929 | GTEST_DISALLOW_ASSIGN_(name##ActionP6);\ |
| 3930 | };\ |
| 3931 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3932 | typename p3##_type, typename p4##_type, typename p5##_type>\ |
| 3933 | inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 3934 | p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ |
| 3935 | p3##_type p3, p4##_type p4, p5##_type p5) {\ |
| 3936 | return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 3937 | p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\ |
| 3938 | }\ |
| 3939 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3940 | typename p3##_type, typename p4##_type, typename p5##_type>\ |
| 3941 | template <typename F>\ |
| 3942 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3943 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3944 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3945 | typename arg9_type>\ |
| 3946 | typename ::testing::internal::Function<F>::Result\ |
| 3947 | name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 3948 | p5##_type>::gmock_Impl<F>::gmock_PerformImpl(\ |
| 3949 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 3950 | |
| 3951 | #define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\ |
| 3952 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 3953 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 3954 | typename p6##_type>\ |
| 3955 | class name##ActionP7 {\ |
| 3956 | public:\ |
| 3957 | name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 3958 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 3959 | p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \ |
| 3960 | p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ |
| 3961 | p6(gmock_p6) {}\ |
| 3962 | template <typename F>\ |
| 3963 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 3964 | public:\ |
| 3965 | typedef F function_type;\ |
| 3966 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 3967 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 3968 | args_type;\ |
| 3969 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 3970 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 3971 | p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 3972 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ |
| 3973 | virtual return_type Perform(const args_type& args) {\ |
| 3974 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 3975 | Perform(this, args);\ |
| 3976 | }\ |
| 3977 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 3978 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 3979 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 3980 | typename arg9_type>\ |
| 3981 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 3982 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 3983 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 3984 | arg9_type arg9) const;\ |
| 3985 | p0##_type p0;\ |
| 3986 | p1##_type p1;\ |
| 3987 | p2##_type p2;\ |
| 3988 | p3##_type p3;\ |
| 3989 | p4##_type p4;\ |
| 3990 | p5##_type p5;\ |
| 3991 | p6##_type p6;\ |
| 3992 | private:\ |
| 3993 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 3994 | };\ |
| 3995 | template <typename F> operator ::testing::Action<F>() const {\ |
| 3996 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ |
| 3997 | p6));\ |
| 3998 | }\ |
| 3999 | p0##_type p0;\ |
| 4000 | p1##_type p1;\ |
| 4001 | p2##_type p2;\ |
| 4002 | p3##_type p3;\ |
| 4003 | p4##_type p4;\ |
| 4004 | p5##_type p5;\ |
| 4005 | p6##_type p6;\ |
| 4006 | private:\ |
| 4007 | GTEST_DISALLOW_ASSIGN_(name##ActionP7);\ |
| 4008 | };\ |
| 4009 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 4010 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 4011 | typename p6##_type>\ |
| 4012 | inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 4013 | p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \ |
| 4014 | p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ |
| 4015 | p6##_type p6) {\ |
| 4016 | return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 4017 | p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\ |
| 4018 | }\ |
| 4019 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 4020 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 4021 | typename p6##_type>\ |
| 4022 | template <typename F>\ |
| 4023 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 4024 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 4025 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 4026 | typename arg9_type>\ |
| 4027 | typename ::testing::internal::Function<F>::Result\ |
| 4028 | name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 4029 | p5##_type, p6##_type>::gmock_Impl<F>::gmock_PerformImpl(\ |
| 4030 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 4031 | |
| 4032 | #define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\ |
| 4033 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 4034 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 4035 | typename p6##_type, typename p7##_type>\ |
| 4036 | class name##ActionP8 {\ |
| 4037 | public:\ |
| 4038 | name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 4039 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 4040 | p5##_type gmock_p5, p6##_type gmock_p6, \ |
| 4041 | p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 4042 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ |
| 4043 | p7(gmock_p7) {}\ |
| 4044 | template <typename F>\ |
| 4045 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 4046 | public:\ |
| 4047 | typedef F function_type;\ |
| 4048 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 4049 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 4050 | args_type;\ |
| 4051 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 4052 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 4053 | p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \ |
| 4054 | p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \ |
| 4055 | p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\ |
| 4056 | virtual return_type Perform(const args_type& args) {\ |
| 4057 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 4058 | Perform(this, args);\ |
| 4059 | }\ |
| 4060 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 4061 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 4062 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 4063 | typename arg9_type>\ |
| 4064 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 4065 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 4066 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 4067 | arg9_type arg9) const;\ |
| 4068 | p0##_type p0;\ |
| 4069 | p1##_type p1;\ |
| 4070 | p2##_type p2;\ |
| 4071 | p3##_type p3;\ |
| 4072 | p4##_type p4;\ |
| 4073 | p5##_type p5;\ |
| 4074 | p6##_type p6;\ |
| 4075 | p7##_type p7;\ |
| 4076 | private:\ |
| 4077 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 4078 | };\ |
| 4079 | template <typename F> operator ::testing::Action<F>() const {\ |
| 4080 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ |
| 4081 | p6, p7));\ |
| 4082 | }\ |
| 4083 | p0##_type p0;\ |
| 4084 | p1##_type p1;\ |
| 4085 | p2##_type p2;\ |
| 4086 | p3##_type p3;\ |
| 4087 | p4##_type p4;\ |
| 4088 | p5##_type p5;\ |
| 4089 | p6##_type p6;\ |
| 4090 | p7##_type p7;\ |
| 4091 | private:\ |
| 4092 | GTEST_DISALLOW_ASSIGN_(name##ActionP8);\ |
| 4093 | };\ |
| 4094 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 4095 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 4096 | typename p6##_type, typename p7##_type>\ |
| 4097 | inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 4098 | p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \ |
| 4099 | p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ |
| 4100 | p6##_type p6, p7##_type p7) {\ |
| 4101 | return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 4102 | p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \ |
| 4103 | p6, p7);\ |
| 4104 | }\ |
| 4105 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 4106 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 4107 | typename p6##_type, typename p7##_type>\ |
| 4108 | template <typename F>\ |
| 4109 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 4110 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 4111 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 4112 | typename arg9_type>\ |
| 4113 | typename ::testing::internal::Function<F>::Result\ |
| 4114 | name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 4115 | p5##_type, p6##_type, \ |
| 4116 | p7##_type>::gmock_Impl<F>::gmock_PerformImpl(\ |
| 4117 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 4118 | |
| 4119 | #define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\ |
| 4120 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 4121 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 4122 | typename p6##_type, typename p7##_type, typename p8##_type>\ |
| 4123 | class name##ActionP9 {\ |
| 4124 | public:\ |
| 4125 | name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 4126 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 4127 | p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ |
| 4128 | p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 4129 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ |
| 4130 | p8(gmock_p8) {}\ |
| 4131 | template <typename F>\ |
| 4132 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 4133 | public:\ |
| 4134 | typedef F function_type;\ |
| 4135 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 4136 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 4137 | args_type;\ |
| 4138 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 4139 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 4140 | p6##_type gmock_p6, p7##_type gmock_p7, \ |
| 4141 | p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 4142 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ |
| 4143 | p7(gmock_p7), p8(gmock_p8) {}\ |
| 4144 | virtual return_type Perform(const args_type& args) {\ |
| 4145 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 4146 | Perform(this, args);\ |
| 4147 | }\ |
| 4148 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 4149 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 4150 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 4151 | typename arg9_type>\ |
| 4152 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 4153 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 4154 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 4155 | arg9_type arg9) const;\ |
| 4156 | p0##_type p0;\ |
| 4157 | p1##_type p1;\ |
| 4158 | p2##_type p2;\ |
| 4159 | p3##_type p3;\ |
| 4160 | p4##_type p4;\ |
| 4161 | p5##_type p5;\ |
| 4162 | p6##_type p6;\ |
| 4163 | p7##_type p7;\ |
| 4164 | p8##_type p8;\ |
| 4165 | private:\ |
| 4166 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 4167 | };\ |
| 4168 | template <typename F> operator ::testing::Action<F>() const {\ |
| 4169 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ |
| 4170 | p6, p7, p8));\ |
| 4171 | }\ |
| 4172 | p0##_type p0;\ |
| 4173 | p1##_type p1;\ |
| 4174 | p2##_type p2;\ |
| 4175 | p3##_type p3;\ |
| 4176 | p4##_type p4;\ |
| 4177 | p5##_type p5;\ |
| 4178 | p6##_type p6;\ |
| 4179 | p7##_type p7;\ |
| 4180 | p8##_type p8;\ |
| 4181 | private:\ |
| 4182 | GTEST_DISALLOW_ASSIGN_(name##ActionP9);\ |
| 4183 | };\ |
| 4184 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 4185 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 4186 | typename p6##_type, typename p7##_type, typename p8##_type>\ |
| 4187 | inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 4188 | p4##_type, p5##_type, p6##_type, p7##_type, \ |
| 4189 | p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
| 4190 | p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ |
| 4191 | p8##_type p8) {\ |
| 4192 | return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 4193 | p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \ |
| 4194 | p3, p4, p5, p6, p7, p8);\ |
| 4195 | }\ |
| 4196 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 4197 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 4198 | typename p6##_type, typename p7##_type, typename p8##_type>\ |
| 4199 | template <typename F>\ |
| 4200 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 4201 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 4202 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 4203 | typename arg9_type>\ |
| 4204 | typename ::testing::internal::Function<F>::Result\ |
| 4205 | name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 4206 | p5##_type, p6##_type, p7##_type, \ |
| 4207 | p8##_type>::gmock_Impl<F>::gmock_PerformImpl(\ |
| 4208 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 4209 | |
| 4210 | #define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\ |
| 4211 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 4212 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 4213 | typename p6##_type, typename p7##_type, typename p8##_type, \ |
| 4214 | typename p9##_type>\ |
| 4215 | class name##ActionP10 {\ |
| 4216 | public:\ |
| 4217 | name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 4218 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 4219 | p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ |
| 4220 | p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \ |
| 4221 | p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ |
| 4222 | p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ |
| 4223 | template <typename F>\ |
| 4224 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 4225 | public:\ |
| 4226 | typedef F function_type;\ |
| 4227 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 4228 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 4229 | args_type;\ |
| 4230 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 4231 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 4232 | p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ |
| 4233 | p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 4234 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ |
| 4235 | p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ |
| 4236 | virtual return_type Perform(const args_type& args) {\ |
| 4237 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 4238 | Perform(this, args);\ |
| 4239 | }\ |
| 4240 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 4241 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 4242 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 4243 | typename arg9_type>\ |
| 4244 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 4245 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 4246 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 4247 | arg9_type arg9) const;\ |
| 4248 | p0##_type p0;\ |
| 4249 | p1##_type p1;\ |
| 4250 | p2##_type p2;\ |
| 4251 | p3##_type p3;\ |
| 4252 | p4##_type p4;\ |
| 4253 | p5##_type p5;\ |
| 4254 | p6##_type p6;\ |
| 4255 | p7##_type p7;\ |
| 4256 | p8##_type p8;\ |
| 4257 | p9##_type p9;\ |
| 4258 | private:\ |
| 4259 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 4260 | };\ |
| 4261 | template <typename F> operator ::testing::Action<F>() const {\ |
| 4262 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ |
| 4263 | p6, p7, p8, p9));\ |
| 4264 | }\ |
| 4265 | p0##_type p0;\ |
| 4266 | p1##_type p1;\ |
| 4267 | p2##_type p2;\ |
| 4268 | p3##_type p3;\ |
| 4269 | p4##_type p4;\ |
| 4270 | p5##_type p5;\ |
| 4271 | p6##_type p6;\ |
| 4272 | p7##_type p7;\ |
| 4273 | p8##_type p8;\ |
| 4274 | p9##_type p9;\ |
| 4275 | private:\ |
| 4276 | GTEST_DISALLOW_ASSIGN_(name##ActionP10);\ |
| 4277 | };\ |
| 4278 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 4279 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 4280 | typename p6##_type, typename p7##_type, typename p8##_type, \ |
| 4281 | typename p9##_type>\ |
| 4282 | inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 4283 | p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ |
| 4284 | p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
| 4285 | p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ |
| 4286 | p9##_type p9) {\ |
| 4287 | return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 4288 | p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \ |
| 4289 | p1, p2, p3, p4, p5, p6, p7, p8, p9);\ |
| 4290 | }\ |
| 4291 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 4292 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 4293 | typename p6##_type, typename p7##_type, typename p8##_type, \ |
| 4294 | typename p9##_type>\ |
| 4295 | template <typename F>\ |
| 4296 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 4297 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 4298 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 4299 | typename arg9_type>\ |
| 4300 | typename ::testing::internal::Function<F>::Result\ |
| 4301 | name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 4302 | p5##_type, p6##_type, p7##_type, p8##_type, \ |
| 4303 | p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\ |
| 4304 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 4305 | |
| 4306 | // TODO(wan@google.com): move the following to a different .h file |
| 4307 | // such that we don't have to run 'pump' every time the code is |
| 4308 | // updated. |
| 4309 | namespace testing { |
| 4310 | |
| 4311 | // The ACTION*() macros trigger warning C4100 (unreferenced formal |
| 4312 | // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in |
| 4313 | // the macro definition, as the warnings are generated when the macro |
| 4314 | // is expanded and macro expansion cannot contain #pragma. Therefore |
| 4315 | // we suppress them here. |
| 4316 | #ifdef _MSC_VER |
| 4317 | # pragma warning(push) |
| 4318 | # pragma warning(disable:4100) |
| 4319 | #endif |
| 4320 | |
| 4321 | // Various overloads for InvokeArgument<N>(). |
| 4322 | // |
| 4323 | // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th |
| 4324 | // (0-based) argument, which must be a k-ary callable, of the mock |
| 4325 | // function, with arguments a1, a2, ..., a_k. |
| 4326 | // |
| 4327 | // Notes: |
| 4328 | // |
| 4329 | // 1. The arguments are passed by value by default. If you need to |
| 4330 | // pass an argument by reference, wrap it inside ByRef(). For |
| 4331 | // example, |
| 4332 | // |
| 4333 | // InvokeArgument<1>(5, string("Hello"), ByRef(foo)) |
| 4334 | // |
| 4335 | // passes 5 and string("Hello") by value, and passes foo by |
| 4336 | // reference. |
| 4337 | // |
| 4338 | // 2. If the callable takes an argument by reference but ByRef() is |
| 4339 | // not used, it will receive the reference to a copy of the value, |
| 4340 | // instead of the original value. For example, when the 0-th |
| 4341 | // argument of the mock function takes a const string&, the action |
| 4342 | // |
| 4343 | // InvokeArgument<0>(string("Hello")) |
| 4344 | // |
| 4345 | // makes a copy of the temporary string("Hello") object and passes a |
| 4346 | // reference of the copy, instead of the original temporary object, |
| 4347 | // to the callable. This makes it easy for a user to define an |
| 4348 | // InvokeArgument action from temporary values and have it performed |
| 4349 | // later. |
| 4350 | |
| 4351 | ACTION_TEMPLATE(InvokeArgument, |
| 4352 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 4353 | AND_0_VALUE_PARAMS()) { |
| 4354 | return internal::CallableHelper<return_type>::Call( |
| 4355 | ::std::tr1::get<k>(args)); |
| 4356 | } |
| 4357 | |
| 4358 | ACTION_TEMPLATE(InvokeArgument, |
| 4359 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 4360 | AND_1_VALUE_PARAMS(p0)) { |
| 4361 | return internal::CallableHelper<return_type>::Call( |
| 4362 | ::std::tr1::get<k>(args), p0); |
| 4363 | } |
| 4364 | |
| 4365 | ACTION_TEMPLATE(InvokeArgument, |
| 4366 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 4367 | AND_2_VALUE_PARAMS(p0, p1)) { |
| 4368 | return internal::CallableHelper<return_type>::Call( |
| 4369 | ::std::tr1::get<k>(args), p0, p1); |
| 4370 | } |
| 4371 | |
| 4372 | ACTION_TEMPLATE(InvokeArgument, |
| 4373 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 4374 | AND_3_VALUE_PARAMS(p0, p1, p2)) { |
| 4375 | return internal::CallableHelper<return_type>::Call( |
| 4376 | ::std::tr1::get<k>(args), p0, p1, p2); |
| 4377 | } |
| 4378 | |
| 4379 | ACTION_TEMPLATE(InvokeArgument, |
| 4380 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 4381 | AND_4_VALUE_PARAMS(p0, p1, p2, p3)) { |
| 4382 | return internal::CallableHelper<return_type>::Call( |
| 4383 | ::std::tr1::get<k>(args), p0, p1, p2, p3); |
| 4384 | } |
| 4385 | |
| 4386 | ACTION_TEMPLATE(InvokeArgument, |
| 4387 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 4388 | AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) { |
| 4389 | return internal::CallableHelper<return_type>::Call( |
| 4390 | ::std::tr1::get<k>(args), p0, p1, p2, p3, p4); |
| 4391 | } |
| 4392 | |
| 4393 | ACTION_TEMPLATE(InvokeArgument, |
| 4394 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 4395 | AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) { |
| 4396 | return internal::CallableHelper<return_type>::Call( |
| 4397 | ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5); |
| 4398 | } |
| 4399 | |
| 4400 | ACTION_TEMPLATE(InvokeArgument, |
| 4401 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 4402 | AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) { |
| 4403 | return internal::CallableHelper<return_type>::Call( |
| 4404 | ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6); |
| 4405 | } |
| 4406 | |
| 4407 | ACTION_TEMPLATE(InvokeArgument, |
| 4408 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 4409 | AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) { |
| 4410 | return internal::CallableHelper<return_type>::Call( |
| 4411 | ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7); |
| 4412 | } |
| 4413 | |
| 4414 | ACTION_TEMPLATE(InvokeArgument, |
| 4415 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 4416 | AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) { |
| 4417 | return internal::CallableHelper<return_type>::Call( |
| 4418 | ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8); |
| 4419 | } |
| 4420 | |
| 4421 | ACTION_TEMPLATE(InvokeArgument, |
| 4422 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 4423 | AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) { |
| 4424 | return internal::CallableHelper<return_type>::Call( |
| 4425 | ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); |
| 4426 | } |
| 4427 | |
| 4428 | // Various overloads for ReturnNew<T>(). |
| 4429 | // |
| 4430 | // The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new |
| 4431 | // instance of type T, constructed on the heap with constructor arguments |
| 4432 | // a1, a2, ..., and a_k. The caller assumes ownership of the returned value. |
| 4433 | ACTION_TEMPLATE(ReturnNew, |
| 4434 | HAS_1_TEMPLATE_PARAMS(typename, T), |
| 4435 | AND_0_VALUE_PARAMS()) { |
| 4436 | return new T(); |
| 4437 | } |
| 4438 | |
| 4439 | ACTION_TEMPLATE(ReturnNew, |
| 4440 | HAS_1_TEMPLATE_PARAMS(typename, T), |
| 4441 | AND_1_VALUE_PARAMS(p0)) { |
| 4442 | return new T(p0); |
| 4443 | } |
| 4444 | |
| 4445 | ACTION_TEMPLATE(ReturnNew, |
| 4446 | HAS_1_TEMPLATE_PARAMS(typename, T), |
| 4447 | AND_2_VALUE_PARAMS(p0, p1)) { |
| 4448 | return new T(p0, p1); |
| 4449 | } |
| 4450 | |
| 4451 | ACTION_TEMPLATE(ReturnNew, |
| 4452 | HAS_1_TEMPLATE_PARAMS(typename, T), |
| 4453 | AND_3_VALUE_PARAMS(p0, p1, p2)) { |
| 4454 | return new T(p0, p1, p2); |
| 4455 | } |
| 4456 | |
| 4457 | ACTION_TEMPLATE(ReturnNew, |
| 4458 | HAS_1_TEMPLATE_PARAMS(typename, T), |
| 4459 | AND_4_VALUE_PARAMS(p0, p1, p2, p3)) { |
| 4460 | return new T(p0, p1, p2, p3); |
| 4461 | } |
| 4462 | |
| 4463 | ACTION_TEMPLATE(ReturnNew, |
| 4464 | HAS_1_TEMPLATE_PARAMS(typename, T), |
| 4465 | AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) { |
| 4466 | return new T(p0, p1, p2, p3, p4); |
| 4467 | } |
| 4468 | |
| 4469 | ACTION_TEMPLATE(ReturnNew, |
| 4470 | HAS_1_TEMPLATE_PARAMS(typename, T), |
| 4471 | AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) { |
| 4472 | return new T(p0, p1, p2, p3, p4, p5); |
| 4473 | } |
| 4474 | |
| 4475 | ACTION_TEMPLATE(ReturnNew, |
| 4476 | HAS_1_TEMPLATE_PARAMS(typename, T), |
| 4477 | AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) { |
| 4478 | return new T(p0, p1, p2, p3, p4, p5, p6); |
| 4479 | } |
| 4480 | |
| 4481 | ACTION_TEMPLATE(ReturnNew, |
| 4482 | HAS_1_TEMPLATE_PARAMS(typename, T), |
| 4483 | AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) { |
| 4484 | return new T(p0, p1, p2, p3, p4, p5, p6, p7); |
| 4485 | } |
| 4486 | |
| 4487 | ACTION_TEMPLATE(ReturnNew, |
| 4488 | HAS_1_TEMPLATE_PARAMS(typename, T), |
| 4489 | AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) { |
| 4490 | return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8); |
| 4491 | } |
| 4492 | |
| 4493 | ACTION_TEMPLATE(ReturnNew, |
| 4494 | HAS_1_TEMPLATE_PARAMS(typename, T), |
| 4495 | AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) { |
| 4496 | return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); |
| 4497 | } |
| 4498 | |
| 4499 | #ifdef _MSC_VER |
| 4500 | # pragma warning(pop) |
| 4501 | #endif |
| 4502 | |
| 4503 | } // namespace testing |
| 4504 | |
| 4505 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ |
| 4506 | // This file was GENERATED by command: |
| 4507 | // pump.py gmock-generated-function-mockers.h.pump |
| 4508 | // DO NOT EDIT BY HAND!!! |
| 4509 | |
| 4510 | // Copyright 2007, Google Inc. |
| 4511 | // All rights reserved. |
| 4512 | // |
| 4513 | // Redistribution and use in source and binary forms, with or without |
| 4514 | // modification, are permitted provided that the following conditions are |
| 4515 | // met: |
| 4516 | // |
| 4517 | // * Redistributions of source code must retain the above copyright |
| 4518 | // notice, this list of conditions and the following disclaimer. |
| 4519 | // * Redistributions in binary form must reproduce the above |
| 4520 | // copyright notice, this list of conditions and the following disclaimer |
| 4521 | // in the documentation and/or other materials provided with the |
| 4522 | // distribution. |
| 4523 | // * Neither the name of Google Inc. nor the names of its |
| 4524 | // contributors may be used to endorse or promote products derived from |
| 4525 | // this software without specific prior written permission. |
| 4526 | // |
| 4527 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 4528 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 4529 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 4530 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 4531 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 4532 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 4533 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 4534 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 4535 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 4536 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 4537 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 4538 | // |
| 4539 | // Author: wan@google.com (Zhanyong Wan) |
| 4540 | |
| 4541 | // Google Mock - a framework for writing C++ mock classes. |
| 4542 | // |
| 4543 | // This file implements function mockers of various arities. |
| 4544 | |
| 4545 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ |
| 4546 | #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ |
| 4547 | |
| 4548 | // Copyright 2007, Google Inc. |
| 4549 | // All rights reserved. |
| 4550 | // |
| 4551 | // Redistribution and use in source and binary forms, with or without |
| 4552 | // modification, are permitted provided that the following conditions are |
| 4553 | // met: |
| 4554 | // |
| 4555 | // * Redistributions of source code must retain the above copyright |
| 4556 | // notice, this list of conditions and the following disclaimer. |
| 4557 | // * Redistributions in binary form must reproduce the above |
| 4558 | // copyright notice, this list of conditions and the following disclaimer |
| 4559 | // in the documentation and/or other materials provided with the |
| 4560 | // distribution. |
| 4561 | // * Neither the name of Google Inc. nor the names of its |
| 4562 | // contributors may be used to endorse or promote products derived from |
| 4563 | // this software without specific prior written permission. |
| 4564 | // |
| 4565 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 4566 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 4567 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 4568 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 4569 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 4570 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 4571 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 4572 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 4573 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 4574 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 4575 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 4576 | // |
| 4577 | // Author: wan@google.com (Zhanyong Wan) |
| 4578 | |
| 4579 | // Google Mock - a framework for writing C++ mock classes. |
| 4580 | // |
| 4581 | // This file implements the ON_CALL() and EXPECT_CALL() macros. |
| 4582 | // |
| 4583 | // A user can use the ON_CALL() macro to specify the default action of |
| 4584 | // a mock method. The syntax is: |
| 4585 | // |
| 4586 | // ON_CALL(mock_object, Method(argument-matchers)) |
| 4587 | // .With(multi-argument-matcher) |
| 4588 | // .WillByDefault(action); |
| 4589 | // |
| 4590 | // where the .With() clause is optional. |
| 4591 | // |
| 4592 | // A user can use the EXPECT_CALL() macro to specify an expectation on |
| 4593 | // a mock method. The syntax is: |
| 4594 | // |
| 4595 | // EXPECT_CALL(mock_object, Method(argument-matchers)) |
| 4596 | // .With(multi-argument-matchers) |
| 4597 | // .Times(cardinality) |
| 4598 | // .InSequence(sequences) |
| 4599 | // .After(expectations) |
| 4600 | // .WillOnce(action) |
| 4601 | // .WillRepeatedly(action) |
| 4602 | // .RetiresOnSaturation(); |
| 4603 | // |
| 4604 | // where all clauses are optional, and .InSequence()/.After()/ |
| 4605 | // .WillOnce() can appear any number of times. |
| 4606 | |
| 4607 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ |
| 4608 | #define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ |
| 4609 | |
| 4610 | #include <map> |
| 4611 | #include <set> |
| 4612 | #include <sstream> |
| 4613 | #include <string> |
| 4614 | #include <vector> |
| 4615 | |
| 4616 | // Copyright 2007, Google Inc. |
| 4617 | // All rights reserved. |
| 4618 | // |
| 4619 | // Redistribution and use in source and binary forms, with or without |
| 4620 | // modification, are permitted provided that the following conditions are |
| 4621 | // met: |
| 4622 | // |
| 4623 | // * Redistributions of source code must retain the above copyright |
| 4624 | // notice, this list of conditions and the following disclaimer. |
| 4625 | // * Redistributions in binary form must reproduce the above |
| 4626 | // copyright notice, this list of conditions and the following disclaimer |
| 4627 | // in the documentation and/or other materials provided with the |
| 4628 | // distribution. |
| 4629 | // * Neither the name of Google Inc. nor the names of its |
| 4630 | // contributors may be used to endorse or promote products derived from |
| 4631 | // this software without specific prior written permission. |
| 4632 | // |
| 4633 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 4634 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 4635 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 4636 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 4637 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 4638 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 4639 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 4640 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 4641 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 4642 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 4643 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 4644 | // |
| 4645 | // Author: wan@google.com (Zhanyong Wan) |
| 4646 | |
| 4647 | // Google Mock - a framework for writing C++ mock classes. |
| 4648 | // |
| 4649 | // This file implements some commonly used argument matchers. More |
| 4650 | // matchers can be defined by the user implementing the |
| 4651 | // MatcherInterface<T> interface if necessary. |
| 4652 | |
| 4653 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ |
| 4654 | #define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ |
| 4655 | |
| 4656 | #include <algorithm> |
| 4657 | #include <limits> |
| 4658 | #include <ostream> // NOLINT |
| 4659 | #include <sstream> |
| 4660 | #include <string> |
| 4661 | #include <utility> |
| 4662 | #include <vector> |
| 4663 | |
| 4664 | |
| 4665 | namespace testing { |
| 4666 | |
| 4667 | // To implement a matcher Foo for type T, define: |
| 4668 | // 1. a class FooMatcherImpl that implements the |
| 4669 | // MatcherInterface<T> interface, and |
| 4670 | // 2. a factory function that creates a Matcher<T> object from a |
| 4671 | // FooMatcherImpl*. |
| 4672 | // |
| 4673 | // The two-level delegation design makes it possible to allow a user |
| 4674 | // to write "v" instead of "Eq(v)" where a Matcher is expected, which |
| 4675 | // is impossible if we pass matchers by pointers. It also eases |
| 4676 | // ownership management as Matcher objects can now be copied like |
| 4677 | // plain values. |
| 4678 | |
| 4679 | // MatchResultListener is an abstract class. Its << operator can be |
| 4680 | // used by a matcher to explain why a value matches or doesn't match. |
| 4681 | // |
| 4682 | // TODO(wan@google.com): add method |
| 4683 | // bool InterestedInWhy(bool result) const; |
| 4684 | // to indicate whether the listener is interested in why the match |
| 4685 | // result is 'result'. |
| 4686 | class MatchResultListener { |
| 4687 | public: |
| 4688 | // Creates a listener object with the given underlying ostream. The |
| 4689 | // listener does not own the ostream. |
| 4690 | explicit MatchResultListener(::std::ostream* os) : stream_(os) {} |
| 4691 | virtual ~MatchResultListener() = 0; // Makes this class abstract. |
| 4692 | |
| 4693 | // Streams x to the underlying ostream; does nothing if the ostream |
| 4694 | // is NULL. |
| 4695 | template <typename T> |
| 4696 | MatchResultListener& operator<<(const T& x) { |
| 4697 | if (stream_ != NULL) |
| 4698 | *stream_ << x; |
| 4699 | return *this; |
| 4700 | } |
| 4701 | |
| 4702 | // Returns the underlying ostream. |
| 4703 | ::std::ostream* stream() { return stream_; } |
| 4704 | |
| 4705 | // Returns true iff the listener is interested in an explanation of |
| 4706 | // the match result. A matcher's MatchAndExplain() method can use |
| 4707 | // this information to avoid generating the explanation when no one |
| 4708 | // intends to hear it. |
| 4709 | bool IsInterested() const { return stream_ != NULL; } |
| 4710 | |
| 4711 | private: |
| 4712 | ::std::ostream* const stream_; |
| 4713 | |
| 4714 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener); |
| 4715 | }; |
| 4716 | |
| 4717 | inline MatchResultListener::~MatchResultListener() { |
| 4718 | } |
| 4719 | |
| 4720 | // The implementation of a matcher. |
| 4721 | template <typename T> |
| 4722 | class MatcherInterface { |
| 4723 | public: |
| 4724 | virtual ~MatcherInterface() {} |
| 4725 | |
| 4726 | // Returns true iff the matcher matches x; also explains the match |
| 4727 | // result to 'listener', in the form of a non-restrictive relative |
| 4728 | // clause ("which ...", "whose ...", etc) that describes x. For |
| 4729 | // example, the MatchAndExplain() method of the Pointee(...) matcher |
| 4730 | // should generate an explanation like "which points to ...". |
| 4731 | // |
| 4732 | // You should override this method when defining a new matcher. |
| 4733 | // |
| 4734 | // It's the responsibility of the caller (Google Mock) to guarantee |
| 4735 | // that 'listener' is not NULL. This helps to simplify a matcher's |
| 4736 | // implementation when it doesn't care about the performance, as it |
| 4737 | // can talk to 'listener' without checking its validity first. |
| 4738 | // However, in order to implement dummy listeners efficiently, |
| 4739 | // listener->stream() may be NULL. |
| 4740 | virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0; |
| 4741 | |
| 4742 | // Describes this matcher to an ostream. The function should print |
| 4743 | // a verb phrase that describes the property a value matching this |
| 4744 | // matcher should have. The subject of the verb phrase is the value |
| 4745 | // being matched. For example, the DescribeTo() method of the Gt(7) |
| 4746 | // matcher prints "is greater than 7". |
| 4747 | virtual void DescribeTo(::std::ostream* os) const = 0; |
| 4748 | |
| 4749 | // Describes the negation of this matcher to an ostream. For |
| 4750 | // example, if the description of this matcher is "is greater than |
| 4751 | // 7", the negated description could be "is not greater than 7". |
| 4752 | // You are not required to override this when implementing |
| 4753 | // MatcherInterface, but it is highly advised so that your matcher |
| 4754 | // can produce good error messages. |
| 4755 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 4756 | *os << "not ("; |
| 4757 | DescribeTo(os); |
| 4758 | *os << ")"; |
| 4759 | } |
| 4760 | }; |
| 4761 | |
| 4762 | namespace internal { |
| 4763 | |
| 4764 | // A match result listener that ignores the explanation. |
| 4765 | class DummyMatchResultListener : public MatchResultListener { |
| 4766 | public: |
| 4767 | DummyMatchResultListener() : MatchResultListener(NULL) {} |
| 4768 | |
| 4769 | private: |
| 4770 | GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener); |
| 4771 | }; |
| 4772 | |
| 4773 | // A match result listener that forwards the explanation to a given |
| 4774 | // ostream. The difference between this and MatchResultListener is |
| 4775 | // that the former is concrete. |
| 4776 | class StreamMatchResultListener : public MatchResultListener { |
| 4777 | public: |
| 4778 | explicit StreamMatchResultListener(::std::ostream* os) |
| 4779 | : MatchResultListener(os) {} |
| 4780 | |
| 4781 | private: |
| 4782 | GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener); |
| 4783 | }; |
| 4784 | |
| 4785 | // A match result listener that stores the explanation in a string. |
| 4786 | class StringMatchResultListener : public MatchResultListener { |
| 4787 | public: |
| 4788 | StringMatchResultListener() : MatchResultListener(&ss_) {} |
| 4789 | |
| 4790 | // Returns the explanation heard so far. |
| 4791 | internal::string str() const { return ss_.str(); } |
| 4792 | |
| 4793 | private: |
| 4794 | ::std::stringstream ss_; |
| 4795 | |
| 4796 | GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener); |
| 4797 | }; |
| 4798 | |
| 4799 | // An internal class for implementing Matcher<T>, which will derive |
| 4800 | // from it. We put functionalities common to all Matcher<T> |
| 4801 | // specializations here to avoid code duplication. |
| 4802 | template <typename T> |
| 4803 | class MatcherBase { |
| 4804 | public: |
| 4805 | // Returns true iff the matcher matches x; also explains the match |
| 4806 | // result to 'listener'. |
| 4807 | bool MatchAndExplain(T x, MatchResultListener* listener) const { |
| 4808 | return impl_->MatchAndExplain(x, listener); |
| 4809 | } |
| 4810 | |
| 4811 | // Returns true iff this matcher matches x. |
| 4812 | bool Matches(T x) const { |
| 4813 | DummyMatchResultListener dummy; |
| 4814 | return MatchAndExplain(x, &dummy); |
| 4815 | } |
| 4816 | |
| 4817 | // Describes this matcher to an ostream. |
| 4818 | void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } |
| 4819 | |
| 4820 | // Describes the negation of this matcher to an ostream. |
| 4821 | void DescribeNegationTo(::std::ostream* os) const { |
| 4822 | impl_->DescribeNegationTo(os); |
| 4823 | } |
| 4824 | |
| 4825 | // Explains why x matches, or doesn't match, the matcher. |
| 4826 | void ExplainMatchResultTo(T x, ::std::ostream* os) const { |
| 4827 | StreamMatchResultListener listener(os); |
| 4828 | MatchAndExplain(x, &listener); |
| 4829 | } |
| 4830 | |
| 4831 | protected: |
| 4832 | MatcherBase() {} |
| 4833 | |
| 4834 | // Constructs a matcher from its implementation. |
| 4835 | explicit MatcherBase(const MatcherInterface<T>* impl) |
| 4836 | : impl_(impl) {} |
| 4837 | |
| 4838 | virtual ~MatcherBase() {} |
| 4839 | |
| 4840 | private: |
| 4841 | // shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar |
| 4842 | // interfaces. The former dynamically allocates a chunk of memory |
| 4843 | // to hold the reference count, while the latter tracks all |
| 4844 | // references using a circular linked list without allocating |
| 4845 | // memory. It has been observed that linked_ptr performs better in |
| 4846 | // typical scenarios. However, shared_ptr can out-perform |
| 4847 | // linked_ptr when there are many more uses of the copy constructor |
| 4848 | // than the default constructor. |
| 4849 | // |
| 4850 | // If performance becomes a problem, we should see if using |
| 4851 | // shared_ptr helps. |
| 4852 | ::testing::internal::linked_ptr<const MatcherInterface<T> > impl_; |
| 4853 | }; |
| 4854 | |
| 4855 | } // namespace internal |
| 4856 | |
| 4857 | // A Matcher<T> is a copyable and IMMUTABLE (except by assignment) |
| 4858 | // object that can check whether a value of type T matches. The |
| 4859 | // implementation of Matcher<T> is just a linked_ptr to const |
| 4860 | // MatcherInterface<T>, so copying is fairly cheap. Don't inherit |
| 4861 | // from Matcher! |
| 4862 | template <typename T> |
| 4863 | class Matcher : public internal::MatcherBase<T> { |
| 4864 | public: |
| 4865 | // Constructs a null matcher. Needed for storing Matcher objects in STL |
| 4866 | // containers. A default-constructed matcher is not yet initialized. You |
| 4867 | // cannot use it until a valid value has been assigned to it. |
| 4868 | Matcher() {} |
| 4869 | |
| 4870 | // Constructs a matcher from its implementation. |
| 4871 | explicit Matcher(const MatcherInterface<T>* impl) |
| 4872 | : internal::MatcherBase<T>(impl) {} |
| 4873 | |
| 4874 | // Implicit constructor here allows people to write |
| 4875 | // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes |
| 4876 | Matcher(T value); // NOLINT |
| 4877 | }; |
| 4878 | |
| 4879 | // The following two specializations allow the user to write str |
| 4880 | // instead of Eq(str) and "foo" instead of Eq("foo") when a string |
| 4881 | // matcher is expected. |
| 4882 | template <> |
| 4883 | class Matcher<const internal::string&> |
| 4884 | : public internal::MatcherBase<const internal::string&> { |
| 4885 | public: |
| 4886 | Matcher() {} |
| 4887 | |
| 4888 | explicit Matcher(const MatcherInterface<const internal::string&>* impl) |
| 4889 | : internal::MatcherBase<const internal::string&>(impl) {} |
| 4890 | |
| 4891 | // Allows the user to write str instead of Eq(str) sometimes, where |
| 4892 | // str is a string object. |
| 4893 | Matcher(const internal::string& s); // NOLINT |
| 4894 | |
| 4895 | // Allows the user to write "foo" instead of Eq("foo") sometimes. |
| 4896 | Matcher(const char* s); // NOLINT |
| 4897 | }; |
| 4898 | |
| 4899 | template <> |
| 4900 | class Matcher<internal::string> |
| 4901 | : public internal::MatcherBase<internal::string> { |
| 4902 | public: |
| 4903 | Matcher() {} |
| 4904 | |
| 4905 | explicit Matcher(const MatcherInterface<internal::string>* impl) |
| 4906 | : internal::MatcherBase<internal::string>(impl) {} |
| 4907 | |
| 4908 | // Allows the user to write str instead of Eq(str) sometimes, where |
| 4909 | // str is a string object. |
| 4910 | Matcher(const internal::string& s); // NOLINT |
| 4911 | |
| 4912 | // Allows the user to write "foo" instead of Eq("foo") sometimes. |
| 4913 | Matcher(const char* s); // NOLINT |
| 4914 | }; |
| 4915 | |
| 4916 | // The PolymorphicMatcher class template makes it easy to implement a |
| 4917 | // polymorphic matcher (i.e. a matcher that can match values of more |
| 4918 | // than one type, e.g. Eq(n) and NotNull()). |
| 4919 | // |
| 4920 | // To define a polymorphic matcher, a user should provide an Impl |
| 4921 | // class that has a DescribeTo() method and a DescribeNegationTo() |
| 4922 | // method, and define a member function (or member function template) |
| 4923 | // |
| 4924 | // bool MatchAndExplain(const Value& value, |
| 4925 | // MatchResultListener* listener) const; |
| 4926 | // |
| 4927 | // See the definition of NotNull() for a complete example. |
| 4928 | template <class Impl> |
| 4929 | class PolymorphicMatcher { |
| 4930 | public: |
| 4931 | explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {} |
| 4932 | |
| 4933 | // Returns a mutable reference to the underlying matcher |
| 4934 | // implementation object. |
| 4935 | Impl& mutable_impl() { return impl_; } |
| 4936 | |
| 4937 | // Returns an immutable reference to the underlying matcher |
| 4938 | // implementation object. |
| 4939 | const Impl& impl() const { return impl_; } |
| 4940 | |
| 4941 | template <typename T> |
| 4942 | operator Matcher<T>() const { |
| 4943 | return Matcher<T>(new MonomorphicImpl<T>(impl_)); |
| 4944 | } |
| 4945 | |
| 4946 | private: |
| 4947 | template <typename T> |
| 4948 | class MonomorphicImpl : public MatcherInterface<T> { |
| 4949 | public: |
| 4950 | explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} |
| 4951 | |
| 4952 | virtual void DescribeTo(::std::ostream* os) const { |
| 4953 | impl_.DescribeTo(os); |
| 4954 | } |
| 4955 | |
| 4956 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 4957 | impl_.DescribeNegationTo(os); |
| 4958 | } |
| 4959 | |
| 4960 | virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { |
| 4961 | return impl_.MatchAndExplain(x, listener); |
| 4962 | } |
| 4963 | |
| 4964 | private: |
| 4965 | const Impl impl_; |
| 4966 | |
| 4967 | GTEST_DISALLOW_ASSIGN_(MonomorphicImpl); |
| 4968 | }; |
| 4969 | |
| 4970 | Impl impl_; |
| 4971 | |
| 4972 | GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher); |
| 4973 | }; |
| 4974 | |
| 4975 | // Creates a matcher from its implementation. This is easier to use |
| 4976 | // than the Matcher<T> constructor as it doesn't require you to |
| 4977 | // explicitly write the template argument, e.g. |
| 4978 | // |
| 4979 | // MakeMatcher(foo); |
| 4980 | // vs |
| 4981 | // Matcher<const string&>(foo); |
| 4982 | template <typename T> |
| 4983 | inline Matcher<T> MakeMatcher(const MatcherInterface<T>* impl) { |
| 4984 | return Matcher<T>(impl); |
| 4985 | }; |
| 4986 | |
| 4987 | // Creates a polymorphic matcher from its implementation. This is |
| 4988 | // easier to use than the PolymorphicMatcher<Impl> constructor as it |
| 4989 | // doesn't require you to explicitly write the template argument, e.g. |
| 4990 | // |
| 4991 | // MakePolymorphicMatcher(foo); |
| 4992 | // vs |
| 4993 | // PolymorphicMatcher<TypeOfFoo>(foo); |
| 4994 | template <class Impl> |
| 4995 | inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) { |
| 4996 | return PolymorphicMatcher<Impl>(impl); |
| 4997 | } |
| 4998 | |
| 4999 | // In order to be safe and clear, casting between different matcher |
| 5000 | // types is done explicitly via MatcherCast<T>(m), which takes a |
| 5001 | // matcher m and returns a Matcher<T>. It compiles only when T can be |
| 5002 | // statically converted to the argument type of m. |
| 5003 | template <typename T, typename M> |
| 5004 | Matcher<T> MatcherCast(M m); |
| 5005 | |
| 5006 | // Implements SafeMatcherCast(). |
| 5007 | // |
| 5008 | // We use an intermediate class to do the actual safe casting as Nokia's |
| 5009 | // Symbian compiler cannot decide between |
| 5010 | // template <T, M> ... (M) and |
| 5011 | // template <T, U> ... (const Matcher<U>&) |
| 5012 | // for function templates but can for member function templates. |
| 5013 | template <typename T> |
| 5014 | class SafeMatcherCastImpl { |
| 5015 | public: |
| 5016 | // This overload handles polymorphic matchers only since monomorphic |
| 5017 | // matchers are handled by the next one. |
| 5018 | template <typename M> |
| 5019 | static inline Matcher<T> Cast(M polymorphic_matcher) { |
| 5020 | return Matcher<T>(polymorphic_matcher); |
| 5021 | } |
| 5022 | |
| 5023 | // This overload handles monomorphic matchers. |
| 5024 | // |
| 5025 | // In general, if type T can be implicitly converted to type U, we can |
| 5026 | // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is |
| 5027 | // contravariant): just keep a copy of the original Matcher<U>, convert the |
| 5028 | // argument from type T to U, and then pass it to the underlying Matcher<U>. |
| 5029 | // The only exception is when U is a reference and T is not, as the |
| 5030 | // underlying Matcher<U> may be interested in the argument's address, which |
| 5031 | // is not preserved in the conversion from T to U. |
| 5032 | template <typename U> |
| 5033 | static inline Matcher<T> Cast(const Matcher<U>& matcher) { |
| 5034 | // Enforce that T can be implicitly converted to U. |
| 5035 | GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible<T, U>::value), |
| 5036 | T_must_be_implicitly_convertible_to_U); |
| 5037 | // Enforce that we are not converting a non-reference type T to a reference |
| 5038 | // type U. |
| 5039 | GTEST_COMPILE_ASSERT_( |
| 5040 | internal::is_reference<T>::value || !internal::is_reference<U>::value, |
| 5041 | cannot_convert_non_referentce_arg_to_reference); |
| 5042 | // In case both T and U are arithmetic types, enforce that the |
| 5043 | // conversion is not lossy. |
| 5044 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT; |
| 5045 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU; |
| 5046 | const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther; |
| 5047 | const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther; |
| 5048 | GTEST_COMPILE_ASSERT_( |
| 5049 | kTIsOther || kUIsOther || |
| 5050 | (internal::LosslessArithmeticConvertible<RawT, RawU>::value), |
| 5051 | conversion_of_arithmetic_types_must_be_lossless); |
| 5052 | return MatcherCast<T>(matcher); |
| 5053 | } |
| 5054 | }; |
| 5055 | |
| 5056 | template <typename T, typename M> |
| 5057 | inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) { |
| 5058 | return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher); |
| 5059 | } |
| 5060 | |
| 5061 | // A<T>() returns a matcher that matches any value of type T. |
| 5062 | template <typename T> |
| 5063 | Matcher<T> A(); |
| 5064 | |
| 5065 | // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION |
| 5066 | // and MUST NOT BE USED IN USER CODE!!! |
| 5067 | namespace internal { |
| 5068 | |
| 5069 | // If the explanation is not empty, prints it to the ostream. |
| 5070 | inline void PrintIfNotEmpty(const internal::string& explanation, |
| 5071 | std::ostream* os) { |
| 5072 | if (explanation != "" && os != NULL) { |
| 5073 | *os << ", " << explanation; |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | // Returns true if the given type name is easy to read by a human. |
| 5078 | // This is used to decide whether printing the type of a value might |
| 5079 | // be helpful. |
| 5080 | inline bool IsReadableTypeName(const string& type_name) { |
| 5081 | // We consider a type name readable if it's short or doesn't contain |
| 5082 | // a template or function type. |
| 5083 | return (type_name.length() <= 20 || |
| 5084 | type_name.find_first_of("<(") == string::npos); |
| 5085 | } |
| 5086 | |
| 5087 | // Matches the value against the given matcher, prints the value and explains |
| 5088 | // the match result to the listener. Returns the match result. |
| 5089 | // 'listener' must not be NULL. |
| 5090 | // Value cannot be passed by const reference, because some matchers take a |
| 5091 | // non-const argument. |
| 5092 | template <typename Value, typename T> |
| 5093 | bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher, |
| 5094 | MatchResultListener* listener) { |
| 5095 | if (!listener->IsInterested()) { |
| 5096 | // If the listener is not interested, we do not need to construct the |
| 5097 | // inner explanation. |
| 5098 | return matcher.Matches(value); |
| 5099 | } |
| 5100 | |
| 5101 | StringMatchResultListener inner_listener; |
| 5102 | const bool match = matcher.MatchAndExplain(value, &inner_listener); |
| 5103 | |
| 5104 | UniversalPrint(value, listener->stream()); |
| 5105 | #if GTEST_HAS_RTTI |
| 5106 | const string& type_name = GetTypeName<Value>(); |
| 5107 | if (IsReadableTypeName(type_name)) |
| 5108 | *listener->stream() << " (of type " << type_name << ")"; |
| 5109 | #endif |
| 5110 | PrintIfNotEmpty(inner_listener.str(), listener->stream()); |
| 5111 | |
| 5112 | return match; |
| 5113 | } |
| 5114 | |
| 5115 | // An internal helper class for doing compile-time loop on a tuple's |
| 5116 | // fields. |
| 5117 | template <size_t N> |
| 5118 | class TuplePrefix { |
| 5119 | public: |
| 5120 | // TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true |
| 5121 | // iff the first N fields of matcher_tuple matches the first N |
| 5122 | // fields of value_tuple, respectively. |
| 5123 | template <typename MatcherTuple, typename ValueTuple> |
| 5124 | static bool Matches(const MatcherTuple& matcher_tuple, |
| 5125 | const ValueTuple& value_tuple) { |
| 5126 | using ::std::tr1::get; |
| 5127 | return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple) |
| 5128 | && get<N - 1>(matcher_tuple).Matches(get<N - 1>(value_tuple)); |
| 5129 | } |
| 5130 | |
| 5131 | // TuplePrefix<N>::ExplainMatchFailuresTo(matchers, values, os) |
| 5132 | // describes failures in matching the first N fields of matchers |
| 5133 | // against the first N fields of values. If there is no failure, |
| 5134 | // nothing will be streamed to os. |
| 5135 | template <typename MatcherTuple, typename ValueTuple> |
| 5136 | static void ExplainMatchFailuresTo(const MatcherTuple& matchers, |
| 5137 | const ValueTuple& values, |
| 5138 | ::std::ostream* os) { |
| 5139 | using ::std::tr1::tuple_element; |
| 5140 | using ::std::tr1::get; |
| 5141 | |
| 5142 | // First, describes failures in the first N - 1 fields. |
| 5143 | TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os); |
| 5144 | |
| 5145 | // Then describes the failure (if any) in the (N - 1)-th (0-based) |
| 5146 | // field. |
| 5147 | typename tuple_element<N - 1, MatcherTuple>::type matcher = |
| 5148 | get<N - 1>(matchers); |
| 5149 | typedef typename tuple_element<N - 1, ValueTuple>::type Value; |
| 5150 | Value value = get<N - 1>(values); |
| 5151 | StringMatchResultListener listener; |
| 5152 | if (!matcher.MatchAndExplain(value, &listener)) { |
| 5153 | // TODO(wan): include in the message the name of the parameter |
| 5154 | // as used in MOCK_METHOD*() when possible. |
| 5155 | *os << " Expected arg #" << N - 1 << ": "; |
| 5156 | get<N - 1>(matchers).DescribeTo(os); |
| 5157 | *os << "\n Actual: "; |
| 5158 | // We remove the reference in type Value to prevent the |
| 5159 | // universal printer from printing the address of value, which |
| 5160 | // isn't interesting to the user most of the time. The |
| 5161 | // matcher's MatchAndExplain() method handles the case when |
| 5162 | // the address is interesting. |
| 5163 | internal::UniversalPrint(value, os); |
| 5164 | PrintIfNotEmpty(listener.str(), os); |
| 5165 | *os << "\n"; |
| 5166 | } |
| 5167 | } |
| 5168 | }; |
| 5169 | |
| 5170 | // The base case. |
| 5171 | template <> |
| 5172 | class TuplePrefix<0> { |
| 5173 | public: |
| 5174 | template <typename MatcherTuple, typename ValueTuple> |
| 5175 | static bool Matches(const MatcherTuple& /* matcher_tuple */, |
| 5176 | const ValueTuple& /* value_tuple */) { |
| 5177 | return true; |
| 5178 | } |
| 5179 | |
| 5180 | template <typename MatcherTuple, typename ValueTuple> |
| 5181 | static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */, |
| 5182 | const ValueTuple& /* values */, |
| 5183 | ::std::ostream* /* os */) {} |
| 5184 | }; |
| 5185 | |
| 5186 | // TupleMatches(matcher_tuple, value_tuple) returns true iff all |
| 5187 | // matchers in matcher_tuple match the corresponding fields in |
| 5188 | // value_tuple. It is a compiler error if matcher_tuple and |
| 5189 | // value_tuple have different number of fields or incompatible field |
| 5190 | // types. |
| 5191 | template <typename MatcherTuple, typename ValueTuple> |
| 5192 | bool TupleMatches(const MatcherTuple& matcher_tuple, |
| 5193 | const ValueTuple& value_tuple) { |
| 5194 | using ::std::tr1::tuple_size; |
| 5195 | // Makes sure that matcher_tuple and value_tuple have the same |
| 5196 | // number of fields. |
| 5197 | GTEST_COMPILE_ASSERT_(tuple_size<MatcherTuple>::value == |
| 5198 | tuple_size<ValueTuple>::value, |
| 5199 | matcher_and_value_have_different_numbers_of_fields); |
| 5200 | return TuplePrefix<tuple_size<ValueTuple>::value>:: |
| 5201 | Matches(matcher_tuple, value_tuple); |
| 5202 | } |
| 5203 | |
| 5204 | // Describes failures in matching matchers against values. If there |
| 5205 | // is no failure, nothing will be streamed to os. |
| 5206 | template <typename MatcherTuple, typename ValueTuple> |
| 5207 | void ExplainMatchFailureTupleTo(const MatcherTuple& matchers, |
| 5208 | const ValueTuple& values, |
| 5209 | ::std::ostream* os) { |
| 5210 | using ::std::tr1::tuple_size; |
| 5211 | TuplePrefix<tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo( |
| 5212 | matchers, values, os); |
| 5213 | } |
| 5214 | |
| 5215 | // The MatcherCastImpl class template is a helper for implementing |
| 5216 | // MatcherCast(). We need this helper in order to partially |
| 5217 | // specialize the implementation of MatcherCast() (C++ allows |
| 5218 | // class/struct templates to be partially specialized, but not |
| 5219 | // function templates.). |
| 5220 | |
| 5221 | // This general version is used when MatcherCast()'s argument is a |
| 5222 | // polymorphic matcher (i.e. something that can be converted to a |
| 5223 | // Matcher but is not one yet; for example, Eq(value)). |
| 5224 | template <typename T, typename M> |
| 5225 | class MatcherCastImpl { |
| 5226 | public: |
| 5227 | static Matcher<T> Cast(M polymorphic_matcher) { |
| 5228 | return Matcher<T>(polymorphic_matcher); |
| 5229 | } |
| 5230 | }; |
| 5231 | |
| 5232 | // This more specialized version is used when MatcherCast()'s argument |
| 5233 | // is already a Matcher. This only compiles when type T can be |
| 5234 | // statically converted to type U. |
| 5235 | template <typename T, typename U> |
| 5236 | class MatcherCastImpl<T, Matcher<U> > { |
| 5237 | public: |
| 5238 | static Matcher<T> Cast(const Matcher<U>& source_matcher) { |
| 5239 | return Matcher<T>(new Impl(source_matcher)); |
| 5240 | } |
| 5241 | |
| 5242 | private: |
| 5243 | class Impl : public MatcherInterface<T> { |
| 5244 | public: |
| 5245 | explicit Impl(const Matcher<U>& source_matcher) |
| 5246 | : source_matcher_(source_matcher) {} |
| 5247 | |
| 5248 | // We delegate the matching logic to the source matcher. |
| 5249 | virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { |
| 5250 | return source_matcher_.MatchAndExplain(static_cast<U>(x), listener); |
| 5251 | } |
| 5252 | |
| 5253 | virtual void DescribeTo(::std::ostream* os) const { |
| 5254 | source_matcher_.DescribeTo(os); |
| 5255 | } |
| 5256 | |
| 5257 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 5258 | source_matcher_.DescribeNegationTo(os); |
| 5259 | } |
| 5260 | |
| 5261 | private: |
| 5262 | const Matcher<U> source_matcher_; |
| 5263 | |
| 5264 | GTEST_DISALLOW_ASSIGN_(Impl); |
| 5265 | }; |
| 5266 | }; |
| 5267 | |
| 5268 | // This even more specialized version is used for efficiently casting |
| 5269 | // a matcher to its own type. |
| 5270 | template <typename T> |
| 5271 | class MatcherCastImpl<T, Matcher<T> > { |
| 5272 | public: |
| 5273 | static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; } |
| 5274 | }; |
| 5275 | |
| 5276 | // Implements A<T>(). |
| 5277 | template <typename T> |
| 5278 | class AnyMatcherImpl : public MatcherInterface<T> { |
| 5279 | public: |
| 5280 | virtual bool MatchAndExplain( |
| 5281 | T /* x */, MatchResultListener* /* listener */) const { return true; } |
| 5282 | virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; } |
| 5283 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 5284 | // This is mostly for completeness' safe, as it's not very useful |
| 5285 | // to write Not(A<bool>()). However we cannot completely rule out |
| 5286 | // such a possibility, and it doesn't hurt to be prepared. |
| 5287 | *os << "never matches"; |
| 5288 | } |
| 5289 | }; |
| 5290 | |
| 5291 | // Implements _, a matcher that matches any value of any |
| 5292 | // type. This is a polymorphic matcher, so we need a template type |
| 5293 | // conversion operator to make it appearing as a Matcher<T> for any |
| 5294 | // type T. |
| 5295 | class AnythingMatcher { |
| 5296 | public: |
| 5297 | template <typename T> |
| 5298 | operator Matcher<T>() const { return A<T>(); } |
| 5299 | }; |
| 5300 | |
| 5301 | // Implements a matcher that compares a given value with a |
| 5302 | // pre-supplied value using one of the ==, <=, <, etc, operators. The |
| 5303 | // two values being compared don't have to have the same type. |
| 5304 | // |
| 5305 | // The matcher defined here is polymorphic (for example, Eq(5) can be |
| 5306 | // used to match an int, a short, a double, etc). Therefore we use |
| 5307 | // a template type conversion operator in the implementation. |
| 5308 | // |
| 5309 | // We define this as a macro in order to eliminate duplicated source |
| 5310 | // code. |
| 5311 | // |
| 5312 | // The following template definition assumes that the Rhs parameter is |
| 5313 | // a "bare" type (i.e. neither 'const T' nor 'T&'). |
| 5314 | #define GMOCK_IMPLEMENT_COMPARISON_MATCHER_( \ |
| 5315 | name, op, relation, negated_relation) \ |
| 5316 | template <typename Rhs> class name##Matcher { \ |
| 5317 | public: \ |
| 5318 | explicit name##Matcher(const Rhs& rhs) : rhs_(rhs) {} \ |
| 5319 | template <typename Lhs> \ |
| 5320 | operator Matcher<Lhs>() const { \ |
| 5321 | return MakeMatcher(new Impl<Lhs>(rhs_)); \ |
| 5322 | } \ |
| 5323 | private: \ |
| 5324 | template <typename Lhs> \ |
| 5325 | class Impl : public MatcherInterface<Lhs> { \ |
| 5326 | public: \ |
| 5327 | explicit Impl(const Rhs& rhs) : rhs_(rhs) {} \ |
| 5328 | virtual bool MatchAndExplain(\ |
| 5329 | Lhs lhs, MatchResultListener* /* listener */) const { \ |
| 5330 | return lhs op rhs_; \ |
| 5331 | } \ |
| 5332 | virtual void DescribeTo(::std::ostream* os) const { \ |
| 5333 | *os << relation " "; \ |
| 5334 | UniversalPrint(rhs_, os); \ |
| 5335 | } \ |
| 5336 | virtual void DescribeNegationTo(::std::ostream* os) const { \ |
| 5337 | *os << negated_relation " "; \ |
| 5338 | UniversalPrint(rhs_, os); \ |
| 5339 | } \ |
| 5340 | private: \ |
| 5341 | Rhs rhs_; \ |
| 5342 | GTEST_DISALLOW_ASSIGN_(Impl); \ |
| 5343 | }; \ |
| 5344 | Rhs rhs_; \ |
| 5345 | GTEST_DISALLOW_ASSIGN_(name##Matcher); \ |
| 5346 | } |
| 5347 | |
| 5348 | // Implements Eq(v), Ge(v), Gt(v), Le(v), Lt(v), and Ne(v) |
| 5349 | // respectively. |
| 5350 | GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to"); |
| 5351 | GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ge, >=, "is >=", "isn't >="); |
| 5352 | GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Gt, >, "is >", "isn't >"); |
| 5353 | GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Le, <=, "is <=", "isn't <="); |
| 5354 | GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Lt, <, "is <", "isn't <"); |
| 5355 | GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ne, !=, "isn't equal to", "is equal to"); |
| 5356 | |
| 5357 | #undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_ |
| 5358 | |
| 5359 | // Implements the polymorphic IsNull() matcher, which matches any raw or smart |
| 5360 | // pointer that is NULL. |
| 5361 | class IsNullMatcher { |
| 5362 | public: |
| 5363 | template <typename Pointer> |
| 5364 | bool MatchAndExplain(const Pointer& p, |
| 5365 | MatchResultListener* /* listener */) const { |
| 5366 | return GetRawPointer(p) == NULL; |
| 5367 | } |
| 5368 | |
| 5369 | void DescribeTo(::std::ostream* os) const { *os << "is NULL"; } |
| 5370 | void DescribeNegationTo(::std::ostream* os) const { |
| 5371 | *os << "isn't NULL"; |
| 5372 | } |
| 5373 | }; |
| 5374 | |
| 5375 | // Implements the polymorphic NotNull() matcher, which matches any raw or smart |
| 5376 | // pointer that is not NULL. |
| 5377 | class NotNullMatcher { |
| 5378 | public: |
| 5379 | template <typename Pointer> |
| 5380 | bool MatchAndExplain(const Pointer& p, |
| 5381 | MatchResultListener* /* listener */) const { |
| 5382 | return GetRawPointer(p) != NULL; |
| 5383 | } |
| 5384 | |
| 5385 | void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; } |
| 5386 | void DescribeNegationTo(::std::ostream* os) const { |
| 5387 | *os << "is NULL"; |
| 5388 | } |
| 5389 | }; |
| 5390 | |
| 5391 | // Ref(variable) matches any argument that is a reference to |
| 5392 | // 'variable'. This matcher is polymorphic as it can match any |
| 5393 | // super type of the type of 'variable'. |
| 5394 | // |
| 5395 | // The RefMatcher template class implements Ref(variable). It can |
| 5396 | // only be instantiated with a reference type. This prevents a user |
| 5397 | // from mistakenly using Ref(x) to match a non-reference function |
| 5398 | // argument. For example, the following will righteously cause a |
| 5399 | // compiler error: |
| 5400 | // |
| 5401 | // int n; |
| 5402 | // Matcher<int> m1 = Ref(n); // This won't compile. |
| 5403 | // Matcher<int&> m2 = Ref(n); // This will compile. |
| 5404 | template <typename T> |
| 5405 | class RefMatcher; |
| 5406 | |
| 5407 | template <typename T> |
| 5408 | class RefMatcher<T&> { |
| 5409 | // Google Mock is a generic framework and thus needs to support |
| 5410 | // mocking any function types, including those that take non-const |
| 5411 | // reference arguments. Therefore the template parameter T (and |
| 5412 | // Super below) can be instantiated to either a const type or a |
| 5413 | // non-const type. |
| 5414 | public: |
| 5415 | // RefMatcher() takes a T& instead of const T&, as we want the |
| 5416 | // compiler to catch using Ref(const_value) as a matcher for a |
| 5417 | // non-const reference. |
| 5418 | explicit RefMatcher(T& x) : object_(x) {} // NOLINT |
| 5419 | |
| 5420 | template <typename Super> |
| 5421 | operator Matcher<Super&>() const { |
| 5422 | // By passing object_ (type T&) to Impl(), which expects a Super&, |
| 5423 | // we make sure that Super is a super type of T. In particular, |
| 5424 | // this catches using Ref(const_value) as a matcher for a |
| 5425 | // non-const reference, as you cannot implicitly convert a const |
| 5426 | // reference to a non-const reference. |
| 5427 | return MakeMatcher(new Impl<Super>(object_)); |
| 5428 | } |
| 5429 | |
| 5430 | private: |
| 5431 | template <typename Super> |
| 5432 | class Impl : public MatcherInterface<Super&> { |
| 5433 | public: |
| 5434 | explicit Impl(Super& x) : object_(x) {} // NOLINT |
| 5435 | |
| 5436 | // MatchAndExplain() takes a Super& (as opposed to const Super&) |
| 5437 | // in order to match the interface MatcherInterface<Super&>. |
| 5438 | virtual bool MatchAndExplain( |
| 5439 | Super& x, MatchResultListener* listener) const { |
| 5440 | *listener << "which is located @" << static_cast<const void*>(&x); |
| 5441 | return &x == &object_; |
| 5442 | } |
| 5443 | |
| 5444 | virtual void DescribeTo(::std::ostream* os) const { |
| 5445 | *os << "references the variable "; |
| 5446 | UniversalPrinter<Super&>::Print(object_, os); |
| 5447 | } |
| 5448 | |
| 5449 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 5450 | *os << "does not reference the variable "; |
| 5451 | UniversalPrinter<Super&>::Print(object_, os); |
| 5452 | } |
| 5453 | |
| 5454 | private: |
| 5455 | const Super& object_; |
| 5456 | |
| 5457 | GTEST_DISALLOW_ASSIGN_(Impl); |
| 5458 | }; |
| 5459 | |
| 5460 | T& object_; |
| 5461 | |
| 5462 | GTEST_DISALLOW_ASSIGN_(RefMatcher); |
| 5463 | }; |
| 5464 | |
| 5465 | // Polymorphic helper functions for narrow and wide string matchers. |
| 5466 | inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) { |
| 5467 | return String::CaseInsensitiveCStringEquals(lhs, rhs); |
| 5468 | } |
| 5469 | |
| 5470 | inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs, |
| 5471 | const wchar_t* rhs) { |
| 5472 | return String::CaseInsensitiveWideCStringEquals(lhs, rhs); |
| 5473 | } |
| 5474 | |
| 5475 | // String comparison for narrow or wide strings that can have embedded NUL |
| 5476 | // characters. |
| 5477 | template <typename StringType> |
| 5478 | bool CaseInsensitiveStringEquals(const StringType& s1, |
| 5479 | const StringType& s2) { |
| 5480 | // Are the heads equal? |
| 5481 | if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) { |
| 5482 | return false; |
| 5483 | } |
| 5484 | |
| 5485 | // Skip the equal heads. |
| 5486 | const typename StringType::value_type nul = 0; |
| 5487 | const size_t i1 = s1.find(nul), i2 = s2.find(nul); |
| 5488 | |
| 5489 | // Are we at the end of either s1 or s2? |
| 5490 | if (i1 == StringType::npos || i2 == StringType::npos) { |
| 5491 | return i1 == i2; |
| 5492 | } |
| 5493 | |
| 5494 | // Are the tails equal? |
| 5495 | return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1)); |
| 5496 | } |
| 5497 | |
| 5498 | // String matchers. |
| 5499 | |
| 5500 | // Implements equality-based string matchers like StrEq, StrCaseNe, and etc. |
| 5501 | template <typename StringType> |
| 5502 | class StrEqualityMatcher { |
| 5503 | public: |
| 5504 | typedef typename StringType::const_pointer ConstCharPointer; |
| 5505 | |
| 5506 | StrEqualityMatcher(const StringType& str, bool expect_eq, |
| 5507 | bool case_sensitive) |
| 5508 | : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {} |
| 5509 | |
| 5510 | // When expect_eq_ is true, returns true iff s is equal to string_; |
| 5511 | // otherwise returns true iff s is not equal to string_. |
| 5512 | bool MatchAndExplain(ConstCharPointer s, |
| 5513 | MatchResultListener* listener) const { |
| 5514 | if (s == NULL) { |
| 5515 | return !expect_eq_; |
| 5516 | } |
| 5517 | return MatchAndExplain(StringType(s), listener); |
| 5518 | } |
| 5519 | |
| 5520 | bool MatchAndExplain(const StringType& s, |
| 5521 | MatchResultListener* /* listener */) const { |
| 5522 | const bool eq = case_sensitive_ ? s == string_ : |
| 5523 | CaseInsensitiveStringEquals(s, string_); |
| 5524 | return expect_eq_ == eq; |
| 5525 | } |
| 5526 | |
| 5527 | void DescribeTo(::std::ostream* os) const { |
| 5528 | DescribeToHelper(expect_eq_, os); |
| 5529 | } |
| 5530 | |
| 5531 | void DescribeNegationTo(::std::ostream* os) const { |
| 5532 | DescribeToHelper(!expect_eq_, os); |
| 5533 | } |
| 5534 | |
| 5535 | private: |
| 5536 | void DescribeToHelper(bool expect_eq, ::std::ostream* os) const { |
| 5537 | *os << (expect_eq ? "is " : "isn't "); |
| 5538 | *os << "equal to "; |
| 5539 | if (!case_sensitive_) { |
| 5540 | *os << "(ignoring case) "; |
| 5541 | } |
| 5542 | UniversalPrint(string_, os); |
| 5543 | } |
| 5544 | |
| 5545 | const StringType string_; |
| 5546 | const bool expect_eq_; |
| 5547 | const bool case_sensitive_; |
| 5548 | |
| 5549 | GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher); |
| 5550 | }; |
| 5551 | |
| 5552 | // Implements the polymorphic HasSubstr(substring) matcher, which |
| 5553 | // can be used as a Matcher<T> as long as T can be converted to a |
| 5554 | // string. |
| 5555 | template <typename StringType> |
| 5556 | class HasSubstrMatcher { |
| 5557 | public: |
| 5558 | typedef typename StringType::const_pointer ConstCharPointer; |
| 5559 | |
| 5560 | explicit HasSubstrMatcher(const StringType& substring) |
| 5561 | : substring_(substring) {} |
| 5562 | |
| 5563 | // These overloaded methods allow HasSubstr(substring) to be used as a |
| 5564 | // Matcher<T> as long as T can be converted to string. Returns true |
| 5565 | // iff s contains substring_ as a substring. |
| 5566 | bool MatchAndExplain(ConstCharPointer s, |
| 5567 | MatchResultListener* listener) const { |
| 5568 | return s != NULL && MatchAndExplain(StringType(s), listener); |
| 5569 | } |
| 5570 | |
| 5571 | bool MatchAndExplain(const StringType& s, |
| 5572 | MatchResultListener* /* listener */) const { |
| 5573 | return s.find(substring_) != StringType::npos; |
| 5574 | } |
| 5575 | |
| 5576 | // Describes what this matcher matches. |
| 5577 | void DescribeTo(::std::ostream* os) const { |
| 5578 | *os << "has substring "; |
| 5579 | UniversalPrint(substring_, os); |
| 5580 | } |
| 5581 | |
| 5582 | void DescribeNegationTo(::std::ostream* os) const { |
| 5583 | *os << "has no substring "; |
| 5584 | UniversalPrint(substring_, os); |
| 5585 | } |
| 5586 | |
| 5587 | private: |
| 5588 | const StringType substring_; |
| 5589 | |
| 5590 | GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher); |
| 5591 | }; |
| 5592 | |
| 5593 | // Implements the polymorphic StartsWith(substring) matcher, which |
| 5594 | // can be used as a Matcher<T> as long as T can be converted to a |
| 5595 | // string. |
| 5596 | template <typename StringType> |
| 5597 | class StartsWithMatcher { |
| 5598 | public: |
| 5599 | typedef typename StringType::const_pointer ConstCharPointer; |
| 5600 | |
| 5601 | explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) { |
| 5602 | } |
| 5603 | |
| 5604 | // These overloaded methods allow StartsWith(prefix) to be used as a |
| 5605 | // Matcher<T> as long as T can be converted to string. Returns true |
| 5606 | // iff s starts with prefix_. |
| 5607 | bool MatchAndExplain(ConstCharPointer s, |
| 5608 | MatchResultListener* listener) const { |
| 5609 | return s != NULL && MatchAndExplain(StringType(s), listener); |
| 5610 | } |
| 5611 | |
| 5612 | bool MatchAndExplain(const StringType& s, |
| 5613 | MatchResultListener* /* listener */) const { |
| 5614 | return s.length() >= prefix_.length() && |
| 5615 | s.substr(0, prefix_.length()) == prefix_; |
| 5616 | } |
| 5617 | |
| 5618 | void DescribeTo(::std::ostream* os) const { |
| 5619 | *os << "starts with "; |
| 5620 | UniversalPrint(prefix_, os); |
| 5621 | } |
| 5622 | |
| 5623 | void DescribeNegationTo(::std::ostream* os) const { |
| 5624 | *os << "doesn't start with "; |
| 5625 | UniversalPrint(prefix_, os); |
| 5626 | } |
| 5627 | |
| 5628 | private: |
| 5629 | const StringType prefix_; |
| 5630 | |
| 5631 | GTEST_DISALLOW_ASSIGN_(StartsWithMatcher); |
| 5632 | }; |
| 5633 | |
| 5634 | // Implements the polymorphic EndsWith(substring) matcher, which |
| 5635 | // can be used as a Matcher<T> as long as T can be converted to a |
| 5636 | // string. |
| 5637 | template <typename StringType> |
| 5638 | class EndsWithMatcher { |
| 5639 | public: |
| 5640 | typedef typename StringType::const_pointer ConstCharPointer; |
| 5641 | |
| 5642 | explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {} |
| 5643 | |
| 5644 | // These overloaded methods allow EndsWith(suffix) to be used as a |
| 5645 | // Matcher<T> as long as T can be converted to string. Returns true |
| 5646 | // iff s ends with suffix_. |
| 5647 | bool MatchAndExplain(ConstCharPointer s, |
| 5648 | MatchResultListener* listener) const { |
| 5649 | return s != NULL && MatchAndExplain(StringType(s), listener); |
| 5650 | } |
| 5651 | |
| 5652 | bool MatchAndExplain(const StringType& s, |
| 5653 | MatchResultListener* /* listener */) const { |
| 5654 | return s.length() >= suffix_.length() && |
| 5655 | s.substr(s.length() - suffix_.length()) == suffix_; |
| 5656 | } |
| 5657 | |
| 5658 | void DescribeTo(::std::ostream* os) const { |
| 5659 | *os << "ends with "; |
| 5660 | UniversalPrint(suffix_, os); |
| 5661 | } |
| 5662 | |
| 5663 | void DescribeNegationTo(::std::ostream* os) const { |
| 5664 | *os << "doesn't end with "; |
| 5665 | UniversalPrint(suffix_, os); |
| 5666 | } |
| 5667 | |
| 5668 | private: |
| 5669 | const StringType suffix_; |
| 5670 | |
| 5671 | GTEST_DISALLOW_ASSIGN_(EndsWithMatcher); |
| 5672 | }; |
| 5673 | |
| 5674 | // Implements polymorphic matchers MatchesRegex(regex) and |
| 5675 | // ContainsRegex(regex), which can be used as a Matcher<T> as long as |
| 5676 | // T can be converted to a string. |
| 5677 | class MatchesRegexMatcher { |
| 5678 | public: |
| 5679 | MatchesRegexMatcher(const RE* regex, bool full_match) |
| 5680 | : regex_(regex), full_match_(full_match) {} |
| 5681 | |
| 5682 | // These overloaded methods allow MatchesRegex(regex) to be used as |
| 5683 | // a Matcher<T> as long as T can be converted to string. Returns |
| 5684 | // true iff s matches regular expression regex. When full_match_ is |
| 5685 | // true, a full match is done; otherwise a partial match is done. |
| 5686 | bool MatchAndExplain(const char* s, |
| 5687 | MatchResultListener* listener) const { |
| 5688 | return s != NULL && MatchAndExplain(internal::string(s), listener); |
| 5689 | } |
| 5690 | |
| 5691 | bool MatchAndExplain(const internal::string& s, |
| 5692 | MatchResultListener* /* listener */) const { |
| 5693 | return full_match_ ? RE::FullMatch(s, *regex_) : |
| 5694 | RE::PartialMatch(s, *regex_); |
| 5695 | } |
| 5696 | |
| 5697 | void DescribeTo(::std::ostream* os) const { |
| 5698 | *os << (full_match_ ? "matches" : "contains") |
| 5699 | << " regular expression "; |
| 5700 | UniversalPrinter<internal::string>::Print(regex_->pattern(), os); |
| 5701 | } |
| 5702 | |
| 5703 | void DescribeNegationTo(::std::ostream* os) const { |
| 5704 | *os << "doesn't " << (full_match_ ? "match" : "contain") |
| 5705 | << " regular expression "; |
| 5706 | UniversalPrinter<internal::string>::Print(regex_->pattern(), os); |
| 5707 | } |
| 5708 | |
| 5709 | private: |
| 5710 | const internal::linked_ptr<const RE> regex_; |
| 5711 | const bool full_match_; |
| 5712 | |
| 5713 | GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher); |
| 5714 | }; |
| 5715 | |
| 5716 | // Implements a matcher that compares the two fields of a 2-tuple |
| 5717 | // using one of the ==, <=, <, etc, operators. The two fields being |
| 5718 | // compared don't have to have the same type. |
| 5719 | // |
| 5720 | // The matcher defined here is polymorphic (for example, Eq() can be |
| 5721 | // used to match a tuple<int, short>, a tuple<const long&, double>, |
| 5722 | // etc). Therefore we use a template type conversion operator in the |
| 5723 | // implementation. |
| 5724 | // |
| 5725 | // We define this as a macro in order to eliminate duplicated source |
| 5726 | // code. |
| 5727 | #define GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(name, op, relation) \ |
| 5728 | class name##2Matcher { \ |
| 5729 | public: \ |
| 5730 | template <typename T1, typename T2> \ |
| 5731 | operator Matcher< ::std::tr1::tuple<T1, T2> >() const { \ |
| 5732 | return MakeMatcher(new Impl< ::std::tr1::tuple<T1, T2> >); \ |
| 5733 | } \ |
| 5734 | template <typename T1, typename T2> \ |
| 5735 | operator Matcher<const ::std::tr1::tuple<T1, T2>&>() const { \ |
| 5736 | return MakeMatcher(new Impl<const ::std::tr1::tuple<T1, T2>&>); \ |
| 5737 | } \ |
| 5738 | private: \ |
| 5739 | template <typename Tuple> \ |
| 5740 | class Impl : public MatcherInterface<Tuple> { \ |
| 5741 | public: \ |
| 5742 | virtual bool MatchAndExplain( \ |
| 5743 | Tuple args, \ |
| 5744 | MatchResultListener* /* listener */) const { \ |
| 5745 | return ::std::tr1::get<0>(args) op ::std::tr1::get<1>(args); \ |
| 5746 | } \ |
| 5747 | virtual void DescribeTo(::std::ostream* os) const { \ |
| 5748 | *os << "are " relation; \ |
| 5749 | } \ |
| 5750 | virtual void DescribeNegationTo(::std::ostream* os) const { \ |
| 5751 | *os << "aren't " relation; \ |
| 5752 | } \ |
| 5753 | }; \ |
| 5754 | } |
| 5755 | |
| 5756 | // Implements Eq(), Ge(), Gt(), Le(), Lt(), and Ne() respectively. |
| 5757 | GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Eq, ==, "an equal pair"); |
| 5758 | GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( |
| 5759 | Ge, >=, "a pair where the first >= the second"); |
| 5760 | GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( |
| 5761 | Gt, >, "a pair where the first > the second"); |
| 5762 | GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( |
| 5763 | Le, <=, "a pair where the first <= the second"); |
| 5764 | GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( |
| 5765 | Lt, <, "a pair where the first < the second"); |
| 5766 | GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ne, !=, "an unequal pair"); |
| 5767 | |
| 5768 | #undef GMOCK_IMPLEMENT_COMPARISON2_MATCHER_ |
| 5769 | |
| 5770 | // Implements the Not(...) matcher for a particular argument type T. |
| 5771 | // We do not nest it inside the NotMatcher class template, as that |
| 5772 | // will prevent different instantiations of NotMatcher from sharing |
| 5773 | // the same NotMatcherImpl<T> class. |
| 5774 | template <typename T> |
| 5775 | class NotMatcherImpl : public MatcherInterface<T> { |
| 5776 | public: |
| 5777 | explicit NotMatcherImpl(const Matcher<T>& matcher) |
| 5778 | : matcher_(matcher) {} |
| 5779 | |
| 5780 | virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { |
| 5781 | return !matcher_.MatchAndExplain(x, listener); |
| 5782 | } |
| 5783 | |
| 5784 | virtual void DescribeTo(::std::ostream* os) const { |
| 5785 | matcher_.DescribeNegationTo(os); |
| 5786 | } |
| 5787 | |
| 5788 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 5789 | matcher_.DescribeTo(os); |
| 5790 | } |
| 5791 | |
| 5792 | private: |
| 5793 | const Matcher<T> matcher_; |
| 5794 | |
| 5795 | GTEST_DISALLOW_ASSIGN_(NotMatcherImpl); |
| 5796 | }; |
| 5797 | |
| 5798 | // Implements the Not(m) matcher, which matches a value that doesn't |
| 5799 | // match matcher m. |
| 5800 | template <typename InnerMatcher> |
| 5801 | class NotMatcher { |
| 5802 | public: |
| 5803 | explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {} |
| 5804 | |
| 5805 | // This template type conversion operator allows Not(m) to be used |
| 5806 | // to match any type m can match. |
| 5807 | template <typename T> |
| 5808 | operator Matcher<T>() const { |
| 5809 | return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_))); |
| 5810 | } |
| 5811 | |
| 5812 | private: |
| 5813 | InnerMatcher matcher_; |
| 5814 | |
| 5815 | GTEST_DISALLOW_ASSIGN_(NotMatcher); |
| 5816 | }; |
| 5817 | |
| 5818 | // Implements the AllOf(m1, m2) matcher for a particular argument type |
| 5819 | // T. We do not nest it inside the BothOfMatcher class template, as |
| 5820 | // that will prevent different instantiations of BothOfMatcher from |
| 5821 | // sharing the same BothOfMatcherImpl<T> class. |
| 5822 | template <typename T> |
| 5823 | class BothOfMatcherImpl : public MatcherInterface<T> { |
| 5824 | public: |
| 5825 | BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2) |
| 5826 | : matcher1_(matcher1), matcher2_(matcher2) {} |
| 5827 | |
| 5828 | virtual void DescribeTo(::std::ostream* os) const { |
| 5829 | *os << "("; |
| 5830 | matcher1_.DescribeTo(os); |
| 5831 | *os << ") and ("; |
| 5832 | matcher2_.DescribeTo(os); |
| 5833 | *os << ")"; |
| 5834 | } |
| 5835 | |
| 5836 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 5837 | *os << "("; |
| 5838 | matcher1_.DescribeNegationTo(os); |
| 5839 | *os << ") or ("; |
| 5840 | matcher2_.DescribeNegationTo(os); |
| 5841 | *os << ")"; |
| 5842 | } |
| 5843 | |
| 5844 | virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { |
| 5845 | // If either matcher1_ or matcher2_ doesn't match x, we only need |
| 5846 | // to explain why one of them fails. |
| 5847 | StringMatchResultListener listener1; |
| 5848 | if (!matcher1_.MatchAndExplain(x, &listener1)) { |
| 5849 | *listener << listener1.str(); |
| 5850 | return false; |
| 5851 | } |
| 5852 | |
| 5853 | StringMatchResultListener listener2; |
| 5854 | if (!matcher2_.MatchAndExplain(x, &listener2)) { |
| 5855 | *listener << listener2.str(); |
| 5856 | return false; |
| 5857 | } |
| 5858 | |
| 5859 | // Otherwise we need to explain why *both* of them match. |
| 5860 | const internal::string s1 = listener1.str(); |
| 5861 | const internal::string s2 = listener2.str(); |
| 5862 | |
| 5863 | if (s1 == "") { |
| 5864 | *listener << s2; |
| 5865 | } else { |
| 5866 | *listener << s1; |
| 5867 | if (s2 != "") { |
| 5868 | *listener << ", and " << s2; |
| 5869 | } |
| 5870 | } |
| 5871 | return true; |
| 5872 | } |
| 5873 | |
| 5874 | private: |
| 5875 | const Matcher<T> matcher1_; |
| 5876 | const Matcher<T> matcher2_; |
| 5877 | |
| 5878 | GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl); |
| 5879 | }; |
| 5880 | |
| 5881 | // Used for implementing the AllOf(m_1, ..., m_n) matcher, which |
| 5882 | // matches a value that matches all of the matchers m_1, ..., and m_n. |
| 5883 | template <typename Matcher1, typename Matcher2> |
| 5884 | class BothOfMatcher { |
| 5885 | public: |
| 5886 | BothOfMatcher(Matcher1 matcher1, Matcher2 matcher2) |
| 5887 | : matcher1_(matcher1), matcher2_(matcher2) {} |
| 5888 | |
| 5889 | // This template type conversion operator allows a |
| 5890 | // BothOfMatcher<Matcher1, Matcher2> object to match any type that |
| 5891 | // both Matcher1 and Matcher2 can match. |
| 5892 | template <typename T> |
| 5893 | operator Matcher<T>() const { |
| 5894 | return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_), |
| 5895 | SafeMatcherCast<T>(matcher2_))); |
| 5896 | } |
| 5897 | |
| 5898 | private: |
| 5899 | Matcher1 matcher1_; |
| 5900 | Matcher2 matcher2_; |
| 5901 | |
| 5902 | GTEST_DISALLOW_ASSIGN_(BothOfMatcher); |
| 5903 | }; |
| 5904 | |
| 5905 | // Implements the AnyOf(m1, m2) matcher for a particular argument type |
| 5906 | // T. We do not nest it inside the AnyOfMatcher class template, as |
| 5907 | // that will prevent different instantiations of AnyOfMatcher from |
| 5908 | // sharing the same EitherOfMatcherImpl<T> class. |
| 5909 | template <typename T> |
| 5910 | class EitherOfMatcherImpl : public MatcherInterface<T> { |
| 5911 | public: |
| 5912 | EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2) |
| 5913 | : matcher1_(matcher1), matcher2_(matcher2) {} |
| 5914 | |
| 5915 | virtual void DescribeTo(::std::ostream* os) const { |
| 5916 | *os << "("; |
| 5917 | matcher1_.DescribeTo(os); |
| 5918 | *os << ") or ("; |
| 5919 | matcher2_.DescribeTo(os); |
| 5920 | *os << ")"; |
| 5921 | } |
| 5922 | |
| 5923 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 5924 | *os << "("; |
| 5925 | matcher1_.DescribeNegationTo(os); |
| 5926 | *os << ") and ("; |
| 5927 | matcher2_.DescribeNegationTo(os); |
| 5928 | *os << ")"; |
| 5929 | } |
| 5930 | |
| 5931 | virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { |
| 5932 | // If either matcher1_ or matcher2_ matches x, we just need to |
| 5933 | // explain why *one* of them matches. |
| 5934 | StringMatchResultListener listener1; |
| 5935 | if (matcher1_.MatchAndExplain(x, &listener1)) { |
| 5936 | *listener << listener1.str(); |
| 5937 | return true; |
| 5938 | } |
| 5939 | |
| 5940 | StringMatchResultListener listener2; |
| 5941 | if (matcher2_.MatchAndExplain(x, &listener2)) { |
| 5942 | *listener << listener2.str(); |
| 5943 | return true; |
| 5944 | } |
| 5945 | |
| 5946 | // Otherwise we need to explain why *both* of them fail. |
| 5947 | const internal::string s1 = listener1.str(); |
| 5948 | const internal::string s2 = listener2.str(); |
| 5949 | |
| 5950 | if (s1 == "") { |
| 5951 | *listener << s2; |
| 5952 | } else { |
| 5953 | *listener << s1; |
| 5954 | if (s2 != "") { |
| 5955 | *listener << ", and " << s2; |
| 5956 | } |
| 5957 | } |
| 5958 | return false; |
| 5959 | } |
| 5960 | |
| 5961 | private: |
| 5962 | const Matcher<T> matcher1_; |
| 5963 | const Matcher<T> matcher2_; |
| 5964 | |
| 5965 | GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl); |
| 5966 | }; |
| 5967 | |
| 5968 | // Used for implementing the AnyOf(m_1, ..., m_n) matcher, which |
| 5969 | // matches a value that matches at least one of the matchers m_1, ..., |
| 5970 | // and m_n. |
| 5971 | template <typename Matcher1, typename Matcher2> |
| 5972 | class EitherOfMatcher { |
| 5973 | public: |
| 5974 | EitherOfMatcher(Matcher1 matcher1, Matcher2 matcher2) |
| 5975 | : matcher1_(matcher1), matcher2_(matcher2) {} |
| 5976 | |
| 5977 | // This template type conversion operator allows a |
| 5978 | // EitherOfMatcher<Matcher1, Matcher2> object to match any type that |
| 5979 | // both Matcher1 and Matcher2 can match. |
| 5980 | template <typename T> |
| 5981 | operator Matcher<T>() const { |
| 5982 | return Matcher<T>(new EitherOfMatcherImpl<T>( |
| 5983 | SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_))); |
| 5984 | } |
| 5985 | |
| 5986 | private: |
| 5987 | Matcher1 matcher1_; |
| 5988 | Matcher2 matcher2_; |
| 5989 | |
| 5990 | GTEST_DISALLOW_ASSIGN_(EitherOfMatcher); |
| 5991 | }; |
| 5992 | |
| 5993 | // Used for implementing Truly(pred), which turns a predicate into a |
| 5994 | // matcher. |
| 5995 | template <typename Predicate> |
| 5996 | class TrulyMatcher { |
| 5997 | public: |
| 5998 | explicit TrulyMatcher(Predicate pred) : predicate_(pred) {} |
| 5999 | |
| 6000 | // This method template allows Truly(pred) to be used as a matcher |
| 6001 | // for type T where T is the argument type of predicate 'pred'. The |
| 6002 | // argument is passed by reference as the predicate may be |
| 6003 | // interested in the address of the argument. |
| 6004 | template <typename T> |
| 6005 | bool MatchAndExplain(T& x, // NOLINT |
| 6006 | MatchResultListener* /* listener */) const { |
| 6007 | // Without the if-statement, MSVC sometimes warns about converting |
| 6008 | // a value to bool (warning 4800). |
| 6009 | // |
| 6010 | // We cannot write 'return !!predicate_(x);' as that doesn't work |
| 6011 | // when predicate_(x) returns a class convertible to bool but |
| 6012 | // having no operator!(). |
| 6013 | if (predicate_(x)) |
| 6014 | return true; |
| 6015 | return false; |
| 6016 | } |
| 6017 | |
| 6018 | void DescribeTo(::std::ostream* os) const { |
| 6019 | *os << "satisfies the given predicate"; |
| 6020 | } |
| 6021 | |
| 6022 | void DescribeNegationTo(::std::ostream* os) const { |
| 6023 | *os << "doesn't satisfy the given predicate"; |
| 6024 | } |
| 6025 | |
| 6026 | private: |
| 6027 | Predicate predicate_; |
| 6028 | |
| 6029 | GTEST_DISALLOW_ASSIGN_(TrulyMatcher); |
| 6030 | }; |
| 6031 | |
| 6032 | // Used for implementing Matches(matcher), which turns a matcher into |
| 6033 | // a predicate. |
| 6034 | template <typename M> |
| 6035 | class MatcherAsPredicate { |
| 6036 | public: |
| 6037 | explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {} |
| 6038 | |
| 6039 | // This template operator() allows Matches(m) to be used as a |
| 6040 | // predicate on type T where m is a matcher on type T. |
| 6041 | // |
| 6042 | // The argument x is passed by reference instead of by value, as |
| 6043 | // some matcher may be interested in its address (e.g. as in |
| 6044 | // Matches(Ref(n))(x)). |
| 6045 | template <typename T> |
| 6046 | bool operator()(const T& x) const { |
| 6047 | // We let matcher_ commit to a particular type here instead of |
| 6048 | // when the MatcherAsPredicate object was constructed. This |
| 6049 | // allows us to write Matches(m) where m is a polymorphic matcher |
| 6050 | // (e.g. Eq(5)). |
| 6051 | // |
| 6052 | // If we write Matcher<T>(matcher_).Matches(x) here, it won't |
| 6053 | // compile when matcher_ has type Matcher<const T&>; if we write |
| 6054 | // Matcher<const T&>(matcher_).Matches(x) here, it won't compile |
| 6055 | // when matcher_ has type Matcher<T>; if we just write |
| 6056 | // matcher_.Matches(x), it won't compile when matcher_ is |
| 6057 | // polymorphic, e.g. Eq(5). |
| 6058 | // |
| 6059 | // MatcherCast<const T&>() is necessary for making the code work |
| 6060 | // in all of the above situations. |
| 6061 | return MatcherCast<const T&>(matcher_).Matches(x); |
| 6062 | } |
| 6063 | |
| 6064 | private: |
| 6065 | M matcher_; |
| 6066 | |
| 6067 | GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate); |
| 6068 | }; |
| 6069 | |
| 6070 | // For implementing ASSERT_THAT() and EXPECT_THAT(). The template |
| 6071 | // argument M must be a type that can be converted to a matcher. |
| 6072 | template <typename M> |
| 6073 | class PredicateFormatterFromMatcher { |
| 6074 | public: |
| 6075 | explicit PredicateFormatterFromMatcher(const M& m) : matcher_(m) {} |
| 6076 | |
| 6077 | // This template () operator allows a PredicateFormatterFromMatcher |
| 6078 | // object to act as a predicate-formatter suitable for using with |
| 6079 | // Google Test's EXPECT_PRED_FORMAT1() macro. |
| 6080 | template <typename T> |
| 6081 | AssertionResult operator()(const char* value_text, const T& x) const { |
| 6082 | // We convert matcher_ to a Matcher<const T&> *now* instead of |
| 6083 | // when the PredicateFormatterFromMatcher object was constructed, |
| 6084 | // as matcher_ may be polymorphic (e.g. NotNull()) and we won't |
| 6085 | // know which type to instantiate it to until we actually see the |
| 6086 | // type of x here. |
| 6087 | // |
| 6088 | // We write MatcherCast<const T&>(matcher_) instead of |
| 6089 | // Matcher<const T&>(matcher_), as the latter won't compile when |
| 6090 | // matcher_ has type Matcher<T> (e.g. An<int>()). |
| 6091 | const Matcher<const T&> matcher = MatcherCast<const T&>(matcher_); |
| 6092 | StringMatchResultListener listener; |
| 6093 | if (MatchPrintAndExplain(x, matcher, &listener)) |
| 6094 | return AssertionSuccess(); |
| 6095 | |
| 6096 | ::std::stringstream ss; |
| 6097 | ss << "Value of: " << value_text << "\n" |
| 6098 | << "Expected: "; |
| 6099 | matcher.DescribeTo(&ss); |
| 6100 | ss << "\n Actual: " << listener.str(); |
| 6101 | return AssertionFailure() << ss.str(); |
| 6102 | } |
| 6103 | |
| 6104 | private: |
| 6105 | const M matcher_; |
| 6106 | |
| 6107 | GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher); |
| 6108 | }; |
| 6109 | |
| 6110 | // A helper function for converting a matcher to a predicate-formatter |
| 6111 | // without the user needing to explicitly write the type. This is |
| 6112 | // used for implementing ASSERT_THAT() and EXPECT_THAT(). |
| 6113 | template <typename M> |
| 6114 | inline PredicateFormatterFromMatcher<M> |
| 6115 | MakePredicateFormatterFromMatcher(const M& matcher) { |
| 6116 | return PredicateFormatterFromMatcher<M>(matcher); |
| 6117 | } |
| 6118 | |
| 6119 | // Implements the polymorphic floating point equality matcher, which |
| 6120 | // matches two float values using ULP-based approximation. The |
| 6121 | // template is meant to be instantiated with FloatType being either |
| 6122 | // float or double. |
| 6123 | template <typename FloatType> |
| 6124 | class FloatingEqMatcher { |
| 6125 | public: |
| 6126 | // Constructor for FloatingEqMatcher. |
| 6127 | // The matcher's input will be compared with rhs. The matcher treats two |
| 6128 | // NANs as equal if nan_eq_nan is true. Otherwise, under IEEE standards, |
| 6129 | // equality comparisons between NANs will always return false. |
| 6130 | FloatingEqMatcher(FloatType rhs, bool nan_eq_nan) : |
| 6131 | rhs_(rhs), nan_eq_nan_(nan_eq_nan) {} |
| 6132 | |
| 6133 | // Implements floating point equality matcher as a Matcher<T>. |
| 6134 | template <typename T> |
| 6135 | class Impl : public MatcherInterface<T> { |
| 6136 | public: |
| 6137 | Impl(FloatType rhs, bool nan_eq_nan) : |
| 6138 | rhs_(rhs), nan_eq_nan_(nan_eq_nan) {} |
| 6139 | |
| 6140 | virtual bool MatchAndExplain(T value, |
| 6141 | MatchResultListener* /* listener */) const { |
| 6142 | const FloatingPoint<FloatType> lhs(value), rhs(rhs_); |
| 6143 | |
| 6144 | // Compares NaNs first, if nan_eq_nan_ is true. |
| 6145 | if (nan_eq_nan_ && lhs.is_nan()) { |
| 6146 | return rhs.is_nan(); |
| 6147 | } |
| 6148 | |
| 6149 | return lhs.AlmostEquals(rhs); |
| 6150 | } |
| 6151 | |
| 6152 | virtual void DescribeTo(::std::ostream* os) const { |
| 6153 | // os->precision() returns the previously set precision, which we |
| 6154 | // store to restore the ostream to its original configuration |
| 6155 | // after outputting. |
| 6156 | const ::std::streamsize old_precision = os->precision( |
| 6157 | ::std::numeric_limits<FloatType>::digits10 + 2); |
| 6158 | if (FloatingPoint<FloatType>(rhs_).is_nan()) { |
| 6159 | if (nan_eq_nan_) { |
| 6160 | *os << "is NaN"; |
| 6161 | } else { |
| 6162 | *os << "never matches"; |
| 6163 | } |
| 6164 | } else { |
| 6165 | *os << "is approximately " << rhs_; |
| 6166 | } |
| 6167 | os->precision(old_precision); |
| 6168 | } |
| 6169 | |
| 6170 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 6171 | // As before, get original precision. |
| 6172 | const ::std::streamsize old_precision = os->precision( |
| 6173 | ::std::numeric_limits<FloatType>::digits10 + 2); |
| 6174 | if (FloatingPoint<FloatType>(rhs_).is_nan()) { |
| 6175 | if (nan_eq_nan_) { |
| 6176 | *os << "isn't NaN"; |
| 6177 | } else { |
| 6178 | *os << "is anything"; |
| 6179 | } |
| 6180 | } else { |
| 6181 | *os << "isn't approximately " << rhs_; |
| 6182 | } |
| 6183 | // Restore original precision. |
| 6184 | os->precision(old_precision); |
| 6185 | } |
| 6186 | |
| 6187 | private: |
| 6188 | const FloatType rhs_; |
| 6189 | const bool nan_eq_nan_; |
| 6190 | |
| 6191 | GTEST_DISALLOW_ASSIGN_(Impl); |
| 6192 | }; |
| 6193 | |
| 6194 | // The following 3 type conversion operators allow FloatEq(rhs) and |
| 6195 | // NanSensitiveFloatEq(rhs) to be used as a Matcher<float>, a |
| 6196 | // Matcher<const float&>, or a Matcher<float&>, but nothing else. |
| 6197 | // (While Google's C++ coding style doesn't allow arguments passed |
| 6198 | // by non-const reference, we may see them in code not conforming to |
| 6199 | // the style. Therefore Google Mock needs to support them.) |
| 6200 | operator Matcher<FloatType>() const { |
| 6201 | return MakeMatcher(new Impl<FloatType>(rhs_, nan_eq_nan_)); |
| 6202 | } |
| 6203 | |
| 6204 | operator Matcher<const FloatType&>() const { |
| 6205 | return MakeMatcher(new Impl<const FloatType&>(rhs_, nan_eq_nan_)); |
| 6206 | } |
| 6207 | |
| 6208 | operator Matcher<FloatType&>() const { |
| 6209 | return MakeMatcher(new Impl<FloatType&>(rhs_, nan_eq_nan_)); |
| 6210 | } |
| 6211 | private: |
| 6212 | const FloatType rhs_; |
| 6213 | const bool nan_eq_nan_; |
| 6214 | |
| 6215 | GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher); |
| 6216 | }; |
| 6217 | |
| 6218 | // Implements the Pointee(m) matcher for matching a pointer whose |
| 6219 | // pointee matches matcher m. The pointer can be either raw or smart. |
| 6220 | template <typename InnerMatcher> |
| 6221 | class PointeeMatcher { |
| 6222 | public: |
| 6223 | explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {} |
| 6224 | |
| 6225 | // This type conversion operator template allows Pointee(m) to be |
| 6226 | // used as a matcher for any pointer type whose pointee type is |
| 6227 | // compatible with the inner matcher, where type Pointer can be |
| 6228 | // either a raw pointer or a smart pointer. |
| 6229 | // |
| 6230 | // The reason we do this instead of relying on |
| 6231 | // MakePolymorphicMatcher() is that the latter is not flexible |
| 6232 | // enough for implementing the DescribeTo() method of Pointee(). |
| 6233 | template <typename Pointer> |
| 6234 | operator Matcher<Pointer>() const { |
| 6235 | return MakeMatcher(new Impl<Pointer>(matcher_)); |
| 6236 | } |
| 6237 | |
| 6238 | private: |
| 6239 | // The monomorphic implementation that works for a particular pointer type. |
| 6240 | template <typename Pointer> |
| 6241 | class Impl : public MatcherInterface<Pointer> { |
| 6242 | public: |
| 6243 | typedef typename PointeeOf<GTEST_REMOVE_CONST_( // NOLINT |
| 6244 | GTEST_REMOVE_REFERENCE_(Pointer))>::type Pointee; |
| 6245 | |
| 6246 | explicit Impl(const InnerMatcher& matcher) |
| 6247 | : matcher_(MatcherCast<const Pointee&>(matcher)) {} |
| 6248 | |
| 6249 | virtual void DescribeTo(::std::ostream* os) const { |
| 6250 | *os << "points to a value that "; |
| 6251 | matcher_.DescribeTo(os); |
| 6252 | } |
| 6253 | |
| 6254 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 6255 | *os << "does not point to a value that "; |
| 6256 | matcher_.DescribeTo(os); |
| 6257 | } |
| 6258 | |
| 6259 | virtual bool MatchAndExplain(Pointer pointer, |
| 6260 | MatchResultListener* listener) const { |
| 6261 | if (GetRawPointer(pointer) == NULL) |
| 6262 | return false; |
| 6263 | |
| 6264 | *listener << "which points to "; |
| 6265 | return MatchPrintAndExplain(*pointer, matcher_, listener); |
| 6266 | } |
| 6267 | |
| 6268 | private: |
| 6269 | const Matcher<const Pointee&> matcher_; |
| 6270 | |
| 6271 | GTEST_DISALLOW_ASSIGN_(Impl); |
| 6272 | }; |
| 6273 | |
| 6274 | const InnerMatcher matcher_; |
| 6275 | |
| 6276 | GTEST_DISALLOW_ASSIGN_(PointeeMatcher); |
| 6277 | }; |
| 6278 | |
| 6279 | // Implements the Field() matcher for matching a field (i.e. member |
| 6280 | // variable) of an object. |
| 6281 | template <typename Class, typename FieldType> |
| 6282 | class FieldMatcher { |
| 6283 | public: |
| 6284 | FieldMatcher(FieldType Class::*field, |
| 6285 | const Matcher<const FieldType&>& matcher) |
| 6286 | : field_(field), matcher_(matcher) {} |
| 6287 | |
| 6288 | void DescribeTo(::std::ostream* os) const { |
| 6289 | *os << "is an object whose given field "; |
| 6290 | matcher_.DescribeTo(os); |
| 6291 | } |
| 6292 | |
| 6293 | void DescribeNegationTo(::std::ostream* os) const { |
| 6294 | *os << "is an object whose given field "; |
| 6295 | matcher_.DescribeNegationTo(os); |
| 6296 | } |
| 6297 | |
| 6298 | template <typename T> |
| 6299 | bool MatchAndExplain(const T& value, MatchResultListener* listener) const { |
| 6300 | return MatchAndExplainImpl( |
| 6301 | typename ::testing::internal:: |
| 6302 | is_pointer<GTEST_REMOVE_CONST_(T)>::type(), |
| 6303 | value, listener); |
| 6304 | } |
| 6305 | |
| 6306 | private: |
| 6307 | // The first argument of MatchAndExplainImpl() is needed to help |
| 6308 | // Symbian's C++ compiler choose which overload to use. Its type is |
| 6309 | // true_type iff the Field() matcher is used to match a pointer. |
| 6310 | bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, |
| 6311 | MatchResultListener* listener) const { |
| 6312 | *listener << "whose given field is "; |
| 6313 | return MatchPrintAndExplain(obj.*field_, matcher_, listener); |
| 6314 | } |
| 6315 | |
| 6316 | bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, |
| 6317 | MatchResultListener* listener) const { |
| 6318 | if (p == NULL) |
| 6319 | return false; |
| 6320 | |
| 6321 | *listener << "which points to an object "; |
| 6322 | // Since *p has a field, it must be a class/struct/union type and |
| 6323 | // thus cannot be a pointer. Therefore we pass false_type() as |
| 6324 | // the first argument. |
| 6325 | return MatchAndExplainImpl(false_type(), *p, listener); |
| 6326 | } |
| 6327 | |
| 6328 | const FieldType Class::*field_; |
| 6329 | const Matcher<const FieldType&> matcher_; |
| 6330 | |
| 6331 | GTEST_DISALLOW_ASSIGN_(FieldMatcher); |
| 6332 | }; |
| 6333 | |
| 6334 | // Implements the Property() matcher for matching a property |
| 6335 | // (i.e. return value of a getter method) of an object. |
| 6336 | template <typename Class, typename PropertyType> |
| 6337 | class PropertyMatcher { |
| 6338 | public: |
| 6339 | // The property may have a reference type, so 'const PropertyType&' |
| 6340 | // may cause double references and fail to compile. That's why we |
| 6341 | // need GTEST_REFERENCE_TO_CONST, which works regardless of |
| 6342 | // PropertyType being a reference or not. |
| 6343 | typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty; |
| 6344 | |
| 6345 | PropertyMatcher(PropertyType (Class::*property)() const, |
| 6346 | const Matcher<RefToConstProperty>& matcher) |
| 6347 | : property_(property), matcher_(matcher) {} |
| 6348 | |
| 6349 | void DescribeTo(::std::ostream* os) const { |
| 6350 | *os << "is an object whose given property "; |
| 6351 | matcher_.DescribeTo(os); |
| 6352 | } |
| 6353 | |
| 6354 | void DescribeNegationTo(::std::ostream* os) const { |
| 6355 | *os << "is an object whose given property "; |
| 6356 | matcher_.DescribeNegationTo(os); |
| 6357 | } |
| 6358 | |
| 6359 | template <typename T> |
| 6360 | bool MatchAndExplain(const T&value, MatchResultListener* listener) const { |
| 6361 | return MatchAndExplainImpl( |
| 6362 | typename ::testing::internal:: |
| 6363 | is_pointer<GTEST_REMOVE_CONST_(T)>::type(), |
| 6364 | value, listener); |
| 6365 | } |
| 6366 | |
| 6367 | private: |
| 6368 | // The first argument of MatchAndExplainImpl() is needed to help |
| 6369 | // Symbian's C++ compiler choose which overload to use. Its type is |
| 6370 | // true_type iff the Property() matcher is used to match a pointer. |
| 6371 | bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, |
| 6372 | MatchResultListener* listener) const { |
| 6373 | *listener << "whose given property is "; |
| 6374 | // Cannot pass the return value (for example, int) to MatchPrintAndExplain, |
| 6375 | // which takes a non-const reference as argument. |
| 6376 | RefToConstProperty result = (obj.*property_)(); |
| 6377 | return MatchPrintAndExplain(result, matcher_, listener); |
| 6378 | } |
| 6379 | |
| 6380 | bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, |
| 6381 | MatchResultListener* listener) const { |
| 6382 | if (p == NULL) |
| 6383 | return false; |
| 6384 | |
| 6385 | *listener << "which points to an object "; |
| 6386 | // Since *p has a property method, it must be a class/struct/union |
| 6387 | // type and thus cannot be a pointer. Therefore we pass |
| 6388 | // false_type() as the first argument. |
| 6389 | return MatchAndExplainImpl(false_type(), *p, listener); |
| 6390 | } |
| 6391 | |
| 6392 | PropertyType (Class::*property_)() const; |
| 6393 | const Matcher<RefToConstProperty> matcher_; |
| 6394 | |
| 6395 | GTEST_DISALLOW_ASSIGN_(PropertyMatcher); |
| 6396 | }; |
| 6397 | |
| 6398 | // Type traits specifying various features of different functors for ResultOf. |
| 6399 | // The default template specifies features for functor objects. |
| 6400 | // Functor classes have to typedef argument_type and result_type |
| 6401 | // to be compatible with ResultOf. |
| 6402 | template <typename Functor> |
| 6403 | struct CallableTraits { |
| 6404 | typedef typename Functor::result_type ResultType; |
| 6405 | typedef Functor StorageType; |
| 6406 | |
| 6407 | static void CheckIsValid(Functor /* functor */) {} |
| 6408 | template <typename T> |
| 6409 | static ResultType Invoke(Functor f, T arg) { return f(arg); } |
| 6410 | }; |
| 6411 | |
| 6412 | // Specialization for function pointers. |
| 6413 | template <typename ArgType, typename ResType> |
| 6414 | struct CallableTraits<ResType(*)(ArgType)> { |
| 6415 | typedef ResType ResultType; |
| 6416 | typedef ResType(*StorageType)(ArgType); |
| 6417 | |
| 6418 | static void CheckIsValid(ResType(*f)(ArgType)) { |
| 6419 | GTEST_CHECK_(f != NULL) |
| 6420 | << "NULL function pointer is passed into ResultOf()."; |
| 6421 | } |
| 6422 | template <typename T> |
| 6423 | static ResType Invoke(ResType(*f)(ArgType), T arg) { |
| 6424 | return (*f)(arg); |
| 6425 | } |
| 6426 | }; |
| 6427 | |
| 6428 | // Implements the ResultOf() matcher for matching a return value of a |
| 6429 | // unary function of an object. |
| 6430 | template <typename Callable> |
| 6431 | class ResultOfMatcher { |
| 6432 | public: |
| 6433 | typedef typename CallableTraits<Callable>::ResultType ResultType; |
| 6434 | |
| 6435 | ResultOfMatcher(Callable callable, const Matcher<ResultType>& matcher) |
| 6436 | : callable_(callable), matcher_(matcher) { |
| 6437 | CallableTraits<Callable>::CheckIsValid(callable_); |
| 6438 | } |
| 6439 | |
| 6440 | template <typename T> |
| 6441 | operator Matcher<T>() const { |
| 6442 | return Matcher<T>(new Impl<T>(callable_, matcher_)); |
| 6443 | } |
| 6444 | |
| 6445 | private: |
| 6446 | typedef typename CallableTraits<Callable>::StorageType CallableStorageType; |
| 6447 | |
| 6448 | template <typename T> |
| 6449 | class Impl : public MatcherInterface<T> { |
| 6450 | public: |
| 6451 | Impl(CallableStorageType callable, const Matcher<ResultType>& matcher) |
| 6452 | : callable_(callable), matcher_(matcher) {} |
| 6453 | |
| 6454 | virtual void DescribeTo(::std::ostream* os) const { |
| 6455 | *os << "is mapped by the given callable to a value that "; |
| 6456 | matcher_.DescribeTo(os); |
| 6457 | } |
| 6458 | |
| 6459 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 6460 | *os << "is mapped by the given callable to a value that "; |
| 6461 | matcher_.DescribeNegationTo(os); |
| 6462 | } |
| 6463 | |
| 6464 | virtual bool MatchAndExplain(T obj, MatchResultListener* listener) const { |
| 6465 | *listener << "which is mapped by the given callable to "; |
| 6466 | // Cannot pass the return value (for example, int) to |
| 6467 | // MatchPrintAndExplain, which takes a non-const reference as argument. |
| 6468 | ResultType result = |
| 6469 | CallableTraits<Callable>::template Invoke<T>(callable_, obj); |
| 6470 | return MatchPrintAndExplain(result, matcher_, listener); |
| 6471 | } |
| 6472 | |
| 6473 | private: |
| 6474 | // Functors often define operator() as non-const method even though |
| 6475 | // they are actualy stateless. But we need to use them even when |
| 6476 | // 'this' is a const pointer. It's the user's responsibility not to |
| 6477 | // use stateful callables with ResultOf(), which does't guarantee |
| 6478 | // how many times the callable will be invoked. |
| 6479 | mutable CallableStorageType callable_; |
| 6480 | const Matcher<ResultType> matcher_; |
| 6481 | |
| 6482 | GTEST_DISALLOW_ASSIGN_(Impl); |
| 6483 | }; // class Impl |
| 6484 | |
| 6485 | const CallableStorageType callable_; |
| 6486 | const Matcher<ResultType> matcher_; |
| 6487 | |
| 6488 | GTEST_DISALLOW_ASSIGN_(ResultOfMatcher); |
| 6489 | }; |
| 6490 | |
| 6491 | // Implements an equality matcher for any STL-style container whose elements |
| 6492 | // support ==. This matcher is like Eq(), but its failure explanations provide |
| 6493 | // more detailed information that is useful when the container is used as a set. |
| 6494 | // The failure message reports elements that are in one of the operands but not |
| 6495 | // the other. The failure messages do not report duplicate or out-of-order |
| 6496 | // elements in the containers (which don't properly matter to sets, but can |
| 6497 | // occur if the containers are vectors or lists, for example). |
| 6498 | // |
| 6499 | // Uses the container's const_iterator, value_type, operator ==, |
| 6500 | // begin(), and end(). |
| 6501 | template <typename Container> |
| 6502 | class ContainerEqMatcher { |
| 6503 | public: |
| 6504 | typedef internal::StlContainerView<Container> View; |
| 6505 | typedef typename View::type StlContainer; |
| 6506 | typedef typename View::const_reference StlContainerReference; |
| 6507 | |
| 6508 | // We make a copy of rhs in case the elements in it are modified |
| 6509 | // after this matcher is created. |
| 6510 | explicit ContainerEqMatcher(const Container& rhs) : rhs_(View::Copy(rhs)) { |
| 6511 | // Makes sure the user doesn't instantiate this class template |
| 6512 | // with a const or reference type. |
| 6513 | (void)testing::StaticAssertTypeEq<Container, |
| 6514 | GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>(); |
| 6515 | } |
| 6516 | |
| 6517 | void DescribeTo(::std::ostream* os) const { |
| 6518 | *os << "equals "; |
| 6519 | UniversalPrint(rhs_, os); |
| 6520 | } |
| 6521 | void DescribeNegationTo(::std::ostream* os) const { |
| 6522 | *os << "does not equal "; |
| 6523 | UniversalPrint(rhs_, os); |
| 6524 | } |
| 6525 | |
| 6526 | template <typename LhsContainer> |
| 6527 | bool MatchAndExplain(const LhsContainer& lhs, |
| 6528 | MatchResultListener* listener) const { |
| 6529 | // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug |
| 6530 | // that causes LhsContainer to be a const type sometimes. |
| 6531 | typedef internal::StlContainerView<GTEST_REMOVE_CONST_(LhsContainer)> |
| 6532 | LhsView; |
| 6533 | typedef typename LhsView::type LhsStlContainer; |
| 6534 | StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); |
| 6535 | if (lhs_stl_container == rhs_) |
| 6536 | return true; |
| 6537 | |
| 6538 | ::std::ostream* const os = listener->stream(); |
| 6539 | if (os != NULL) { |
| 6540 | // Something is different. Check for extra values first. |
| 6541 | bool printed_header = false; |
| 6542 | for (typename LhsStlContainer::const_iterator it = |
| 6543 | lhs_stl_container.begin(); |
| 6544 | it != lhs_stl_container.end(); ++it) { |
| 6545 | if (internal::ArrayAwareFind(rhs_.begin(), rhs_.end(), *it) == |
| 6546 | rhs_.end()) { |
| 6547 | if (printed_header) { |
| 6548 | *os << ", "; |
| 6549 | } else { |
| 6550 | *os << "which has these unexpected elements: "; |
| 6551 | printed_header = true; |
| 6552 | } |
| 6553 | UniversalPrint(*it, os); |
| 6554 | } |
| 6555 | } |
| 6556 | |
| 6557 | // Now check for missing values. |
| 6558 | bool printed_header2 = false; |
| 6559 | for (typename StlContainer::const_iterator it = rhs_.begin(); |
| 6560 | it != rhs_.end(); ++it) { |
| 6561 | if (internal::ArrayAwareFind( |
| 6562 | lhs_stl_container.begin(), lhs_stl_container.end(), *it) == |
| 6563 | lhs_stl_container.end()) { |
| 6564 | if (printed_header2) { |
| 6565 | *os << ", "; |
| 6566 | } else { |
| 6567 | *os << (printed_header ? ",\nand" : "which") |
| 6568 | << " doesn't have these expected elements: "; |
| 6569 | printed_header2 = true; |
| 6570 | } |
| 6571 | UniversalPrint(*it, os); |
| 6572 | } |
| 6573 | } |
| 6574 | } |
| 6575 | |
| 6576 | return false; |
| 6577 | } |
| 6578 | |
| 6579 | private: |
| 6580 | const StlContainer rhs_; |
| 6581 | |
| 6582 | GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher); |
| 6583 | }; |
| 6584 | |
| 6585 | // Implements Pointwise(tuple_matcher, rhs_container). tuple_matcher |
| 6586 | // must be able to be safely cast to Matcher<tuple<const T1&, const |
| 6587 | // T2&> >, where T1 and T2 are the types of elements in the LHS |
| 6588 | // container and the RHS container respectively. |
| 6589 | template <typename TupleMatcher, typename RhsContainer> |
| 6590 | class PointwiseMatcher { |
| 6591 | public: |
| 6592 | typedef internal::StlContainerView<RhsContainer> RhsView; |
| 6593 | typedef typename RhsView::type RhsStlContainer; |
| 6594 | typedef typename RhsStlContainer::value_type RhsValue; |
| 6595 | |
| 6596 | // Like ContainerEq, we make a copy of rhs in case the elements in |
| 6597 | // it are modified after this matcher is created. |
| 6598 | PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs) |
| 6599 | : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) { |
| 6600 | // Makes sure the user doesn't instantiate this class template |
| 6601 | // with a const or reference type. |
| 6602 | (void)testing::StaticAssertTypeEq<RhsContainer, |
| 6603 | GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>(); |
| 6604 | } |
| 6605 | |
| 6606 | template <typename LhsContainer> |
| 6607 | operator Matcher<LhsContainer>() const { |
| 6608 | return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_)); |
| 6609 | } |
| 6610 | |
| 6611 | template <typename LhsContainer> |
| 6612 | class Impl : public MatcherInterface<LhsContainer> { |
| 6613 | public: |
| 6614 | typedef internal::StlContainerView< |
| 6615 | GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView; |
| 6616 | typedef typename LhsView::type LhsStlContainer; |
| 6617 | typedef typename LhsView::const_reference LhsStlContainerReference; |
| 6618 | typedef typename LhsStlContainer::value_type LhsValue; |
| 6619 | // We pass the LHS value and the RHS value to the inner matcher by |
| 6620 | // reference, as they may be expensive to copy. We must use tuple |
| 6621 | // instead of pair here, as a pair cannot hold references (C++ 98, |
| 6622 | // 20.2.2 [lib.pairs]). |
| 6623 | typedef std::tr1::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg; |
| 6624 | |
| 6625 | Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs) |
| 6626 | // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher. |
| 6627 | : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)), |
| 6628 | rhs_(rhs) {} |
| 6629 | |
| 6630 | virtual void DescribeTo(::std::ostream* os) const { |
| 6631 | *os << "contains " << rhs_.size() |
| 6632 | << " values, where each value and its corresponding value in "; |
| 6633 | UniversalPrinter<RhsStlContainer>::Print(rhs_, os); |
| 6634 | *os << " "; |
| 6635 | mono_tuple_matcher_.DescribeTo(os); |
| 6636 | } |
| 6637 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 6638 | *os << "doesn't contain exactly " << rhs_.size() |
| 6639 | << " values, or contains a value x at some index i" |
| 6640 | << " where x and the i-th value of "; |
| 6641 | UniversalPrint(rhs_, os); |
| 6642 | *os << " "; |
| 6643 | mono_tuple_matcher_.DescribeNegationTo(os); |
| 6644 | } |
| 6645 | |
| 6646 | virtual bool MatchAndExplain(LhsContainer lhs, |
| 6647 | MatchResultListener* listener) const { |
| 6648 | LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); |
| 6649 | const size_t actual_size = lhs_stl_container.size(); |
| 6650 | if (actual_size != rhs_.size()) { |
| 6651 | *listener << "which contains " << actual_size << " values"; |
| 6652 | return false; |
| 6653 | } |
| 6654 | |
| 6655 | typename LhsStlContainer::const_iterator left = lhs_stl_container.begin(); |
| 6656 | typename RhsStlContainer::const_iterator right = rhs_.begin(); |
| 6657 | for (size_t i = 0; i != actual_size; ++i, ++left, ++right) { |
| 6658 | const InnerMatcherArg value_pair(*left, *right); |
| 6659 | |
| 6660 | if (listener->IsInterested()) { |
| 6661 | StringMatchResultListener inner_listener; |
| 6662 | if (!mono_tuple_matcher_.MatchAndExplain( |
| 6663 | value_pair, &inner_listener)) { |
| 6664 | *listener << "where the value pair ("; |
| 6665 | UniversalPrint(*left, listener->stream()); |
| 6666 | *listener << ", "; |
| 6667 | UniversalPrint(*right, listener->stream()); |
| 6668 | *listener << ") at index #" << i << " don't match"; |
| 6669 | PrintIfNotEmpty(inner_listener.str(), listener->stream()); |
| 6670 | return false; |
| 6671 | } |
| 6672 | } else { |
| 6673 | if (!mono_tuple_matcher_.Matches(value_pair)) |
| 6674 | return false; |
| 6675 | } |
| 6676 | } |
| 6677 | |
| 6678 | return true; |
| 6679 | } |
| 6680 | |
| 6681 | private: |
| 6682 | const Matcher<InnerMatcherArg> mono_tuple_matcher_; |
| 6683 | const RhsStlContainer rhs_; |
| 6684 | |
| 6685 | GTEST_DISALLOW_ASSIGN_(Impl); |
| 6686 | }; |
| 6687 | |
| 6688 | private: |
| 6689 | const TupleMatcher tuple_matcher_; |
| 6690 | const RhsStlContainer rhs_; |
| 6691 | |
| 6692 | GTEST_DISALLOW_ASSIGN_(PointwiseMatcher); |
| 6693 | }; |
| 6694 | |
| 6695 | // Holds the logic common to ContainsMatcherImpl and EachMatcherImpl. |
| 6696 | template <typename Container> |
| 6697 | class QuantifierMatcherImpl : public MatcherInterface<Container> { |
| 6698 | public: |
| 6699 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 6700 | typedef StlContainerView<RawContainer> View; |
| 6701 | typedef typename View::type StlContainer; |
| 6702 | typedef typename View::const_reference StlContainerReference; |
| 6703 | typedef typename StlContainer::value_type Element; |
| 6704 | |
| 6705 | template <typename InnerMatcher> |
| 6706 | explicit QuantifierMatcherImpl(InnerMatcher inner_matcher) |
| 6707 | : inner_matcher_( |
| 6708 | testing::SafeMatcherCast<const Element&>(inner_matcher)) {} |
| 6709 | |
| 6710 | // Checks whether: |
| 6711 | // * All elements in the container match, if all_elements_should_match. |
| 6712 | // * Any element in the container matches, if !all_elements_should_match. |
| 6713 | bool MatchAndExplainImpl(bool all_elements_should_match, |
| 6714 | Container container, |
| 6715 | MatchResultListener* listener) const { |
| 6716 | StlContainerReference stl_container = View::ConstReference(container); |
| 6717 | size_t i = 0; |
| 6718 | for (typename StlContainer::const_iterator it = stl_container.begin(); |
| 6719 | it != stl_container.end(); ++it, ++i) { |
| 6720 | StringMatchResultListener inner_listener; |
| 6721 | const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener); |
| 6722 | |
| 6723 | if (matches != all_elements_should_match) { |
| 6724 | *listener << "whose element #" << i |
| 6725 | << (matches ? " matches" : " doesn't match"); |
| 6726 | PrintIfNotEmpty(inner_listener.str(), listener->stream()); |
| 6727 | return !all_elements_should_match; |
| 6728 | } |
| 6729 | } |
| 6730 | return all_elements_should_match; |
| 6731 | } |
| 6732 | |
| 6733 | protected: |
| 6734 | const Matcher<const Element&> inner_matcher_; |
| 6735 | |
| 6736 | GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl); |
| 6737 | }; |
| 6738 | |
| 6739 | // Implements Contains(element_matcher) for the given argument type Container. |
| 6740 | // Symmetric to EachMatcherImpl. |
| 6741 | template <typename Container> |
| 6742 | class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> { |
| 6743 | public: |
| 6744 | template <typename InnerMatcher> |
| 6745 | explicit ContainsMatcherImpl(InnerMatcher inner_matcher) |
| 6746 | : QuantifierMatcherImpl<Container>(inner_matcher) {} |
| 6747 | |
| 6748 | // Describes what this matcher does. |
| 6749 | virtual void DescribeTo(::std::ostream* os) const { |
| 6750 | *os << "contains at least one element that "; |
| 6751 | this->inner_matcher_.DescribeTo(os); |
| 6752 | } |
| 6753 | |
| 6754 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 6755 | *os << "doesn't contain any element that "; |
| 6756 | this->inner_matcher_.DescribeTo(os); |
| 6757 | } |
| 6758 | |
| 6759 | virtual bool MatchAndExplain(Container container, |
| 6760 | MatchResultListener* listener) const { |
| 6761 | return this->MatchAndExplainImpl(false, container, listener); |
| 6762 | } |
| 6763 | |
| 6764 | private: |
| 6765 | GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl); |
| 6766 | }; |
| 6767 | |
| 6768 | // Implements Each(element_matcher) for the given argument type Container. |
| 6769 | // Symmetric to ContainsMatcherImpl. |
| 6770 | template <typename Container> |
| 6771 | class EachMatcherImpl : public QuantifierMatcherImpl<Container> { |
| 6772 | public: |
| 6773 | template <typename InnerMatcher> |
| 6774 | explicit EachMatcherImpl(InnerMatcher inner_matcher) |
| 6775 | : QuantifierMatcherImpl<Container>(inner_matcher) {} |
| 6776 | |
| 6777 | // Describes what this matcher does. |
| 6778 | virtual void DescribeTo(::std::ostream* os) const { |
| 6779 | *os << "only contains elements that "; |
| 6780 | this->inner_matcher_.DescribeTo(os); |
| 6781 | } |
| 6782 | |
| 6783 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 6784 | *os << "contains some element that "; |
| 6785 | this->inner_matcher_.DescribeNegationTo(os); |
| 6786 | } |
| 6787 | |
| 6788 | virtual bool MatchAndExplain(Container container, |
| 6789 | MatchResultListener* listener) const { |
| 6790 | return this->MatchAndExplainImpl(true, container, listener); |
| 6791 | } |
| 6792 | |
| 6793 | private: |
| 6794 | GTEST_DISALLOW_ASSIGN_(EachMatcherImpl); |
| 6795 | }; |
| 6796 | |
| 6797 | // Implements polymorphic Contains(element_matcher). |
| 6798 | template <typename M> |
| 6799 | class ContainsMatcher { |
| 6800 | public: |
| 6801 | explicit ContainsMatcher(M m) : inner_matcher_(m) {} |
| 6802 | |
| 6803 | template <typename Container> |
| 6804 | operator Matcher<Container>() const { |
| 6805 | return MakeMatcher(new ContainsMatcherImpl<Container>(inner_matcher_)); |
| 6806 | } |
| 6807 | |
| 6808 | private: |
| 6809 | const M inner_matcher_; |
| 6810 | |
| 6811 | GTEST_DISALLOW_ASSIGN_(ContainsMatcher); |
| 6812 | }; |
| 6813 | |
| 6814 | // Implements polymorphic Each(element_matcher). |
| 6815 | template <typename M> |
| 6816 | class EachMatcher { |
| 6817 | public: |
| 6818 | explicit EachMatcher(M m) : inner_matcher_(m) {} |
| 6819 | |
| 6820 | template <typename Container> |
| 6821 | operator Matcher<Container>() const { |
| 6822 | return MakeMatcher(new EachMatcherImpl<Container>(inner_matcher_)); |
| 6823 | } |
| 6824 | |
| 6825 | private: |
| 6826 | const M inner_matcher_; |
| 6827 | |
| 6828 | GTEST_DISALLOW_ASSIGN_(EachMatcher); |
| 6829 | }; |
| 6830 | |
| 6831 | // Implements Key(inner_matcher) for the given argument pair type. |
| 6832 | // Key(inner_matcher) matches an std::pair whose 'first' field matches |
| 6833 | // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an |
| 6834 | // std::map that contains at least one element whose key is >= 5. |
| 6835 | template <typename PairType> |
| 6836 | class KeyMatcherImpl : public MatcherInterface<PairType> { |
| 6837 | public: |
| 6838 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType; |
| 6839 | typedef typename RawPairType::first_type KeyType; |
| 6840 | |
| 6841 | template <typename InnerMatcher> |
| 6842 | explicit KeyMatcherImpl(InnerMatcher inner_matcher) |
| 6843 | : inner_matcher_( |
| 6844 | testing::SafeMatcherCast<const KeyType&>(inner_matcher)) { |
| 6845 | } |
| 6846 | |
| 6847 | // Returns true iff 'key_value.first' (the key) matches the inner matcher. |
| 6848 | virtual bool MatchAndExplain(PairType key_value, |
| 6849 | MatchResultListener* listener) const { |
| 6850 | StringMatchResultListener inner_listener; |
| 6851 | const bool match = inner_matcher_.MatchAndExplain(key_value.first, |
| 6852 | &inner_listener); |
| 6853 | const internal::string explanation = inner_listener.str(); |
| 6854 | if (explanation != "") { |
| 6855 | *listener << "whose first field is a value " << explanation; |
| 6856 | } |
| 6857 | return match; |
| 6858 | } |
| 6859 | |
| 6860 | // Describes what this matcher does. |
| 6861 | virtual void DescribeTo(::std::ostream* os) const { |
| 6862 | *os << "has a key that "; |
| 6863 | inner_matcher_.DescribeTo(os); |
| 6864 | } |
| 6865 | |
| 6866 | // Describes what the negation of this matcher does. |
| 6867 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 6868 | *os << "doesn't have a key that "; |
| 6869 | inner_matcher_.DescribeTo(os); |
| 6870 | } |
| 6871 | |
| 6872 | private: |
| 6873 | const Matcher<const KeyType&> inner_matcher_; |
| 6874 | |
| 6875 | GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl); |
| 6876 | }; |
| 6877 | |
| 6878 | // Implements polymorphic Key(matcher_for_key). |
| 6879 | template <typename M> |
| 6880 | class KeyMatcher { |
| 6881 | public: |
| 6882 | explicit KeyMatcher(M m) : matcher_for_key_(m) {} |
| 6883 | |
| 6884 | template <typename PairType> |
| 6885 | operator Matcher<PairType>() const { |
| 6886 | return MakeMatcher(new KeyMatcherImpl<PairType>(matcher_for_key_)); |
| 6887 | } |
| 6888 | |
| 6889 | private: |
| 6890 | const M matcher_for_key_; |
| 6891 | |
| 6892 | GTEST_DISALLOW_ASSIGN_(KeyMatcher); |
| 6893 | }; |
| 6894 | |
| 6895 | // Implements Pair(first_matcher, second_matcher) for the given argument pair |
| 6896 | // type with its two matchers. See Pair() function below. |
| 6897 | template <typename PairType> |
| 6898 | class PairMatcherImpl : public MatcherInterface<PairType> { |
| 6899 | public: |
| 6900 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType; |
| 6901 | typedef typename RawPairType::first_type FirstType; |
| 6902 | typedef typename RawPairType::second_type SecondType; |
| 6903 | |
| 6904 | template <typename FirstMatcher, typename SecondMatcher> |
| 6905 | PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher) |
| 6906 | : first_matcher_( |
| 6907 | testing::SafeMatcherCast<const FirstType&>(first_matcher)), |
| 6908 | second_matcher_( |
| 6909 | testing::SafeMatcherCast<const SecondType&>(second_matcher)) { |
| 6910 | } |
| 6911 | |
| 6912 | // Describes what this matcher does. |
| 6913 | virtual void DescribeTo(::std::ostream* os) const { |
| 6914 | *os << "has a first field that "; |
| 6915 | first_matcher_.DescribeTo(os); |
| 6916 | *os << ", and has a second field that "; |
| 6917 | second_matcher_.DescribeTo(os); |
| 6918 | } |
| 6919 | |
| 6920 | // Describes what the negation of this matcher does. |
| 6921 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 6922 | *os << "has a first field that "; |
| 6923 | first_matcher_.DescribeNegationTo(os); |
| 6924 | *os << ", or has a second field that "; |
| 6925 | second_matcher_.DescribeNegationTo(os); |
| 6926 | } |
| 6927 | |
| 6928 | // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.second' |
| 6929 | // matches second_matcher. |
| 6930 | virtual bool MatchAndExplain(PairType a_pair, |
| 6931 | MatchResultListener* listener) const { |
| 6932 | if (!listener->IsInterested()) { |
| 6933 | // If the listener is not interested, we don't need to construct the |
| 6934 | // explanation. |
| 6935 | return first_matcher_.Matches(a_pair.first) && |
| 6936 | second_matcher_.Matches(a_pair.second); |
| 6937 | } |
| 6938 | StringMatchResultListener first_inner_listener; |
| 6939 | if (!first_matcher_.MatchAndExplain(a_pair.first, |
| 6940 | &first_inner_listener)) { |
| 6941 | *listener << "whose first field does not match"; |
| 6942 | PrintIfNotEmpty(first_inner_listener.str(), listener->stream()); |
| 6943 | return false; |
| 6944 | } |
| 6945 | StringMatchResultListener second_inner_listener; |
| 6946 | if (!second_matcher_.MatchAndExplain(a_pair.second, |
| 6947 | &second_inner_listener)) { |
| 6948 | *listener << "whose second field does not match"; |
| 6949 | PrintIfNotEmpty(second_inner_listener.str(), listener->stream()); |
| 6950 | return false; |
| 6951 | } |
| 6952 | ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(), |
| 6953 | listener); |
| 6954 | return true; |
| 6955 | } |
| 6956 | |
| 6957 | private: |
| 6958 | void ExplainSuccess(const internal::string& first_explanation, |
| 6959 | const internal::string& second_explanation, |
| 6960 | MatchResultListener* listener) const { |
| 6961 | *listener << "whose both fields match"; |
| 6962 | if (first_explanation != "") { |
| 6963 | *listener << ", where the first field is a value " << first_explanation; |
| 6964 | } |
| 6965 | if (second_explanation != "") { |
| 6966 | *listener << ", "; |
| 6967 | if (first_explanation != "") { |
| 6968 | *listener << "and "; |
| 6969 | } else { |
| 6970 | *listener << "where "; |
| 6971 | } |
| 6972 | *listener << "the second field is a value " << second_explanation; |
| 6973 | } |
| 6974 | } |
| 6975 | |
| 6976 | const Matcher<const FirstType&> first_matcher_; |
| 6977 | const Matcher<const SecondType&> second_matcher_; |
| 6978 | |
| 6979 | GTEST_DISALLOW_ASSIGN_(PairMatcherImpl); |
| 6980 | }; |
| 6981 | |
| 6982 | // Implements polymorphic Pair(first_matcher, second_matcher). |
| 6983 | template <typename FirstMatcher, typename SecondMatcher> |
| 6984 | class PairMatcher { |
| 6985 | public: |
| 6986 | PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher) |
| 6987 | : first_matcher_(first_matcher), second_matcher_(second_matcher) {} |
| 6988 | |
| 6989 | template <typename PairType> |
| 6990 | operator Matcher<PairType> () const { |
| 6991 | return MakeMatcher( |
| 6992 | new PairMatcherImpl<PairType>( |
| 6993 | first_matcher_, second_matcher_)); |
| 6994 | } |
| 6995 | |
| 6996 | private: |
| 6997 | const FirstMatcher first_matcher_; |
| 6998 | const SecondMatcher second_matcher_; |
| 6999 | |
| 7000 | GTEST_DISALLOW_ASSIGN_(PairMatcher); |
| 7001 | }; |
| 7002 | |
| 7003 | // Implements ElementsAre() and ElementsAreArray(). |
| 7004 | template <typename Container> |
| 7005 | class ElementsAreMatcherImpl : public MatcherInterface<Container> { |
| 7006 | public: |
| 7007 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 7008 | typedef internal::StlContainerView<RawContainer> View; |
| 7009 | typedef typename View::type StlContainer; |
| 7010 | typedef typename View::const_reference StlContainerReference; |
| 7011 | typedef typename StlContainer::value_type Element; |
| 7012 | |
| 7013 | // Constructs the matcher from a sequence of element values or |
| 7014 | // element matchers. |
| 7015 | template <typename InputIter> |
| 7016 | ElementsAreMatcherImpl(InputIter first, size_t a_count) { |
| 7017 | matchers_.reserve(a_count); |
| 7018 | InputIter it = first; |
| 7019 | for (size_t i = 0; i != a_count; ++i, ++it) { |
| 7020 | matchers_.push_back(MatcherCast<const Element&>(*it)); |
| 7021 | } |
| 7022 | } |
| 7023 | |
| 7024 | // Describes what this matcher does. |
| 7025 | virtual void DescribeTo(::std::ostream* os) const { |
| 7026 | if (count() == 0) { |
| 7027 | *os << "is empty"; |
| 7028 | } else if (count() == 1) { |
| 7029 | *os << "has 1 element that "; |
| 7030 | matchers_[0].DescribeTo(os); |
| 7031 | } else { |
| 7032 | *os << "has " << Elements(count()) << " where\n"; |
| 7033 | for (size_t i = 0; i != count(); ++i) { |
| 7034 | *os << "element #" << i << " "; |
| 7035 | matchers_[i].DescribeTo(os); |
| 7036 | if (i + 1 < count()) { |
| 7037 | *os << ",\n"; |
| 7038 | } |
| 7039 | } |
| 7040 | } |
| 7041 | } |
| 7042 | |
| 7043 | // Describes what the negation of this matcher does. |
| 7044 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 7045 | if (count() == 0) { |
| 7046 | *os << "isn't empty"; |
| 7047 | return; |
| 7048 | } |
| 7049 | |
| 7050 | *os << "doesn't have " << Elements(count()) << ", or\n"; |
| 7051 | for (size_t i = 0; i != count(); ++i) { |
| 7052 | *os << "element #" << i << " "; |
| 7053 | matchers_[i].DescribeNegationTo(os); |
| 7054 | if (i + 1 < count()) { |
| 7055 | *os << ", or\n"; |
| 7056 | } |
| 7057 | } |
| 7058 | } |
| 7059 | |
| 7060 | virtual bool MatchAndExplain(Container container, |
| 7061 | MatchResultListener* listener) const { |
| 7062 | StlContainerReference stl_container = View::ConstReference(container); |
| 7063 | const size_t actual_count = stl_container.size(); |
| 7064 | if (actual_count != count()) { |
| 7065 | // The element count doesn't match. If the container is empty, |
| 7066 | // there's no need to explain anything as Google Mock already |
| 7067 | // prints the empty container. Otherwise we just need to show |
| 7068 | // how many elements there actually are. |
| 7069 | if (actual_count != 0) { |
| 7070 | *listener << "which has " << Elements(actual_count); |
| 7071 | } |
| 7072 | return false; |
| 7073 | } |
| 7074 | |
| 7075 | typename StlContainer::const_iterator it = stl_container.begin(); |
| 7076 | // explanations[i] is the explanation of the element at index i. |
| 7077 | std::vector<internal::string> explanations(count()); |
| 7078 | for (size_t i = 0; i != count(); ++it, ++i) { |
| 7079 | StringMatchResultListener s; |
| 7080 | if (matchers_[i].MatchAndExplain(*it, &s)) { |
| 7081 | explanations[i] = s.str(); |
| 7082 | } else { |
| 7083 | // The container has the right size but the i-th element |
| 7084 | // doesn't match its expectation. |
| 7085 | *listener << "whose element #" << i << " doesn't match"; |
| 7086 | PrintIfNotEmpty(s.str(), listener->stream()); |
| 7087 | return false; |
| 7088 | } |
| 7089 | } |
| 7090 | |
| 7091 | // Every element matches its expectation. We need to explain why |
| 7092 | // (the obvious ones can be skipped). |
| 7093 | bool reason_printed = false; |
| 7094 | for (size_t i = 0; i != count(); ++i) { |
| 7095 | const internal::string& s = explanations[i]; |
| 7096 | if (!s.empty()) { |
| 7097 | if (reason_printed) { |
| 7098 | *listener << ",\nand "; |
| 7099 | } |
| 7100 | *listener << "whose element #" << i << " matches, " << s; |
| 7101 | reason_printed = true; |
| 7102 | } |
| 7103 | } |
| 7104 | |
| 7105 | return true; |
| 7106 | } |
| 7107 | |
| 7108 | private: |
| 7109 | static Message Elements(size_t count) { |
| 7110 | return Message() << count << (count == 1 ? " element" : " elements"); |
| 7111 | } |
| 7112 | |
| 7113 | size_t count() const { return matchers_.size(); } |
| 7114 | std::vector<Matcher<const Element&> > matchers_; |
| 7115 | |
| 7116 | GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl); |
| 7117 | }; |
| 7118 | |
| 7119 | // Implements ElementsAre() of 0 arguments. |
| 7120 | class ElementsAreMatcher0 { |
| 7121 | public: |
| 7122 | ElementsAreMatcher0() {} |
| 7123 | |
| 7124 | template <typename Container> |
| 7125 | operator Matcher<Container>() const { |
| 7126 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 7127 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 7128 | Element; |
| 7129 | |
| 7130 | const Matcher<const Element&>* const matchers = NULL; |
| 7131 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 0)); |
| 7132 | } |
| 7133 | }; |
| 7134 | |
| 7135 | // Implements ElementsAreArray(). |
| 7136 | template <typename T> |
| 7137 | class ElementsAreArrayMatcher { |
| 7138 | public: |
| 7139 | ElementsAreArrayMatcher(const T* first, size_t count) : |
| 7140 | first_(first), count_(count) {} |
| 7141 | |
| 7142 | template <typename Container> |
| 7143 | operator Matcher<Container>() const { |
| 7144 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 7145 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 7146 | Element; |
| 7147 | |
| 7148 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(first_, count_)); |
| 7149 | } |
| 7150 | |
| 7151 | private: |
| 7152 | const T* const first_; |
| 7153 | const size_t count_; |
| 7154 | |
| 7155 | GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher); |
| 7156 | }; |
| 7157 | |
| 7158 | // Returns the description for a matcher defined using the MATCHER*() |
| 7159 | // macro where the user-supplied description string is "", if |
| 7160 | // 'negation' is false; otherwise returns the description of the |
| 7161 | // negation of the matcher. 'param_values' contains a list of strings |
| 7162 | // that are the print-out of the matcher's parameters. |
| 7163 | string FormatMatcherDescription(bool negation, const char* matcher_name, |
| 7164 | const Strings& param_values); |
| 7165 | |
| 7166 | } // namespace internal |
| 7167 | |
| 7168 | // Implements MatcherCast(). |
| 7169 | template <typename T, typename M> |
| 7170 | inline Matcher<T> MatcherCast(M matcher) { |
| 7171 | return internal::MatcherCastImpl<T, M>::Cast(matcher); |
| 7172 | } |
| 7173 | |
| 7174 | // _ is a matcher that matches anything of any type. |
| 7175 | // |
| 7176 | // This definition is fine as: |
| 7177 | // |
| 7178 | // 1. The C++ standard permits using the name _ in a namespace that |
| 7179 | // is not the global namespace or ::std. |
| 7180 | // 2. The AnythingMatcher class has no data member or constructor, |
| 7181 | // so it's OK to create global variables of this type. |
| 7182 | // 3. c-style has approved of using _ in this case. |
| 7183 | const internal::AnythingMatcher _ = {}; |
| 7184 | // Creates a matcher that matches any value of the given type T. |
| 7185 | template <typename T> |
| 7186 | inline Matcher<T> A() { return MakeMatcher(new internal::AnyMatcherImpl<T>()); } |
| 7187 | |
| 7188 | // Creates a matcher that matches any value of the given type T. |
| 7189 | template <typename T> |
| 7190 | inline Matcher<T> An() { return A<T>(); } |
| 7191 | |
| 7192 | // Creates a polymorphic matcher that matches anything equal to x. |
| 7193 | // Note: if the parameter of Eq() were declared as const T&, Eq("foo") |
| 7194 | // wouldn't compile. |
| 7195 | template <typename T> |
| 7196 | inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); } |
| 7197 | |
| 7198 | // Constructs a Matcher<T> from a 'value' of type T. The constructed |
| 7199 | // matcher matches any value that's equal to 'value'. |
| 7200 | template <typename T> |
| 7201 | Matcher<T>::Matcher(T value) { *this = Eq(value); } |
| 7202 | |
| 7203 | // Creates a monomorphic matcher that matches anything with type Lhs |
| 7204 | // and equal to rhs. A user may need to use this instead of Eq(...) |
| 7205 | // in order to resolve an overloading ambiguity. |
| 7206 | // |
| 7207 | // TypedEq<T>(x) is just a convenient short-hand for Matcher<T>(Eq(x)) |
| 7208 | // or Matcher<T>(x), but more readable than the latter. |
| 7209 | // |
| 7210 | // We could define similar monomorphic matchers for other comparison |
| 7211 | // operations (e.g. TypedLt, TypedGe, and etc), but decided not to do |
| 7212 | // it yet as those are used much less than Eq() in practice. A user |
| 7213 | // can always write Matcher<T>(Lt(5)) to be explicit about the type, |
| 7214 | // for example. |
| 7215 | template <typename Lhs, typename Rhs> |
| 7216 | inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); } |
| 7217 | |
| 7218 | // Creates a polymorphic matcher that matches anything >= x. |
| 7219 | template <typename Rhs> |
| 7220 | inline internal::GeMatcher<Rhs> Ge(Rhs x) { |
| 7221 | return internal::GeMatcher<Rhs>(x); |
| 7222 | } |
| 7223 | |
| 7224 | // Creates a polymorphic matcher that matches anything > x. |
| 7225 | template <typename Rhs> |
| 7226 | inline internal::GtMatcher<Rhs> Gt(Rhs x) { |
| 7227 | return internal::GtMatcher<Rhs>(x); |
| 7228 | } |
| 7229 | |
| 7230 | // Creates a polymorphic matcher that matches anything <= x. |
| 7231 | template <typename Rhs> |
| 7232 | inline internal::LeMatcher<Rhs> Le(Rhs x) { |
| 7233 | return internal::LeMatcher<Rhs>(x); |
| 7234 | } |
| 7235 | |
| 7236 | // Creates a polymorphic matcher that matches anything < x. |
| 7237 | template <typename Rhs> |
| 7238 | inline internal::LtMatcher<Rhs> Lt(Rhs x) { |
| 7239 | return internal::LtMatcher<Rhs>(x); |
| 7240 | } |
| 7241 | |
| 7242 | // Creates a polymorphic matcher that matches anything != x. |
| 7243 | template <typename Rhs> |
| 7244 | inline internal::NeMatcher<Rhs> Ne(Rhs x) { |
| 7245 | return internal::NeMatcher<Rhs>(x); |
| 7246 | } |
| 7247 | |
| 7248 | // Creates a polymorphic matcher that matches any NULL pointer. |
| 7249 | inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() { |
| 7250 | return MakePolymorphicMatcher(internal::IsNullMatcher()); |
| 7251 | } |
| 7252 | |
| 7253 | // Creates a polymorphic matcher that matches any non-NULL pointer. |
| 7254 | // This is convenient as Not(NULL) doesn't compile (the compiler |
| 7255 | // thinks that that expression is comparing a pointer with an integer). |
| 7256 | inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() { |
| 7257 | return MakePolymorphicMatcher(internal::NotNullMatcher()); |
| 7258 | } |
| 7259 | |
| 7260 | // Creates a polymorphic matcher that matches any argument that |
| 7261 | // references variable x. |
| 7262 | template <typename T> |
| 7263 | inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT |
| 7264 | return internal::RefMatcher<T&>(x); |
| 7265 | } |
| 7266 | |
| 7267 | // Creates a matcher that matches any double argument approximately |
| 7268 | // equal to rhs, where two NANs are considered unequal. |
| 7269 | inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) { |
| 7270 | return internal::FloatingEqMatcher<double>(rhs, false); |
| 7271 | } |
| 7272 | |
| 7273 | // Creates a matcher that matches any double argument approximately |
| 7274 | // equal to rhs, including NaN values when rhs is NaN. |
| 7275 | inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(double rhs) { |
| 7276 | return internal::FloatingEqMatcher<double>(rhs, true); |
| 7277 | } |
| 7278 | |
| 7279 | // Creates a matcher that matches any float argument approximately |
| 7280 | // equal to rhs, where two NANs are considered unequal. |
| 7281 | inline internal::FloatingEqMatcher<float> FloatEq(float rhs) { |
| 7282 | return internal::FloatingEqMatcher<float>(rhs, false); |
| 7283 | } |
| 7284 | |
| 7285 | // Creates a matcher that matches any double argument approximately |
| 7286 | // equal to rhs, including NaN values when rhs is NaN. |
| 7287 | inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(float rhs) { |
| 7288 | return internal::FloatingEqMatcher<float>(rhs, true); |
| 7289 | } |
| 7290 | |
| 7291 | // Creates a matcher that matches a pointer (raw or smart) that points |
| 7292 | // to a value that matches inner_matcher. |
| 7293 | template <typename InnerMatcher> |
| 7294 | inline internal::PointeeMatcher<InnerMatcher> Pointee( |
| 7295 | const InnerMatcher& inner_matcher) { |
| 7296 | return internal::PointeeMatcher<InnerMatcher>(inner_matcher); |
| 7297 | } |
| 7298 | |
| 7299 | // Creates a matcher that matches an object whose given field matches |
| 7300 | // 'matcher'. For example, |
| 7301 | // Field(&Foo::number, Ge(5)) |
| 7302 | // matches a Foo object x iff x.number >= 5. |
| 7303 | template <typename Class, typename FieldType, typename FieldMatcher> |
| 7304 | inline PolymorphicMatcher< |
| 7305 | internal::FieldMatcher<Class, FieldType> > Field( |
| 7306 | FieldType Class::*field, const FieldMatcher& matcher) { |
| 7307 | return MakePolymorphicMatcher( |
| 7308 | internal::FieldMatcher<Class, FieldType>( |
| 7309 | field, MatcherCast<const FieldType&>(matcher))); |
| 7310 | // The call to MatcherCast() is required for supporting inner |
| 7311 | // matchers of compatible types. For example, it allows |
| 7312 | // Field(&Foo::bar, m) |
| 7313 | // to compile where bar is an int32 and m is a matcher for int64. |
| 7314 | } |
| 7315 | |
| 7316 | // Creates a matcher that matches an object whose given property |
| 7317 | // matches 'matcher'. For example, |
| 7318 | // Property(&Foo::str, StartsWith("hi")) |
| 7319 | // matches a Foo object x iff x.str() starts with "hi". |
| 7320 | template <typename Class, typename PropertyType, typename PropertyMatcher> |
| 7321 | inline PolymorphicMatcher< |
| 7322 | internal::PropertyMatcher<Class, PropertyType> > Property( |
| 7323 | PropertyType (Class::*property)() const, const PropertyMatcher& matcher) { |
| 7324 | return MakePolymorphicMatcher( |
| 7325 | internal::PropertyMatcher<Class, PropertyType>( |
| 7326 | property, |
| 7327 | MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); |
| 7328 | // The call to MatcherCast() is required for supporting inner |
| 7329 | // matchers of compatible types. For example, it allows |
| 7330 | // Property(&Foo::bar, m) |
| 7331 | // to compile where bar() returns an int32 and m is a matcher for int64. |
| 7332 | } |
| 7333 | |
| 7334 | // Creates a matcher that matches an object iff the result of applying |
| 7335 | // a callable to x matches 'matcher'. |
| 7336 | // For example, |
| 7337 | // ResultOf(f, StartsWith("hi")) |
| 7338 | // matches a Foo object x iff f(x) starts with "hi". |
| 7339 | // callable parameter can be a function, function pointer, or a functor. |
| 7340 | // Callable has to satisfy the following conditions: |
| 7341 | // * It is required to keep no state affecting the results of |
| 7342 | // the calls on it and make no assumptions about how many calls |
| 7343 | // will be made. Any state it keeps must be protected from the |
| 7344 | // concurrent access. |
| 7345 | // * If it is a function object, it has to define type result_type. |
| 7346 | // We recommend deriving your functor classes from std::unary_function. |
| 7347 | template <typename Callable, typename ResultOfMatcher> |
| 7348 | internal::ResultOfMatcher<Callable> ResultOf( |
| 7349 | Callable callable, const ResultOfMatcher& matcher) { |
| 7350 | return internal::ResultOfMatcher<Callable>( |
| 7351 | callable, |
| 7352 | MatcherCast<typename internal::CallableTraits<Callable>::ResultType>( |
| 7353 | matcher)); |
| 7354 | // The call to MatcherCast() is required for supporting inner |
| 7355 | // matchers of compatible types. For example, it allows |
| 7356 | // ResultOf(Function, m) |
| 7357 | // to compile where Function() returns an int32 and m is a matcher for int64. |
| 7358 | } |
| 7359 | |
| 7360 | // String matchers. |
| 7361 | |
| 7362 | // Matches a string equal to str. |
| 7363 | inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > |
| 7364 | StrEq(const internal::string& str) { |
| 7365 | return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( |
| 7366 | str, true, true)); |
| 7367 | } |
| 7368 | |
| 7369 | // Matches a string not equal to str. |
| 7370 | inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > |
| 7371 | StrNe(const internal::string& str) { |
| 7372 | return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( |
| 7373 | str, false, true)); |
| 7374 | } |
| 7375 | |
| 7376 | // Matches a string equal to str, ignoring case. |
| 7377 | inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > |
| 7378 | StrCaseEq(const internal::string& str) { |
| 7379 | return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( |
| 7380 | str, true, false)); |
| 7381 | } |
| 7382 | |
| 7383 | // Matches a string not equal to str, ignoring case. |
| 7384 | inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > |
| 7385 | StrCaseNe(const internal::string& str) { |
| 7386 | return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( |
| 7387 | str, false, false)); |
| 7388 | } |
| 7389 | |
| 7390 | // Creates a matcher that matches any string, std::string, or C string |
| 7391 | // that contains the given substring. |
| 7392 | inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::string> > |
| 7393 | HasSubstr(const internal::string& substring) { |
| 7394 | return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::string>( |
| 7395 | substring)); |
| 7396 | } |
| 7397 | |
| 7398 | // Matches a string that starts with 'prefix' (case-sensitive). |
| 7399 | inline PolymorphicMatcher<internal::StartsWithMatcher<internal::string> > |
| 7400 | StartsWith(const internal::string& prefix) { |
| 7401 | return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::string>( |
| 7402 | prefix)); |
| 7403 | } |
| 7404 | |
| 7405 | // Matches a string that ends with 'suffix' (case-sensitive). |
| 7406 | inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> > |
| 7407 | EndsWith(const internal::string& suffix) { |
| 7408 | return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string>( |
| 7409 | suffix)); |
| 7410 | } |
| 7411 | |
| 7412 | // Matches a string that fully matches regular expression 'regex'. |
| 7413 | // The matcher takes ownership of 'regex'. |
| 7414 | inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( |
| 7415 | const internal::RE* regex) { |
| 7416 | return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true)); |
| 7417 | } |
| 7418 | inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( |
| 7419 | const internal::string& regex) { |
| 7420 | return MatchesRegex(new internal::RE(regex)); |
| 7421 | } |
| 7422 | |
| 7423 | // Matches a string that contains regular expression 'regex'. |
| 7424 | // The matcher takes ownership of 'regex'. |
| 7425 | inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( |
| 7426 | const internal::RE* regex) { |
| 7427 | return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false)); |
| 7428 | } |
| 7429 | inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( |
| 7430 | const internal::string& regex) { |
| 7431 | return ContainsRegex(new internal::RE(regex)); |
| 7432 | } |
| 7433 | |
| 7434 | #if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING |
| 7435 | // Wide string matchers. |
| 7436 | |
| 7437 | // Matches a string equal to str. |
| 7438 | inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > |
| 7439 | StrEq(const internal::wstring& str) { |
| 7440 | return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( |
| 7441 | str, true, true)); |
| 7442 | } |
| 7443 | |
| 7444 | // Matches a string not equal to str. |
| 7445 | inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > |
| 7446 | StrNe(const internal::wstring& str) { |
| 7447 | return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( |
| 7448 | str, false, true)); |
| 7449 | } |
| 7450 | |
| 7451 | // Matches a string equal to str, ignoring case. |
| 7452 | inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > |
| 7453 | StrCaseEq(const internal::wstring& str) { |
| 7454 | return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( |
| 7455 | str, true, false)); |
| 7456 | } |
| 7457 | |
| 7458 | // Matches a string not equal to str, ignoring case. |
| 7459 | inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > |
| 7460 | StrCaseNe(const internal::wstring& str) { |
| 7461 | return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( |
| 7462 | str, false, false)); |
| 7463 | } |
| 7464 | |
| 7465 | // Creates a matcher that matches any wstring, std::wstring, or C wide string |
| 7466 | // that contains the given substring. |
| 7467 | inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::wstring> > |
| 7468 | HasSubstr(const internal::wstring& substring) { |
| 7469 | return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::wstring>( |
| 7470 | substring)); |
| 7471 | } |
| 7472 | |
| 7473 | // Matches a string that starts with 'prefix' (case-sensitive). |
| 7474 | inline PolymorphicMatcher<internal::StartsWithMatcher<internal::wstring> > |
| 7475 | StartsWith(const internal::wstring& prefix) { |
| 7476 | return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::wstring>( |
| 7477 | prefix)); |
| 7478 | } |
| 7479 | |
| 7480 | // Matches a string that ends with 'suffix' (case-sensitive). |
| 7481 | inline PolymorphicMatcher<internal::EndsWithMatcher<internal::wstring> > |
| 7482 | EndsWith(const internal::wstring& suffix) { |
| 7483 | return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::wstring>( |
| 7484 | suffix)); |
| 7485 | } |
| 7486 | |
| 7487 | #endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING |
| 7488 | |
| 7489 | // Creates a polymorphic matcher that matches a 2-tuple where the |
| 7490 | // first field == the second field. |
| 7491 | inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); } |
| 7492 | |
| 7493 | // Creates a polymorphic matcher that matches a 2-tuple where the |
| 7494 | // first field >= the second field. |
| 7495 | inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); } |
| 7496 | |
| 7497 | // Creates a polymorphic matcher that matches a 2-tuple where the |
| 7498 | // first field > the second field. |
| 7499 | inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); } |
| 7500 | |
| 7501 | // Creates a polymorphic matcher that matches a 2-tuple where the |
| 7502 | // first field <= the second field. |
| 7503 | inline internal::Le2Matcher Le() { return internal::Le2Matcher(); } |
| 7504 | |
| 7505 | // Creates a polymorphic matcher that matches a 2-tuple where the |
| 7506 | // first field < the second field. |
| 7507 | inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); } |
| 7508 | |
| 7509 | // Creates a polymorphic matcher that matches a 2-tuple where the |
| 7510 | // first field != the second field. |
| 7511 | inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); } |
| 7512 | |
| 7513 | // Creates a matcher that matches any value of type T that m doesn't |
| 7514 | // match. |
| 7515 | template <typename InnerMatcher> |
| 7516 | inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) { |
| 7517 | return internal::NotMatcher<InnerMatcher>(m); |
| 7518 | } |
| 7519 | |
| 7520 | // Returns a matcher that matches anything that satisfies the given |
| 7521 | // predicate. The predicate can be any unary function or functor |
| 7522 | // whose return type can be implicitly converted to bool. |
| 7523 | template <typename Predicate> |
| 7524 | inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> > |
| 7525 | Truly(Predicate pred) { |
| 7526 | return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred)); |
| 7527 | } |
| 7528 | |
| 7529 | // Returns a matcher that matches an equal container. |
| 7530 | // This matcher behaves like Eq(), but in the event of mismatch lists the |
| 7531 | // values that are included in one container but not the other. (Duplicate |
| 7532 | // values and order differences are not explained.) |
| 7533 | template <typename Container> |
| 7534 | inline PolymorphicMatcher<internal::ContainerEqMatcher< // NOLINT |
| 7535 | GTEST_REMOVE_CONST_(Container)> > |
| 7536 | ContainerEq(const Container& rhs) { |
| 7537 | // This following line is for working around a bug in MSVC 8.0, |
| 7538 | // which causes Container to be a const type sometimes. |
| 7539 | typedef GTEST_REMOVE_CONST_(Container) RawContainer; |
| 7540 | return MakePolymorphicMatcher( |
| 7541 | internal::ContainerEqMatcher<RawContainer>(rhs)); |
| 7542 | } |
| 7543 | |
| 7544 | // Matches an STL-style container or a native array that contains the |
| 7545 | // same number of elements as in rhs, where its i-th element and rhs's |
| 7546 | // i-th element (as a pair) satisfy the given pair matcher, for all i. |
| 7547 | // TupleMatcher must be able to be safely cast to Matcher<tuple<const |
| 7548 | // T1&, const T2&> >, where T1 and T2 are the types of elements in the |
| 7549 | // LHS container and the RHS container respectively. |
| 7550 | template <typename TupleMatcher, typename Container> |
| 7551 | inline internal::PointwiseMatcher<TupleMatcher, |
| 7552 | GTEST_REMOVE_CONST_(Container)> |
| 7553 | Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) { |
| 7554 | // This following line is for working around a bug in MSVC 8.0, |
| 7555 | // which causes Container to be a const type sometimes. |
| 7556 | typedef GTEST_REMOVE_CONST_(Container) RawContainer; |
| 7557 | return internal::PointwiseMatcher<TupleMatcher, RawContainer>( |
| 7558 | tuple_matcher, rhs); |
| 7559 | } |
| 7560 | |
| 7561 | // Matches an STL-style container or a native array that contains at |
| 7562 | // least one element matching the given value or matcher. |
| 7563 | // |
| 7564 | // Examples: |
| 7565 | // ::std::set<int> page_ids; |
| 7566 | // page_ids.insert(3); |
| 7567 | // page_ids.insert(1); |
| 7568 | // EXPECT_THAT(page_ids, Contains(1)); |
| 7569 | // EXPECT_THAT(page_ids, Contains(Gt(2))); |
| 7570 | // EXPECT_THAT(page_ids, Not(Contains(4))); |
| 7571 | // |
| 7572 | // ::std::map<int, size_t> page_lengths; |
| 7573 | // page_lengths[1] = 100; |
| 7574 | // EXPECT_THAT(page_lengths, |
| 7575 | // Contains(::std::pair<const int, size_t>(1, 100))); |
| 7576 | // |
| 7577 | // const char* user_ids[] = { "joe", "mike", "tom" }; |
| 7578 | // EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom")))); |
| 7579 | template <typename M> |
| 7580 | inline internal::ContainsMatcher<M> Contains(M matcher) { |
| 7581 | return internal::ContainsMatcher<M>(matcher); |
| 7582 | } |
| 7583 | |
| 7584 | // Matches an STL-style container or a native array that contains only |
| 7585 | // elements matching the given value or matcher. |
| 7586 | // |
| 7587 | // Each(m) is semantically equivalent to Not(Contains(Not(m))). Only |
| 7588 | // the messages are different. |
| 7589 | // |
| 7590 | // Examples: |
| 7591 | // ::std::set<int> page_ids; |
| 7592 | // // Each(m) matches an empty container, regardless of what m is. |
| 7593 | // EXPECT_THAT(page_ids, Each(Eq(1))); |
| 7594 | // EXPECT_THAT(page_ids, Each(Eq(77))); |
| 7595 | // |
| 7596 | // page_ids.insert(3); |
| 7597 | // EXPECT_THAT(page_ids, Each(Gt(0))); |
| 7598 | // EXPECT_THAT(page_ids, Not(Each(Gt(4)))); |
| 7599 | // page_ids.insert(1); |
| 7600 | // EXPECT_THAT(page_ids, Not(Each(Lt(2)))); |
| 7601 | // |
| 7602 | // ::std::map<int, size_t> page_lengths; |
| 7603 | // page_lengths[1] = 100; |
| 7604 | // page_lengths[2] = 200; |
| 7605 | // page_lengths[3] = 300; |
| 7606 | // EXPECT_THAT(page_lengths, Not(Each(Pair(1, 100)))); |
| 7607 | // EXPECT_THAT(page_lengths, Each(Key(Le(3)))); |
| 7608 | // |
| 7609 | // const char* user_ids[] = { "joe", "mike", "tom" }; |
| 7610 | // EXPECT_THAT(user_ids, Not(Each(Eq(::std::string("tom"))))); |
| 7611 | template <typename M> |
| 7612 | inline internal::EachMatcher<M> Each(M matcher) { |
| 7613 | return internal::EachMatcher<M>(matcher); |
| 7614 | } |
| 7615 | |
| 7616 | // Key(inner_matcher) matches an std::pair whose 'first' field matches |
| 7617 | // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an |
| 7618 | // std::map that contains at least one element whose key is >= 5. |
| 7619 | template <typename M> |
| 7620 | inline internal::KeyMatcher<M> Key(M inner_matcher) { |
| 7621 | return internal::KeyMatcher<M>(inner_matcher); |
| 7622 | } |
| 7623 | |
| 7624 | // Pair(first_matcher, second_matcher) matches a std::pair whose 'first' field |
| 7625 | // matches first_matcher and whose 'second' field matches second_matcher. For |
| 7626 | // example, EXPECT_THAT(map_type, ElementsAre(Pair(Ge(5), "foo"))) can be used |
| 7627 | // to match a std::map<int, string> that contains exactly one element whose key |
| 7628 | // is >= 5 and whose value equals "foo". |
| 7629 | template <typename FirstMatcher, typename SecondMatcher> |
| 7630 | inline internal::PairMatcher<FirstMatcher, SecondMatcher> |
| 7631 | Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) { |
| 7632 | return internal::PairMatcher<FirstMatcher, SecondMatcher>( |
| 7633 | first_matcher, second_matcher); |
| 7634 | } |
| 7635 | |
| 7636 | // Returns a predicate that is satisfied by anything that matches the |
| 7637 | // given matcher. |
| 7638 | template <typename M> |
| 7639 | inline internal::MatcherAsPredicate<M> Matches(M matcher) { |
| 7640 | return internal::MatcherAsPredicate<M>(matcher); |
| 7641 | } |
| 7642 | |
| 7643 | // Returns true iff the value matches the matcher. |
| 7644 | template <typename T, typename M> |
| 7645 | inline bool Value(const T& value, M matcher) { |
| 7646 | return testing::Matches(matcher)(value); |
| 7647 | } |
| 7648 | |
| 7649 | // Matches the value against the given matcher and explains the match |
| 7650 | // result to listener. |
| 7651 | template <typename T, typename M> |
| 7652 | inline bool ExplainMatchResult( |
| 7653 | M matcher, const T& value, MatchResultListener* listener) { |
| 7654 | return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener); |
| 7655 | } |
| 7656 | |
| 7657 | // AllArgs(m) is a synonym of m. This is useful in |
| 7658 | // |
| 7659 | // EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq())); |
| 7660 | // |
| 7661 | // which is easier to read than |
| 7662 | // |
| 7663 | // EXPECT_CALL(foo, Bar(_, _)).With(Eq()); |
| 7664 | template <typename InnerMatcher> |
| 7665 | inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; } |
| 7666 | |
| 7667 | // These macros allow using matchers to check values in Google Test |
| 7668 | // tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher) |
| 7669 | // succeed iff the value matches the matcher. If the assertion fails, |
| 7670 | // the value and the description of the matcher will be printed. |
| 7671 | #define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\ |
| 7672 | ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) |
| 7673 | #define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\ |
| 7674 | ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) |
| 7675 | |
| 7676 | } // namespace testing |
| 7677 | |
| 7678 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ |
| 7679 | |
| 7680 | namespace testing { |
| 7681 | |
| 7682 | // An abstract handle of an expectation. |
| 7683 | class Expectation; |
| 7684 | |
| 7685 | // A set of expectation handles. |
| 7686 | class ExpectationSet; |
| 7687 | |
| 7688 | // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION |
| 7689 | // and MUST NOT BE USED IN USER CODE!!! |
| 7690 | namespace internal { |
| 7691 | |
| 7692 | // Implements a mock function. |
| 7693 | template <typename F> class FunctionMocker; |
| 7694 | |
| 7695 | // Base class for expectations. |
| 7696 | class ExpectationBase; |
| 7697 | |
| 7698 | // Implements an expectation. |
| 7699 | template <typename F> class TypedExpectation; |
| 7700 | |
| 7701 | // Helper class for testing the Expectation class template. |
| 7702 | class ExpectationTester; |
| 7703 | |
| 7704 | // Base class for function mockers. |
| 7705 | template <typename F> class FunctionMockerBase; |
| 7706 | |
| 7707 | // Protects the mock object registry (in class Mock), all function |
| 7708 | // mockers, and all expectations. |
| 7709 | // |
| 7710 | // The reason we don't use more fine-grained protection is: when a |
| 7711 | // mock function Foo() is called, it needs to consult its expectations |
| 7712 | // to see which one should be picked. If another thread is allowed to |
| 7713 | // call a mock function (either Foo() or a different one) at the same |
| 7714 | // time, it could affect the "retired" attributes of Foo()'s |
| 7715 | // expectations when InSequence() is used, and thus affect which |
| 7716 | // expectation gets picked. Therefore, we sequence all mock function |
| 7717 | // calls to ensure the integrity of the mock objects' states. |
| 7718 | GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex); |
| 7719 | |
| 7720 | // Untyped base class for ActionResultHolder<R>. |
| 7721 | class UntypedActionResultHolderBase; |
| 7722 | |
| 7723 | // Abstract base class of FunctionMockerBase. This is the |
| 7724 | // type-agnostic part of the function mocker interface. Its pure |
| 7725 | // virtual methods are implemented by FunctionMockerBase. |
| 7726 | class UntypedFunctionMockerBase { |
| 7727 | public: |
| 7728 | UntypedFunctionMockerBase(); |
| 7729 | virtual ~UntypedFunctionMockerBase(); |
| 7730 | |
| 7731 | // Verifies that all expectations on this mock function have been |
| 7732 | // satisfied. Reports one or more Google Test non-fatal failures |
| 7733 | // and returns false if not. |
| 7734 | // L >= g_gmock_mutex |
| 7735 | bool VerifyAndClearExpectationsLocked(); |
| 7736 | |
| 7737 | // Clears the ON_CALL()s set on this mock function. |
| 7738 | // L >= g_gmock_mutex |
| 7739 | virtual void ClearDefaultActionsLocked() = 0; |
| 7740 | |
| 7741 | // In all of the following Untyped* functions, it's the caller's |
| 7742 | // responsibility to guarantee the correctness of the arguments' |
| 7743 | // types. |
| 7744 | |
| 7745 | // Performs the default action with the given arguments and returns |
| 7746 | // the action's result. The call description string will be used in |
| 7747 | // the error message to describe the call in the case the default |
| 7748 | // action fails. |
| 7749 | // L = * |
| 7750 | virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( |
| 7751 | const void* untyped_args, |
| 7752 | const string& call_description) const = 0; |
| 7753 | |
| 7754 | // Performs the given action with the given arguments and returns |
| 7755 | // the action's result. |
| 7756 | // L = * |
| 7757 | virtual UntypedActionResultHolderBase* UntypedPerformAction( |
| 7758 | const void* untyped_action, |
| 7759 | const void* untyped_args) const = 0; |
| 7760 | |
| 7761 | // Writes a message that the call is uninteresting (i.e. neither |
| 7762 | // explicitly expected nor explicitly unexpected) to the given |
| 7763 | // ostream. |
| 7764 | // L < g_gmock_mutex |
| 7765 | virtual void UntypedDescribeUninterestingCall(const void* untyped_args, |
| 7766 | ::std::ostream* os) const = 0; |
| 7767 | |
| 7768 | // Returns the expectation that matches the given function arguments |
| 7769 | // (or NULL is there's no match); when a match is found, |
| 7770 | // untyped_action is set to point to the action that should be |
| 7771 | // performed (or NULL if the action is "do default"), and |
| 7772 | // is_excessive is modified to indicate whether the call exceeds the |
| 7773 | // expected number. |
| 7774 | // L < g_gmock_mutex |
| 7775 | virtual const ExpectationBase* UntypedFindMatchingExpectation( |
| 7776 | const void* untyped_args, |
| 7777 | const void** untyped_action, bool* is_excessive, |
| 7778 | ::std::ostream* what, ::std::ostream* why) = 0; |
| 7779 | |
| 7780 | // Prints the given function arguments to the ostream. |
| 7781 | virtual void UntypedPrintArgs(const void* untyped_args, |
| 7782 | ::std::ostream* os) const = 0; |
| 7783 | |
| 7784 | // Sets the mock object this mock method belongs to, and registers |
| 7785 | // this information in the global mock registry. Will be called |
| 7786 | // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock |
| 7787 | // method. |
| 7788 | // TODO(wan@google.com): rename to SetAndRegisterOwner(). |
| 7789 | // L < g_gmock_mutex |
| 7790 | void RegisterOwner(const void* mock_obj); |
| 7791 | |
| 7792 | // Sets the mock object this mock method belongs to, and sets the |
| 7793 | // name of the mock function. Will be called upon each invocation |
| 7794 | // of this mock function. |
| 7795 | // L < g_gmock_mutex |
| 7796 | void SetOwnerAndName(const void* mock_obj, const char* name); |
| 7797 | |
| 7798 | // Returns the mock object this mock method belongs to. Must be |
| 7799 | // called after RegisterOwner() or SetOwnerAndName() has been |
| 7800 | // called. |
| 7801 | // L < g_gmock_mutex |
| 7802 | const void* MockObject() const; |
| 7803 | |
| 7804 | // Returns the name of this mock method. Must be called after |
| 7805 | // SetOwnerAndName() has been called. |
| 7806 | // L < g_gmock_mutex |
| 7807 | const char* Name() const; |
| 7808 | |
| 7809 | // Returns the result of invoking this mock function with the given |
| 7810 | // arguments. This function can be safely called from multiple |
| 7811 | // threads concurrently. The caller is responsible for deleting the |
| 7812 | // result. |
| 7813 | // L < g_gmock_mutex |
| 7814 | const UntypedActionResultHolderBase* UntypedInvokeWith( |
| 7815 | const void* untyped_args); |
| 7816 | |
| 7817 | protected: |
| 7818 | typedef std::vector<const void*> UntypedOnCallSpecs; |
| 7819 | |
| 7820 | typedef std::vector<internal::linked_ptr<ExpectationBase> > |
| 7821 | UntypedExpectations; |
| 7822 | |
| 7823 | // Returns an Expectation object that references and co-owns exp, |
| 7824 | // which must be an expectation on this mock function. |
| 7825 | Expectation GetHandleOf(ExpectationBase* exp); |
| 7826 | |
| 7827 | // Address of the mock object this mock method belongs to. Only |
| 7828 | // valid after this mock method has been called or |
| 7829 | // ON_CALL/EXPECT_CALL has been invoked on it. |
| 7830 | const void* mock_obj_; // Protected by g_gmock_mutex. |
| 7831 | |
| 7832 | // Name of the function being mocked. Only valid after this mock |
| 7833 | // method has been called. |
| 7834 | const char* name_; // Protected by g_gmock_mutex. |
| 7835 | |
| 7836 | // All default action specs for this function mocker. |
| 7837 | UntypedOnCallSpecs untyped_on_call_specs_; |
| 7838 | |
| 7839 | // All expectations for this function mocker. |
| 7840 | UntypedExpectations untyped_expectations_; |
| 7841 | }; // class UntypedFunctionMockerBase |
| 7842 | |
| 7843 | // Untyped base class for OnCallSpec<F>. |
| 7844 | class UntypedOnCallSpecBase { |
| 7845 | public: |
| 7846 | // The arguments are the location of the ON_CALL() statement. |
| 7847 | UntypedOnCallSpecBase(const char* a_file, int a_line) |
| 7848 | : file_(a_file), line_(a_line), last_clause_(kNone) {} |
| 7849 | |
| 7850 | // Where in the source file was the default action spec defined? |
| 7851 | const char* file() const { return file_; } |
| 7852 | int line() const { return line_; } |
| 7853 | |
| 7854 | protected: |
| 7855 | // Gives each clause in the ON_CALL() statement a name. |
| 7856 | enum Clause { |
| 7857 | // Do not change the order of the enum members! The run-time |
| 7858 | // syntax checking relies on it. |
| 7859 | kNone, |
| 7860 | kWith, |
| 7861 | kWillByDefault |
| 7862 | }; |
| 7863 | |
| 7864 | // Asserts that the ON_CALL() statement has a certain property. |
| 7865 | void AssertSpecProperty(bool property, const string& failure_message) const { |
| 7866 | Assert(property, file_, line_, failure_message); |
| 7867 | } |
| 7868 | |
| 7869 | // Expects that the ON_CALL() statement has a certain property. |
| 7870 | void ExpectSpecProperty(bool property, const string& failure_message) const { |
| 7871 | Expect(property, file_, line_, failure_message); |
| 7872 | } |
| 7873 | |
| 7874 | const char* file_; |
| 7875 | int line_; |
| 7876 | |
| 7877 | // The last clause in the ON_CALL() statement as seen so far. |
| 7878 | // Initially kNone and changes as the statement is parsed. |
| 7879 | Clause last_clause_; |
| 7880 | }; // class UntypedOnCallSpecBase |
| 7881 | |
| 7882 | // This template class implements an ON_CALL spec. |
| 7883 | template <typename F> |
| 7884 | class OnCallSpec : public UntypedOnCallSpecBase { |
| 7885 | public: |
| 7886 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 7887 | typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; |
| 7888 | |
| 7889 | // Constructs an OnCallSpec object from the information inside |
| 7890 | // the parenthesis of an ON_CALL() statement. |
| 7891 | OnCallSpec(const char* a_file, int a_line, |
| 7892 | const ArgumentMatcherTuple& matchers) |
| 7893 | : UntypedOnCallSpecBase(a_file, a_line), |
| 7894 | matchers_(matchers), |
| 7895 | // By default, extra_matcher_ should match anything. However, |
| 7896 | // we cannot initialize it with _ as that triggers a compiler |
| 7897 | // bug in Symbian's C++ compiler (cannot decide between two |
| 7898 | // overloaded constructors of Matcher<const ArgumentTuple&>). |
| 7899 | extra_matcher_(A<const ArgumentTuple&>()) { |
| 7900 | } |
| 7901 | |
| 7902 | // Implements the .With() clause. |
| 7903 | OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) { |
| 7904 | // Makes sure this is called at most once. |
| 7905 | ExpectSpecProperty(last_clause_ < kWith, |
| 7906 | ".With() cannot appear " |
| 7907 | "more than once in an ON_CALL()."); |
| 7908 | last_clause_ = kWith; |
| 7909 | |
| 7910 | extra_matcher_ = m; |
| 7911 | return *this; |
| 7912 | } |
| 7913 | |
| 7914 | // Implements the .WillByDefault() clause. |
| 7915 | OnCallSpec& WillByDefault(const Action<F>& action) { |
| 7916 | ExpectSpecProperty(last_clause_ < kWillByDefault, |
| 7917 | ".WillByDefault() must appear " |
| 7918 | "exactly once in an ON_CALL()."); |
| 7919 | last_clause_ = kWillByDefault; |
| 7920 | |
| 7921 | ExpectSpecProperty(!action.IsDoDefault(), |
| 7922 | "DoDefault() cannot be used in ON_CALL()."); |
| 7923 | action_ = action; |
| 7924 | return *this; |
| 7925 | } |
| 7926 | |
| 7927 | // Returns true iff the given arguments match the matchers. |
| 7928 | bool Matches(const ArgumentTuple& args) const { |
| 7929 | return TupleMatches(matchers_, args) && extra_matcher_.Matches(args); |
| 7930 | } |
| 7931 | |
| 7932 | // Returns the action specified by the user. |
| 7933 | const Action<F>& GetAction() const { |
| 7934 | AssertSpecProperty(last_clause_ == kWillByDefault, |
| 7935 | ".WillByDefault() must appear exactly " |
| 7936 | "once in an ON_CALL()."); |
| 7937 | return action_; |
| 7938 | } |
| 7939 | |
| 7940 | private: |
| 7941 | // The information in statement |
| 7942 | // |
| 7943 | // ON_CALL(mock_object, Method(matchers)) |
| 7944 | // .With(multi-argument-matcher) |
| 7945 | // .WillByDefault(action); |
| 7946 | // |
| 7947 | // is recorded in the data members like this: |
| 7948 | // |
| 7949 | // source file that contains the statement => file_ |
| 7950 | // line number of the statement => line_ |
| 7951 | // matchers => matchers_ |
| 7952 | // multi-argument-matcher => extra_matcher_ |
| 7953 | // action => action_ |
| 7954 | ArgumentMatcherTuple matchers_; |
| 7955 | Matcher<const ArgumentTuple&> extra_matcher_; |
| 7956 | Action<F> action_; |
| 7957 | }; // class OnCallSpec |
| 7958 | |
| 7959 | // Possible reactions on uninteresting calls. TODO(wan@google.com): |
| 7960 | // rename the enum values to the kFoo style. |
| 7961 | enum CallReaction { |
| 7962 | ALLOW, |
| 7963 | WARN, |
| 7964 | FAIL |
| 7965 | }; |
| 7966 | |
| 7967 | } // namespace internal |
| 7968 | |
| 7969 | // Utilities for manipulating mock objects. |
| 7970 | class Mock { |
| 7971 | public: |
| 7972 | // The following public methods can be called concurrently. |
| 7973 | |
| 7974 | // Tells Google Mock to ignore mock_obj when checking for leaked |
| 7975 | // mock objects. |
| 7976 | static void AllowLeak(const void* mock_obj); |
| 7977 | |
| 7978 | // Verifies and clears all expectations on the given mock object. |
| 7979 | // If the expectations aren't satisfied, generates one or more |
| 7980 | // Google Test non-fatal failures and returns false. |
| 7981 | static bool VerifyAndClearExpectations(void* mock_obj); |
| 7982 | |
| 7983 | // Verifies all expectations on the given mock object and clears its |
| 7984 | // default actions and expectations. Returns true iff the |
| 7985 | // verification was successful. |
| 7986 | static bool VerifyAndClear(void* mock_obj); |
| 7987 | private: |
| 7988 | friend class internal::UntypedFunctionMockerBase; |
| 7989 | |
| 7990 | // Needed for a function mocker to register itself (so that we know |
| 7991 | // how to clear a mock object). |
| 7992 | template <typename F> |
| 7993 | friend class internal::FunctionMockerBase; |
| 7994 | |
| 7995 | template <typename M> |
| 7996 | friend class NiceMock; |
| 7997 | |
| 7998 | template <typename M> |
| 7999 | friend class StrictMock; |
| 8000 | |
| 8001 | // Tells Google Mock to allow uninteresting calls on the given mock |
| 8002 | // object. |
| 8003 | // L < g_gmock_mutex |
| 8004 | static void AllowUninterestingCalls(const void* mock_obj); |
| 8005 | |
| 8006 | // Tells Google Mock to warn the user about uninteresting calls on |
| 8007 | // the given mock object. |
| 8008 | // L < g_gmock_mutex |
| 8009 | static void WarnUninterestingCalls(const void* mock_obj); |
| 8010 | |
| 8011 | // Tells Google Mock to fail uninteresting calls on the given mock |
| 8012 | // object. |
| 8013 | // L < g_gmock_mutex |
| 8014 | static void FailUninterestingCalls(const void* mock_obj); |
| 8015 | |
| 8016 | // Tells Google Mock the given mock object is being destroyed and |
| 8017 | // its entry in the call-reaction table should be removed. |
| 8018 | // L < g_gmock_mutex |
| 8019 | static void UnregisterCallReaction(const void* mock_obj); |
| 8020 | |
| 8021 | // Returns the reaction Google Mock will have on uninteresting calls |
| 8022 | // made on the given mock object. |
| 8023 | // L < g_gmock_mutex |
| 8024 | static internal::CallReaction GetReactionOnUninterestingCalls( |
| 8025 | const void* mock_obj); |
| 8026 | |
| 8027 | // Verifies that all expectations on the given mock object have been |
| 8028 | // satisfied. Reports one or more Google Test non-fatal failures |
| 8029 | // and returns false if not. |
| 8030 | // L >= g_gmock_mutex |
| 8031 | static bool VerifyAndClearExpectationsLocked(void* mock_obj); |
| 8032 | |
| 8033 | // Clears all ON_CALL()s set on the given mock object. |
| 8034 | // L >= g_gmock_mutex |
| 8035 | static void ClearDefaultActionsLocked(void* mock_obj); |
| 8036 | |
| 8037 | // Registers a mock object and a mock method it owns. |
| 8038 | // L < g_gmock_mutex |
| 8039 | static void Register(const void* mock_obj, |
| 8040 | internal::UntypedFunctionMockerBase* mocker); |
| 8041 | |
| 8042 | // Tells Google Mock where in the source code mock_obj is used in an |
| 8043 | // ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this |
| 8044 | // information helps the user identify which object it is. |
| 8045 | // L < g_gmock_mutex |
| 8046 | static void RegisterUseByOnCallOrExpectCall( |
| 8047 | const void* mock_obj, const char* file, int line); |
| 8048 | |
| 8049 | // Unregisters a mock method; removes the owning mock object from |
| 8050 | // the registry when the last mock method associated with it has |
| 8051 | // been unregistered. This is called only in the destructor of |
| 8052 | // FunctionMockerBase. |
| 8053 | // L >= g_gmock_mutex |
| 8054 | static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker); |
| 8055 | }; // class Mock |
| 8056 | |
| 8057 | // An abstract handle of an expectation. Useful in the .After() |
| 8058 | // clause of EXPECT_CALL() for setting the (partial) order of |
| 8059 | // expectations. The syntax: |
| 8060 | // |
| 8061 | // Expectation e1 = EXPECT_CALL(...)...; |
| 8062 | // EXPECT_CALL(...).After(e1)...; |
| 8063 | // |
| 8064 | // sets two expectations where the latter can only be matched after |
| 8065 | // the former has been satisfied. |
| 8066 | // |
| 8067 | // Notes: |
| 8068 | // - This class is copyable and has value semantics. |
| 8069 | // - Constness is shallow: a const Expectation object itself cannot |
| 8070 | // be modified, but the mutable methods of the ExpectationBase |
| 8071 | // object it references can be called via expectation_base(). |
| 8072 | // - The constructors and destructor are defined out-of-line because |
| 8073 | // the Symbian WINSCW compiler wants to otherwise instantiate them |
| 8074 | // when it sees this class definition, at which point it doesn't have |
| 8075 | // ExpectationBase available yet, leading to incorrect destruction |
| 8076 | // in the linked_ptr (or compilation errors if using a checking |
| 8077 | // linked_ptr). |
| 8078 | class Expectation { |
| 8079 | public: |
| 8080 | // Constructs a null object that doesn't reference any expectation. |
| 8081 | Expectation(); |
| 8082 | |
| 8083 | ~Expectation(); |
| 8084 | |
| 8085 | // This single-argument ctor must not be explicit, in order to support the |
| 8086 | // Expectation e = EXPECT_CALL(...); |
| 8087 | // syntax. |
| 8088 | // |
| 8089 | // A TypedExpectation object stores its pre-requisites as |
| 8090 | // Expectation objects, and needs to call the non-const Retire() |
| 8091 | // method on the ExpectationBase objects they reference. Therefore |
| 8092 | // Expectation must receive a *non-const* reference to the |
| 8093 | // ExpectationBase object. |
| 8094 | Expectation(internal::ExpectationBase& exp); // NOLINT |
| 8095 | |
| 8096 | // The compiler-generated copy ctor and operator= work exactly as |
| 8097 | // intended, so we don't need to define our own. |
| 8098 | |
| 8099 | // Returns true iff rhs references the same expectation as this object does. |
| 8100 | bool operator==(const Expectation& rhs) const { |
| 8101 | return expectation_base_ == rhs.expectation_base_; |
| 8102 | } |
| 8103 | |
| 8104 | bool operator!=(const Expectation& rhs) const { return !(*this == rhs); } |
| 8105 | |
| 8106 | private: |
| 8107 | friend class ExpectationSet; |
| 8108 | friend class Sequence; |
| 8109 | friend class ::testing::internal::ExpectationBase; |
| 8110 | friend class ::testing::internal::UntypedFunctionMockerBase; |
| 8111 | |
| 8112 | template <typename F> |
| 8113 | friend class ::testing::internal::FunctionMockerBase; |
| 8114 | |
| 8115 | template <typename F> |
| 8116 | friend class ::testing::internal::TypedExpectation; |
| 8117 | |
| 8118 | // This comparator is needed for putting Expectation objects into a set. |
| 8119 | class Less { |
| 8120 | public: |
| 8121 | bool operator()(const Expectation& lhs, const Expectation& rhs) const { |
| 8122 | return lhs.expectation_base_.get() < rhs.expectation_base_.get(); |
| 8123 | } |
| 8124 | }; |
| 8125 | |
| 8126 | typedef ::std::set<Expectation, Less> Set; |
| 8127 | |
| 8128 | Expectation( |
| 8129 | const internal::linked_ptr<internal::ExpectationBase>& expectation_base); |
| 8130 | |
| 8131 | // Returns the expectation this object references. |
| 8132 | const internal::linked_ptr<internal::ExpectationBase>& |
| 8133 | expectation_base() const { |
| 8134 | return expectation_base_; |
| 8135 | } |
| 8136 | |
| 8137 | // A linked_ptr that co-owns the expectation this handle references. |
| 8138 | internal::linked_ptr<internal::ExpectationBase> expectation_base_; |
| 8139 | }; |
| 8140 | |
| 8141 | // A set of expectation handles. Useful in the .After() clause of |
| 8142 | // EXPECT_CALL() for setting the (partial) order of expectations. The |
| 8143 | // syntax: |
| 8144 | // |
| 8145 | // ExpectationSet es; |
| 8146 | // es += EXPECT_CALL(...)...; |
| 8147 | // es += EXPECT_CALL(...)...; |
| 8148 | // EXPECT_CALL(...).After(es)...; |
| 8149 | // |
| 8150 | // sets three expectations where the last one can only be matched |
| 8151 | // after the first two have both been satisfied. |
| 8152 | // |
| 8153 | // This class is copyable and has value semantics. |
| 8154 | class ExpectationSet { |
| 8155 | public: |
| 8156 | // A bidirectional iterator that can read a const element in the set. |
| 8157 | typedef Expectation::Set::const_iterator const_iterator; |
| 8158 | |
| 8159 | // An object stored in the set. This is an alias of Expectation. |
| 8160 | typedef Expectation::Set::value_type value_type; |
| 8161 | |
| 8162 | // Constructs an empty set. |
| 8163 | ExpectationSet() {} |
| 8164 | |
| 8165 | // This single-argument ctor must not be explicit, in order to support the |
| 8166 | // ExpectationSet es = EXPECT_CALL(...); |
| 8167 | // syntax. |
| 8168 | ExpectationSet(internal::ExpectationBase& exp) { // NOLINT |
| 8169 | *this += Expectation(exp); |
| 8170 | } |
| 8171 | |
| 8172 | // This single-argument ctor implements implicit conversion from |
| 8173 | // Expectation and thus must not be explicit. This allows either an |
| 8174 | // Expectation or an ExpectationSet to be used in .After(). |
| 8175 | ExpectationSet(const Expectation& e) { // NOLINT |
| 8176 | *this += e; |
| 8177 | } |
| 8178 | |
| 8179 | // The compiler-generator ctor and operator= works exactly as |
| 8180 | // intended, so we don't need to define our own. |
| 8181 | |
| 8182 | // Returns true iff rhs contains the same set of Expectation objects |
| 8183 | // as this does. |
| 8184 | bool operator==(const ExpectationSet& rhs) const { |
| 8185 | return expectations_ == rhs.expectations_; |
| 8186 | } |
| 8187 | |
| 8188 | bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); } |
| 8189 | |
| 8190 | // Implements the syntax |
| 8191 | // expectation_set += EXPECT_CALL(...); |
| 8192 | ExpectationSet& operator+=(const Expectation& e) { |
| 8193 | expectations_.insert(e); |
| 8194 | return *this; |
| 8195 | } |
| 8196 | |
| 8197 | int size() const { return static_cast<int>(expectations_.size()); } |
| 8198 | |
| 8199 | const_iterator begin() const { return expectations_.begin(); } |
| 8200 | const_iterator end() const { return expectations_.end(); } |
| 8201 | |
| 8202 | private: |
| 8203 | Expectation::Set expectations_; |
| 8204 | }; |
| 8205 | |
| 8206 | |
| 8207 | // Sequence objects are used by a user to specify the relative order |
| 8208 | // in which the expectations should match. They are copyable (we rely |
| 8209 | // on the compiler-defined copy constructor and assignment operator). |
| 8210 | class Sequence { |
| 8211 | public: |
| 8212 | // Constructs an empty sequence. |
| 8213 | Sequence() : last_expectation_(new Expectation) {} |
| 8214 | |
| 8215 | // Adds an expectation to this sequence. The caller must ensure |
| 8216 | // that no other thread is accessing this Sequence object. |
| 8217 | void AddExpectation(const Expectation& expectation) const; |
| 8218 | |
| 8219 | private: |
| 8220 | // The last expectation in this sequence. We use a linked_ptr here |
| 8221 | // because Sequence objects are copyable and we want the copies to |
| 8222 | // be aliases. The linked_ptr allows the copies to co-own and share |
| 8223 | // the same Expectation object. |
| 8224 | internal::linked_ptr<Expectation> last_expectation_; |
| 8225 | }; // class Sequence |
| 8226 | |
| 8227 | // An object of this type causes all EXPECT_CALL() statements |
| 8228 | // encountered in its scope to be put in an anonymous sequence. The |
| 8229 | // work is done in the constructor and destructor. You should only |
| 8230 | // create an InSequence object on the stack. |
| 8231 | // |
| 8232 | // The sole purpose for this class is to support easy definition of |
| 8233 | // sequential expectations, e.g. |
| 8234 | // |
| 8235 | // { |
| 8236 | // InSequence dummy; // The name of the object doesn't matter. |
| 8237 | // |
| 8238 | // // The following expectations must match in the order they appear. |
| 8239 | // EXPECT_CALL(a, Bar())...; |
| 8240 | // EXPECT_CALL(a, Baz())...; |
| 8241 | // ... |
| 8242 | // EXPECT_CALL(b, Xyz())...; |
| 8243 | // } |
| 8244 | // |
| 8245 | // You can create InSequence objects in multiple threads, as long as |
| 8246 | // they are used to affect different mock objects. The idea is that |
| 8247 | // each thread can create and set up its own mocks as if it's the only |
| 8248 | // thread. However, for clarity of your tests we recommend you to set |
| 8249 | // up mocks in the main thread unless you have a good reason not to do |
| 8250 | // so. |
| 8251 | class InSequence { |
| 8252 | public: |
| 8253 | InSequence(); |
| 8254 | ~InSequence(); |
| 8255 | private: |
| 8256 | bool sequence_created_; |
| 8257 | |
| 8258 | GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT |
| 8259 | } GTEST_ATTRIBUTE_UNUSED_; |
| 8260 | |
| 8261 | namespace internal { |
| 8262 | |
| 8263 | // Points to the implicit sequence introduced by a living InSequence |
| 8264 | // object (if any) in the current thread or NULL. |
| 8265 | extern ThreadLocal<Sequence*> g_gmock_implicit_sequence; |
| 8266 | |
| 8267 | // Base class for implementing expectations. |
| 8268 | // |
| 8269 | // There are two reasons for having a type-agnostic base class for |
| 8270 | // Expectation: |
| 8271 | // |
| 8272 | // 1. We need to store collections of expectations of different |
| 8273 | // types (e.g. all pre-requisites of a particular expectation, all |
| 8274 | // expectations in a sequence). Therefore these expectation objects |
| 8275 | // must share a common base class. |
| 8276 | // |
| 8277 | // 2. We can avoid binary code bloat by moving methods not depending |
| 8278 | // on the template argument of Expectation to the base class. |
| 8279 | // |
| 8280 | // This class is internal and mustn't be used by user code directly. |
| 8281 | class ExpectationBase { |
| 8282 | public: |
| 8283 | // source_text is the EXPECT_CALL(...) source that created this Expectation. |
| 8284 | ExpectationBase(const char* file, int line, const string& source_text); |
| 8285 | |
| 8286 | virtual ~ExpectationBase(); |
| 8287 | |
| 8288 | // Where in the source file was the expectation spec defined? |
| 8289 | const char* file() const { return file_; } |
| 8290 | int line() const { return line_; } |
| 8291 | const char* source_text() const { return source_text_.c_str(); } |
| 8292 | // Returns the cardinality specified in the expectation spec. |
| 8293 | const Cardinality& cardinality() const { return cardinality_; } |
| 8294 | |
| 8295 | // Describes the source file location of this expectation. |
| 8296 | void DescribeLocationTo(::std::ostream* os) const { |
| 8297 | *os << FormatFileLocation(file(), line()) << " "; |
| 8298 | } |
| 8299 | |
| 8300 | // Describes how many times a function call matching this |
| 8301 | // expectation has occurred. |
| 8302 | // L >= g_gmock_mutex |
| 8303 | void DescribeCallCountTo(::std::ostream* os) const; |
| 8304 | |
| 8305 | // If this mock method has an extra matcher (i.e. .With(matcher)), |
| 8306 | // describes it to the ostream. |
| 8307 | virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0; |
| 8308 | |
| 8309 | protected: |
| 8310 | friend class ::testing::Expectation; |
| 8311 | friend class UntypedFunctionMockerBase; |
| 8312 | |
| 8313 | enum Clause { |
| 8314 | // Don't change the order of the enum members! |
| 8315 | kNone, |
| 8316 | kWith, |
| 8317 | kTimes, |
| 8318 | kInSequence, |
| 8319 | kAfter, |
| 8320 | kWillOnce, |
| 8321 | kWillRepeatedly, |
| 8322 | kRetiresOnSaturation |
| 8323 | }; |
| 8324 | |
| 8325 | typedef std::vector<const void*> UntypedActions; |
| 8326 | |
| 8327 | // Returns an Expectation object that references and co-owns this |
| 8328 | // expectation. |
| 8329 | virtual Expectation GetHandle() = 0; |
| 8330 | |
| 8331 | // Asserts that the EXPECT_CALL() statement has the given property. |
| 8332 | void AssertSpecProperty(bool property, const string& failure_message) const { |
| 8333 | Assert(property, file_, line_, failure_message); |
| 8334 | } |
| 8335 | |
| 8336 | // Expects that the EXPECT_CALL() statement has the given property. |
| 8337 | void ExpectSpecProperty(bool property, const string& failure_message) const { |
| 8338 | Expect(property, file_, line_, failure_message); |
| 8339 | } |
| 8340 | |
| 8341 | // Explicitly specifies the cardinality of this expectation. Used |
| 8342 | // by the subclasses to implement the .Times() clause. |
| 8343 | void SpecifyCardinality(const Cardinality& cardinality); |
| 8344 | |
| 8345 | // Returns true iff the user specified the cardinality explicitly |
| 8346 | // using a .Times(). |
| 8347 | bool cardinality_specified() const { return cardinality_specified_; } |
| 8348 | |
| 8349 | // Sets the cardinality of this expectation spec. |
| 8350 | void set_cardinality(const Cardinality& a_cardinality) { |
| 8351 | cardinality_ = a_cardinality; |
| 8352 | } |
| 8353 | |
| 8354 | // The following group of methods should only be called after the |
| 8355 | // EXPECT_CALL() statement, and only when g_gmock_mutex is held by |
| 8356 | // the current thread. |
| 8357 | |
| 8358 | // Retires all pre-requisites of this expectation. |
| 8359 | // L >= g_gmock_mutex |
| 8360 | void RetireAllPreRequisites(); |
| 8361 | |
| 8362 | // Returns true iff this expectation is retired. |
| 8363 | // L >= g_gmock_mutex |
| 8364 | bool is_retired() const { |
| 8365 | g_gmock_mutex.AssertHeld(); |
| 8366 | return retired_; |
| 8367 | } |
| 8368 | |
| 8369 | // Retires this expectation. |
| 8370 | // L >= g_gmock_mutex |
| 8371 | void Retire() { |
| 8372 | g_gmock_mutex.AssertHeld(); |
| 8373 | retired_ = true; |
| 8374 | } |
| 8375 | |
| 8376 | // Returns true iff this expectation is satisfied. |
| 8377 | // L >= g_gmock_mutex |
| 8378 | bool IsSatisfied() const { |
| 8379 | g_gmock_mutex.AssertHeld(); |
| 8380 | return cardinality().IsSatisfiedByCallCount(call_count_); |
| 8381 | } |
| 8382 | |
| 8383 | // Returns true iff this expectation is saturated. |
| 8384 | // L >= g_gmock_mutex |
| 8385 | bool IsSaturated() const { |
| 8386 | g_gmock_mutex.AssertHeld(); |
| 8387 | return cardinality().IsSaturatedByCallCount(call_count_); |
| 8388 | } |
| 8389 | |
| 8390 | // Returns true iff this expectation is over-saturated. |
| 8391 | // L >= g_gmock_mutex |
| 8392 | bool IsOverSaturated() const { |
| 8393 | g_gmock_mutex.AssertHeld(); |
| 8394 | return cardinality().IsOverSaturatedByCallCount(call_count_); |
| 8395 | } |
| 8396 | |
| 8397 | // Returns true iff all pre-requisites of this expectation are satisfied. |
| 8398 | // L >= g_gmock_mutex |
| 8399 | bool AllPrerequisitesAreSatisfied() const; |
| 8400 | |
| 8401 | // Adds unsatisfied pre-requisites of this expectation to 'result'. |
| 8402 | // L >= g_gmock_mutex |
| 8403 | void FindUnsatisfiedPrerequisites(ExpectationSet* result) const; |
| 8404 | |
| 8405 | // Returns the number this expectation has been invoked. |
| 8406 | // L >= g_gmock_mutex |
| 8407 | int call_count() const { |
| 8408 | g_gmock_mutex.AssertHeld(); |
| 8409 | return call_count_; |
| 8410 | } |
| 8411 | |
| 8412 | // Increments the number this expectation has been invoked. |
| 8413 | // L >= g_gmock_mutex |
| 8414 | void IncrementCallCount() { |
| 8415 | g_gmock_mutex.AssertHeld(); |
| 8416 | call_count_++; |
| 8417 | } |
| 8418 | |
| 8419 | // Checks the action count (i.e. the number of WillOnce() and |
| 8420 | // WillRepeatedly() clauses) against the cardinality if this hasn't |
| 8421 | // been done before. Prints a warning if there are too many or too |
| 8422 | // few actions. |
| 8423 | // L < mutex_ |
| 8424 | void CheckActionCountIfNotDone() const; |
| 8425 | |
| 8426 | friend class ::testing::Sequence; |
| 8427 | friend class ::testing::internal::ExpectationTester; |
| 8428 | |
| 8429 | template <typename Function> |
| 8430 | friend class TypedExpectation; |
| 8431 | |
| 8432 | // Implements the .Times() clause. |
| 8433 | void UntypedTimes(const Cardinality& a_cardinality); |
| 8434 | |
| 8435 | // This group of fields are part of the spec and won't change after |
| 8436 | // an EXPECT_CALL() statement finishes. |
| 8437 | const char* file_; // The file that contains the expectation. |
| 8438 | int line_; // The line number of the expectation. |
| 8439 | const string source_text_; // The EXPECT_CALL(...) source text. |
| 8440 | // True iff the cardinality is specified explicitly. |
| 8441 | bool cardinality_specified_; |
| 8442 | Cardinality cardinality_; // The cardinality of the expectation. |
| 8443 | // The immediate pre-requisites (i.e. expectations that must be |
| 8444 | // satisfied before this expectation can be matched) of this |
| 8445 | // expectation. We use linked_ptr in the set because we want an |
| 8446 | // Expectation object to be co-owned by its FunctionMocker and its |
| 8447 | // successors. This allows multiple mock objects to be deleted at |
| 8448 | // different times. |
| 8449 | ExpectationSet immediate_prerequisites_; |
| 8450 | |
| 8451 | // This group of fields are the current state of the expectation, |
| 8452 | // and can change as the mock function is called. |
| 8453 | int call_count_; // How many times this expectation has been invoked. |
| 8454 | bool retired_; // True iff this expectation has retired. |
| 8455 | UntypedActions untyped_actions_; |
| 8456 | bool extra_matcher_specified_; |
| 8457 | bool repeated_action_specified_; // True if a WillRepeatedly() was specified. |
| 8458 | bool retires_on_saturation_; |
| 8459 | Clause last_clause_; |
| 8460 | mutable bool action_count_checked_; // Under mutex_. |
| 8461 | mutable Mutex mutex_; // Protects action_count_checked_. |
| 8462 | |
| 8463 | GTEST_DISALLOW_ASSIGN_(ExpectationBase); |
| 8464 | }; // class ExpectationBase |
| 8465 | |
| 8466 | // Impements an expectation for the given function type. |
| 8467 | template <typename F> |
| 8468 | class TypedExpectation : public ExpectationBase { |
| 8469 | public: |
| 8470 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 8471 | typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; |
| 8472 | typedef typename Function<F>::Result Result; |
| 8473 | |
| 8474 | TypedExpectation(FunctionMockerBase<F>* owner, |
| 8475 | const char* a_file, int a_line, const string& a_source_text, |
| 8476 | const ArgumentMatcherTuple& m) |
| 8477 | : ExpectationBase(a_file, a_line, a_source_text), |
| 8478 | owner_(owner), |
| 8479 | matchers_(m), |
| 8480 | // By default, extra_matcher_ should match anything. However, |
| 8481 | // we cannot initialize it with _ as that triggers a compiler |
| 8482 | // bug in Symbian's C++ compiler (cannot decide between two |
| 8483 | // overloaded constructors of Matcher<const ArgumentTuple&>). |
| 8484 | extra_matcher_(A<const ArgumentTuple&>()), |
| 8485 | repeated_action_(DoDefault()) {} |
| 8486 | |
| 8487 | virtual ~TypedExpectation() { |
| 8488 | // Check the validity of the action count if it hasn't been done |
| 8489 | // yet (for example, if the expectation was never used). |
| 8490 | CheckActionCountIfNotDone(); |
| 8491 | for (UntypedActions::const_iterator it = untyped_actions_.begin(); |
| 8492 | it != untyped_actions_.end(); ++it) { |
| 8493 | delete static_cast<const Action<F>*>(*it); |
| 8494 | } |
| 8495 | } |
| 8496 | |
| 8497 | // Implements the .With() clause. |
| 8498 | TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) { |
| 8499 | if (last_clause_ == kWith) { |
| 8500 | ExpectSpecProperty(false, |
| 8501 | ".With() cannot appear " |
| 8502 | "more than once in an EXPECT_CALL()."); |
| 8503 | } else { |
| 8504 | ExpectSpecProperty(last_clause_ < kWith, |
| 8505 | ".With() must be the first " |
| 8506 | "clause in an EXPECT_CALL()."); |
| 8507 | } |
| 8508 | last_clause_ = kWith; |
| 8509 | |
| 8510 | extra_matcher_ = m; |
| 8511 | extra_matcher_specified_ = true; |
| 8512 | return *this; |
| 8513 | } |
| 8514 | |
| 8515 | // Implements the .Times() clause. |
| 8516 | TypedExpectation& Times(const Cardinality& a_cardinality) { |
| 8517 | ExpectationBase::UntypedTimes(a_cardinality); |
| 8518 | return *this; |
| 8519 | } |
| 8520 | |
| 8521 | // Implements the .Times() clause. |
| 8522 | TypedExpectation& Times(int n) { |
| 8523 | return Times(Exactly(n)); |
| 8524 | } |
| 8525 | |
| 8526 | // Implements the .InSequence() clause. |
| 8527 | TypedExpectation& InSequence(const Sequence& s) { |
| 8528 | ExpectSpecProperty(last_clause_ <= kInSequence, |
| 8529 | ".InSequence() cannot appear after .After()," |
| 8530 | " .WillOnce(), .WillRepeatedly(), or " |
| 8531 | ".RetiresOnSaturation()."); |
| 8532 | last_clause_ = kInSequence; |
| 8533 | |
| 8534 | s.AddExpectation(GetHandle()); |
| 8535 | return *this; |
| 8536 | } |
| 8537 | TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) { |
| 8538 | return InSequence(s1).InSequence(s2); |
| 8539 | } |
| 8540 | TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, |
| 8541 | const Sequence& s3) { |
| 8542 | return InSequence(s1, s2).InSequence(s3); |
| 8543 | } |
| 8544 | TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, |
| 8545 | const Sequence& s3, const Sequence& s4) { |
| 8546 | return InSequence(s1, s2, s3).InSequence(s4); |
| 8547 | } |
| 8548 | TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, |
| 8549 | const Sequence& s3, const Sequence& s4, |
| 8550 | const Sequence& s5) { |
| 8551 | return InSequence(s1, s2, s3, s4).InSequence(s5); |
| 8552 | } |
| 8553 | |
| 8554 | // Implements that .After() clause. |
| 8555 | TypedExpectation& After(const ExpectationSet& s) { |
| 8556 | ExpectSpecProperty(last_clause_ <= kAfter, |
| 8557 | ".After() cannot appear after .WillOnce()," |
| 8558 | " .WillRepeatedly(), or " |
| 8559 | ".RetiresOnSaturation()."); |
| 8560 | last_clause_ = kAfter; |
| 8561 | |
| 8562 | for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) { |
| 8563 | immediate_prerequisites_ += *it; |
| 8564 | } |
| 8565 | return *this; |
| 8566 | } |
| 8567 | TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) { |
| 8568 | return After(s1).After(s2); |
| 8569 | } |
| 8570 | TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, |
| 8571 | const ExpectationSet& s3) { |
| 8572 | return After(s1, s2).After(s3); |
| 8573 | } |
| 8574 | TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, |
| 8575 | const ExpectationSet& s3, const ExpectationSet& s4) { |
| 8576 | return After(s1, s2, s3).After(s4); |
| 8577 | } |
| 8578 | TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, |
| 8579 | const ExpectationSet& s3, const ExpectationSet& s4, |
| 8580 | const ExpectationSet& s5) { |
| 8581 | return After(s1, s2, s3, s4).After(s5); |
| 8582 | } |
| 8583 | |
| 8584 | // Implements the .WillOnce() clause. |
| 8585 | TypedExpectation& WillOnce(const Action<F>& action) { |
| 8586 | ExpectSpecProperty(last_clause_ <= kWillOnce, |
| 8587 | ".WillOnce() cannot appear after " |
| 8588 | ".WillRepeatedly() or .RetiresOnSaturation()."); |
| 8589 | last_clause_ = kWillOnce; |
| 8590 | |
| 8591 | untyped_actions_.push_back(new Action<F>(action)); |
| 8592 | if (!cardinality_specified()) { |
| 8593 | set_cardinality(Exactly(static_cast<int>(untyped_actions_.size()))); |
| 8594 | } |
| 8595 | return *this; |
| 8596 | } |
| 8597 | |
| 8598 | // Implements the .WillRepeatedly() clause. |
| 8599 | TypedExpectation& WillRepeatedly(const Action<F>& action) { |
| 8600 | if (last_clause_ == kWillRepeatedly) { |
| 8601 | ExpectSpecProperty(false, |
| 8602 | ".WillRepeatedly() cannot appear " |
| 8603 | "more than once in an EXPECT_CALL()."); |
| 8604 | } else { |
| 8605 | ExpectSpecProperty(last_clause_ < kWillRepeatedly, |
| 8606 | ".WillRepeatedly() cannot appear " |
| 8607 | "after .RetiresOnSaturation()."); |
| 8608 | } |
| 8609 | last_clause_ = kWillRepeatedly; |
| 8610 | repeated_action_specified_ = true; |
| 8611 | |
| 8612 | repeated_action_ = action; |
| 8613 | if (!cardinality_specified()) { |
| 8614 | set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size()))); |
| 8615 | } |
| 8616 | |
| 8617 | // Now that no more action clauses can be specified, we check |
| 8618 | // whether their count makes sense. |
| 8619 | CheckActionCountIfNotDone(); |
| 8620 | return *this; |
| 8621 | } |
| 8622 | |
| 8623 | // Implements the .RetiresOnSaturation() clause. |
| 8624 | TypedExpectation& RetiresOnSaturation() { |
| 8625 | ExpectSpecProperty(last_clause_ < kRetiresOnSaturation, |
| 8626 | ".RetiresOnSaturation() cannot appear " |
| 8627 | "more than once."); |
| 8628 | last_clause_ = kRetiresOnSaturation; |
| 8629 | retires_on_saturation_ = true; |
| 8630 | |
| 8631 | // Now that no more action clauses can be specified, we check |
| 8632 | // whether their count makes sense. |
| 8633 | CheckActionCountIfNotDone(); |
| 8634 | return *this; |
| 8635 | } |
| 8636 | |
| 8637 | // Returns the matchers for the arguments as specified inside the |
| 8638 | // EXPECT_CALL() macro. |
| 8639 | const ArgumentMatcherTuple& matchers() const { |
| 8640 | return matchers_; |
| 8641 | } |
| 8642 | |
| 8643 | // Returns the matcher specified by the .With() clause. |
| 8644 | const Matcher<const ArgumentTuple&>& extra_matcher() const { |
| 8645 | return extra_matcher_; |
| 8646 | } |
| 8647 | |
| 8648 | // Returns the action specified by the .WillRepeatedly() clause. |
| 8649 | const Action<F>& repeated_action() const { return repeated_action_; } |
| 8650 | |
| 8651 | // If this mock method has an extra matcher (i.e. .With(matcher)), |
| 8652 | // describes it to the ostream. |
| 8653 | virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) { |
| 8654 | if (extra_matcher_specified_) { |
| 8655 | *os << " Expected args: "; |
| 8656 | extra_matcher_.DescribeTo(os); |
| 8657 | *os << "\n"; |
| 8658 | } |
| 8659 | } |
| 8660 | |
| 8661 | private: |
| 8662 | template <typename Function> |
| 8663 | friend class FunctionMockerBase; |
| 8664 | |
| 8665 | // Returns an Expectation object that references and co-owns this |
| 8666 | // expectation. |
| 8667 | virtual Expectation GetHandle() { |
| 8668 | return owner_->GetHandleOf(this); |
| 8669 | } |
| 8670 | |
| 8671 | // The following methods will be called only after the EXPECT_CALL() |
| 8672 | // statement finishes and when the current thread holds |
| 8673 | // g_gmock_mutex. |
| 8674 | |
| 8675 | // Returns true iff this expectation matches the given arguments. |
| 8676 | // L >= g_gmock_mutex |
| 8677 | bool Matches(const ArgumentTuple& args) const { |
| 8678 | g_gmock_mutex.AssertHeld(); |
| 8679 | return TupleMatches(matchers_, args) && extra_matcher_.Matches(args); |
| 8680 | } |
| 8681 | |
| 8682 | // Returns true iff this expectation should handle the given arguments. |
| 8683 | // L >= g_gmock_mutex |
| 8684 | bool ShouldHandleArguments(const ArgumentTuple& args) const { |
| 8685 | g_gmock_mutex.AssertHeld(); |
| 8686 | |
| 8687 | // In case the action count wasn't checked when the expectation |
| 8688 | // was defined (e.g. if this expectation has no WillRepeatedly() |
| 8689 | // or RetiresOnSaturation() clause), we check it when the |
| 8690 | // expectation is used for the first time. |
| 8691 | CheckActionCountIfNotDone(); |
| 8692 | return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args); |
| 8693 | } |
| 8694 | |
| 8695 | // Describes the result of matching the arguments against this |
| 8696 | // expectation to the given ostream. |
| 8697 | // L >= g_gmock_mutex |
| 8698 | void ExplainMatchResultTo(const ArgumentTuple& args, |
| 8699 | ::std::ostream* os) const { |
| 8700 | g_gmock_mutex.AssertHeld(); |
| 8701 | |
| 8702 | if (is_retired()) { |
| 8703 | *os << " Expected: the expectation is active\n" |
| 8704 | << " Actual: it is retired\n"; |
| 8705 | } else if (!Matches(args)) { |
| 8706 | if (!TupleMatches(matchers_, args)) { |
| 8707 | ExplainMatchFailureTupleTo(matchers_, args, os); |
| 8708 | } |
| 8709 | StringMatchResultListener listener; |
| 8710 | if (!extra_matcher_.MatchAndExplain(args, &listener)) { |
| 8711 | *os << " Expected args: "; |
| 8712 | extra_matcher_.DescribeTo(os); |
| 8713 | *os << "\n Actual: don't match"; |
| 8714 | |
| 8715 | internal::PrintIfNotEmpty(listener.str(), os); |
| 8716 | *os << "\n"; |
| 8717 | } |
| 8718 | } else if (!AllPrerequisitesAreSatisfied()) { |
| 8719 | *os << " Expected: all pre-requisites are satisfied\n" |
| 8720 | << " Actual: the following immediate pre-requisites " |
| 8721 | << "are not satisfied:\n"; |
| 8722 | ExpectationSet unsatisfied_prereqs; |
| 8723 | FindUnsatisfiedPrerequisites(&unsatisfied_prereqs); |
| 8724 | int i = 0; |
| 8725 | for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin(); |
| 8726 | it != unsatisfied_prereqs.end(); ++it) { |
| 8727 | it->expectation_base()->DescribeLocationTo(os); |
| 8728 | *os << "pre-requisite #" << i++ << "\n"; |
| 8729 | } |
| 8730 | *os << " (end of pre-requisites)\n"; |
| 8731 | } else { |
| 8732 | // This line is here just for completeness' sake. It will never |
| 8733 | // be executed as currently the ExplainMatchResultTo() function |
| 8734 | // is called only when the mock function call does NOT match the |
| 8735 | // expectation. |
| 8736 | *os << "The call matches the expectation.\n"; |
| 8737 | } |
| 8738 | } |
| 8739 | |
| 8740 | // Returns the action that should be taken for the current invocation. |
| 8741 | // L >= g_gmock_mutex |
| 8742 | const Action<F>& GetCurrentAction(const FunctionMockerBase<F>* mocker, |
| 8743 | const ArgumentTuple& args) const { |
| 8744 | g_gmock_mutex.AssertHeld(); |
| 8745 | const int count = call_count(); |
| 8746 | Assert(count >= 1, __FILE__, __LINE__, |
| 8747 | "call_count() is <= 0 when GetCurrentAction() is " |
| 8748 | "called - this should never happen."); |
| 8749 | |
| 8750 | const int action_count = static_cast<int>(untyped_actions_.size()); |
| 8751 | if (action_count > 0 && !repeated_action_specified_ && |
| 8752 | count > action_count) { |
| 8753 | // If there is at least one WillOnce() and no WillRepeatedly(), |
| 8754 | // we warn the user when the WillOnce() clauses ran out. |
| 8755 | ::std::stringstream ss; |
| 8756 | DescribeLocationTo(&ss); |
| 8757 | ss << "Actions ran out in " << source_text() << "...\n" |
| 8758 | << "Called " << count << " times, but only " |
| 8759 | << action_count << " WillOnce()" |
| 8760 | << (action_count == 1 ? " is" : "s are") << " specified - "; |
| 8761 | mocker->DescribeDefaultActionTo(args, &ss); |
| 8762 | Log(WARNING, ss.str(), 1); |
| 8763 | } |
| 8764 | |
| 8765 | return count <= action_count ? |
| 8766 | *static_cast<const Action<F>*>(untyped_actions_[count - 1]) : |
| 8767 | repeated_action(); |
| 8768 | } |
| 8769 | |
| 8770 | // Given the arguments of a mock function call, if the call will |
| 8771 | // over-saturate this expectation, returns the default action; |
| 8772 | // otherwise, returns the next action in this expectation. Also |
| 8773 | // describes *what* happened to 'what', and explains *why* Google |
| 8774 | // Mock does it to 'why'. This method is not const as it calls |
| 8775 | // IncrementCallCount(). A return value of NULL means the default |
| 8776 | // action. |
| 8777 | // L >= g_gmock_mutex |
| 8778 | const Action<F>* GetActionForArguments(const FunctionMockerBase<F>* mocker, |
| 8779 | const ArgumentTuple& args, |
| 8780 | ::std::ostream* what, |
| 8781 | ::std::ostream* why) { |
| 8782 | g_gmock_mutex.AssertHeld(); |
| 8783 | if (IsSaturated()) { |
| 8784 | // We have an excessive call. |
| 8785 | IncrementCallCount(); |
| 8786 | *what << "Mock function called more times than expected - "; |
| 8787 | mocker->DescribeDefaultActionTo(args, what); |
| 8788 | DescribeCallCountTo(why); |
| 8789 | |
| 8790 | // TODO(wan@google.com): allow the user to control whether |
| 8791 | // unexpected calls should fail immediately or continue using a |
| 8792 | // flag --gmock_unexpected_calls_are_fatal. |
| 8793 | return NULL; |
| 8794 | } |
| 8795 | |
| 8796 | IncrementCallCount(); |
| 8797 | RetireAllPreRequisites(); |
| 8798 | |
| 8799 | if (retires_on_saturation_ && IsSaturated()) { |
| 8800 | Retire(); |
| 8801 | } |
| 8802 | |
| 8803 | // Must be done after IncrementCount()! |
| 8804 | *what << "Mock function call matches " << source_text() <<"...\n"; |
| 8805 | return &(GetCurrentAction(mocker, args)); |
| 8806 | } |
| 8807 | |
| 8808 | // All the fields below won't change once the EXPECT_CALL() |
| 8809 | // statement finishes. |
| 8810 | FunctionMockerBase<F>* const owner_; |
| 8811 | ArgumentMatcherTuple matchers_; |
| 8812 | Matcher<const ArgumentTuple&> extra_matcher_; |
| 8813 | Action<F> repeated_action_; |
| 8814 | |
| 8815 | GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation); |
| 8816 | }; // class TypedExpectation |
| 8817 | |
| 8818 | // A MockSpec object is used by ON_CALL() or EXPECT_CALL() for |
| 8819 | // specifying the default behavior of, or expectation on, a mock |
| 8820 | // function. |
| 8821 | |
| 8822 | // Note: class MockSpec really belongs to the ::testing namespace. |
| 8823 | // However if we define it in ::testing, MSVC will complain when |
| 8824 | // classes in ::testing::internal declare it as a friend class |
| 8825 | // template. To workaround this compiler bug, we define MockSpec in |
| 8826 | // ::testing::internal and import it into ::testing. |
| 8827 | |
| 8828 | // Logs a message including file and line number information. |
| 8829 | void LogWithLocation(testing::internal::LogSeverity severity, |
| 8830 | const char* file, int line, |
| 8831 | const string& message); |
| 8832 | |
| 8833 | template <typename F> |
| 8834 | class MockSpec { |
| 8835 | public: |
| 8836 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 8837 | typedef typename internal::Function<F>::ArgumentMatcherTuple |
| 8838 | ArgumentMatcherTuple; |
| 8839 | |
| 8840 | // Constructs a MockSpec object, given the function mocker object |
| 8841 | // that the spec is associated with. |
| 8842 | explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker) |
| 8843 | : function_mocker_(function_mocker) {} |
| 8844 | |
| 8845 | // Adds a new default action spec to the function mocker and returns |
| 8846 | // the newly created spec. |
| 8847 | internal::OnCallSpec<F>& InternalDefaultActionSetAt( |
| 8848 | const char* file, int line, const char* obj, const char* call) { |
| 8849 | LogWithLocation(internal::INFO, file, line, |
| 8850 | string("ON_CALL(") + obj + ", " + call + ") invoked"); |
| 8851 | return function_mocker_->AddNewOnCallSpec(file, line, matchers_); |
| 8852 | } |
| 8853 | |
| 8854 | // Adds a new expectation spec to the function mocker and returns |
| 8855 | // the newly created spec. |
| 8856 | internal::TypedExpectation<F>& InternalExpectedAt( |
| 8857 | const char* file, int line, const char* obj, const char* call) { |
| 8858 | const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")"); |
| 8859 | LogWithLocation(internal::INFO, file, line, source_text + " invoked"); |
| 8860 | return function_mocker_->AddNewExpectation( |
| 8861 | file, line, source_text, matchers_); |
| 8862 | } |
| 8863 | |
| 8864 | private: |
| 8865 | template <typename Function> |
| 8866 | friend class internal::FunctionMocker; |
| 8867 | |
| 8868 | void SetMatchers(const ArgumentMatcherTuple& matchers) { |
| 8869 | matchers_ = matchers; |
| 8870 | } |
| 8871 | |
| 8872 | // The function mocker that owns this spec. |
| 8873 | internal::FunctionMockerBase<F>* const function_mocker_; |
| 8874 | // The argument matchers specified in the spec. |
| 8875 | ArgumentMatcherTuple matchers_; |
| 8876 | |
| 8877 | GTEST_DISALLOW_ASSIGN_(MockSpec); |
| 8878 | }; // class MockSpec |
| 8879 | |
| 8880 | // MSVC warns about using 'this' in base member initializer list, so |
| 8881 | // we need to temporarily disable the warning. We have to do it for |
| 8882 | // the entire class to suppress the warning, even though it's about |
| 8883 | // the constructor only. |
| 8884 | |
| 8885 | #ifdef _MSC_VER |
| 8886 | # pragma warning(push) // Saves the current warning state. |
| 8887 | # pragma warning(disable:4355) // Temporarily disables warning 4355. |
| 8888 | #endif // _MSV_VER |
| 8889 | |
| 8890 | // C++ treats the void type specially. For example, you cannot define |
| 8891 | // a void-typed variable or pass a void value to a function. |
| 8892 | // ActionResultHolder<T> holds a value of type T, where T must be a |
| 8893 | // copyable type or void (T doesn't need to be default-constructable). |
| 8894 | // It hides the syntactic difference between void and other types, and |
| 8895 | // is used to unify the code for invoking both void-returning and |
| 8896 | // non-void-returning mock functions. |
| 8897 | |
| 8898 | // Untyped base class for ActionResultHolder<T>. |
| 8899 | class UntypedActionResultHolderBase { |
| 8900 | public: |
| 8901 | virtual ~UntypedActionResultHolderBase() {} |
| 8902 | |
| 8903 | // Prints the held value as an action's result to os. |
| 8904 | virtual void PrintAsActionResult(::std::ostream* os) const = 0; |
| 8905 | }; |
| 8906 | |
| 8907 | // This generic definition is used when T is not void. |
| 8908 | template <typename T> |
| 8909 | class ActionResultHolder : public UntypedActionResultHolderBase { |
| 8910 | public: |
| 8911 | explicit ActionResultHolder(T a_value) : value_(a_value) {} |
| 8912 | |
| 8913 | // The compiler-generated copy constructor and assignment operator |
| 8914 | // are exactly what we need, so we don't need to define them. |
| 8915 | |
| 8916 | // Returns the held value and deletes this object. |
| 8917 | T GetValueAndDelete() const { |
| 8918 | T retval(value_); |
| 8919 | delete this; |
| 8920 | return retval; |
| 8921 | } |
| 8922 | |
| 8923 | // Prints the held value as an action's result to os. |
| 8924 | virtual void PrintAsActionResult(::std::ostream* os) const { |
| 8925 | *os << "\n Returns: "; |
| 8926 | // T may be a reference type, so we don't use UniversalPrint(). |
| 8927 | UniversalPrinter<T>::Print(value_, os); |
| 8928 | } |
| 8929 | |
| 8930 | // Performs the given mock function's default action and returns the |
| 8931 | // result in a new-ed ActionResultHolder. |
| 8932 | template <typename F> |
| 8933 | static ActionResultHolder* PerformDefaultAction( |
| 8934 | const FunctionMockerBase<F>* func_mocker, |
| 8935 | const typename Function<F>::ArgumentTuple& args, |
| 8936 | const string& call_description) { |
| 8937 | return new ActionResultHolder( |
| 8938 | func_mocker->PerformDefaultAction(args, call_description)); |
| 8939 | } |
| 8940 | |
| 8941 | // Performs the given action and returns the result in a new-ed |
| 8942 | // ActionResultHolder. |
| 8943 | template <typename F> |
| 8944 | static ActionResultHolder* |
| 8945 | PerformAction(const Action<F>& action, |
| 8946 | const typename Function<F>::ArgumentTuple& args) { |
| 8947 | return new ActionResultHolder(action.Perform(args)); |
| 8948 | } |
| 8949 | |
| 8950 | private: |
| 8951 | T value_; |
| 8952 | |
| 8953 | // T could be a reference type, so = isn't supported. |
| 8954 | GTEST_DISALLOW_ASSIGN_(ActionResultHolder); |
| 8955 | }; |
| 8956 | |
| 8957 | // Specialization for T = void. |
| 8958 | template <> |
| 8959 | class ActionResultHolder<void> : public UntypedActionResultHolderBase { |
| 8960 | public: |
| 8961 | void GetValueAndDelete() const { delete this; } |
| 8962 | |
| 8963 | virtual void PrintAsActionResult(::std::ostream* /* os */) const {} |
| 8964 | |
| 8965 | // Performs the given mock function's default action and returns NULL; |
| 8966 | template <typename F> |
| 8967 | static ActionResultHolder* PerformDefaultAction( |
| 8968 | const FunctionMockerBase<F>* func_mocker, |
| 8969 | const typename Function<F>::ArgumentTuple& args, |
| 8970 | const string& call_description) { |
| 8971 | func_mocker->PerformDefaultAction(args, call_description); |
| 8972 | return NULL; |
| 8973 | } |
| 8974 | |
| 8975 | // Performs the given action and returns NULL. |
| 8976 | template <typename F> |
| 8977 | static ActionResultHolder* PerformAction( |
| 8978 | const Action<F>& action, |
| 8979 | const typename Function<F>::ArgumentTuple& args) { |
| 8980 | action.Perform(args); |
| 8981 | return NULL; |
| 8982 | } |
| 8983 | }; |
| 8984 | |
| 8985 | // The base of the function mocker class for the given function type. |
| 8986 | // We put the methods in this class instead of its child to avoid code |
| 8987 | // bloat. |
| 8988 | template <typename F> |
| 8989 | class FunctionMockerBase : public UntypedFunctionMockerBase { |
| 8990 | public: |
| 8991 | typedef typename Function<F>::Result Result; |
| 8992 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 8993 | typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; |
| 8994 | |
| 8995 | FunctionMockerBase() : current_spec_(this) {} |
| 8996 | |
| 8997 | // The destructor verifies that all expectations on this mock |
| 8998 | // function have been satisfied. If not, it will report Google Test |
| 8999 | // non-fatal failures for the violations. |
| 9000 | // L < g_gmock_mutex |
| 9001 | virtual ~FunctionMockerBase() { |
| 9002 | MutexLock l(&g_gmock_mutex); |
| 9003 | VerifyAndClearExpectationsLocked(); |
| 9004 | Mock::UnregisterLocked(this); |
| 9005 | ClearDefaultActionsLocked(); |
| 9006 | } |
| 9007 | |
| 9008 | // Returns the ON_CALL spec that matches this mock function with the |
| 9009 | // given arguments; returns NULL if no matching ON_CALL is found. |
| 9010 | // L = * |
| 9011 | const OnCallSpec<F>* FindOnCallSpec( |
| 9012 | const ArgumentTuple& args) const { |
| 9013 | for (UntypedOnCallSpecs::const_reverse_iterator it |
| 9014 | = untyped_on_call_specs_.rbegin(); |
| 9015 | it != untyped_on_call_specs_.rend(); ++it) { |
| 9016 | const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it); |
| 9017 | if (spec->Matches(args)) |
| 9018 | return spec; |
| 9019 | } |
| 9020 | |
| 9021 | return NULL; |
| 9022 | } |
| 9023 | |
| 9024 | // Performs the default action of this mock function on the given arguments |
| 9025 | // and returns the result. Asserts with a helpful call descrption if there is |
| 9026 | // no valid return value. This method doesn't depend on the mutable state of |
| 9027 | // this object, and thus can be called concurrently without locking. |
| 9028 | // L = * |
| 9029 | Result PerformDefaultAction(const ArgumentTuple& args, |
| 9030 | const string& call_description) const { |
| 9031 | const OnCallSpec<F>* const spec = |
| 9032 | this->FindOnCallSpec(args); |
| 9033 | if (spec != NULL) { |
| 9034 | return spec->GetAction().Perform(args); |
| 9035 | } |
| 9036 | Assert(DefaultValue<Result>::Exists(), "", -1, |
| 9037 | call_description + "\n The mock function has no default action " |
| 9038 | "set, and its return type has no default value set."); |
| 9039 | return DefaultValue<Result>::Get(); |
| 9040 | } |
| 9041 | |
| 9042 | // Performs the default action with the given arguments and returns |
| 9043 | // the action's result. The call description string will be used in |
| 9044 | // the error message to describe the call in the case the default |
| 9045 | // action fails. The caller is responsible for deleting the result. |
| 9046 | // L = * |
| 9047 | virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( |
| 9048 | const void* untyped_args, // must point to an ArgumentTuple |
| 9049 | const string& call_description) const { |
| 9050 | const ArgumentTuple& args = |
| 9051 | *static_cast<const ArgumentTuple*>(untyped_args); |
| 9052 | return ResultHolder::PerformDefaultAction(this, args, call_description); |
| 9053 | } |
| 9054 | |
| 9055 | // Performs the given action with the given arguments and returns |
| 9056 | // the action's result. The caller is responsible for deleting the |
| 9057 | // result. |
| 9058 | // L = * |
| 9059 | virtual UntypedActionResultHolderBase* UntypedPerformAction( |
| 9060 | const void* untyped_action, const void* untyped_args) const { |
| 9061 | // Make a copy of the action before performing it, in case the |
| 9062 | // action deletes the mock object (and thus deletes itself). |
| 9063 | const Action<F> action = *static_cast<const Action<F>*>(untyped_action); |
| 9064 | const ArgumentTuple& args = |
| 9065 | *static_cast<const ArgumentTuple*>(untyped_args); |
| 9066 | return ResultHolder::PerformAction(action, args); |
| 9067 | } |
| 9068 | |
| 9069 | // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked(): |
| 9070 | // clears the ON_CALL()s set on this mock function. |
| 9071 | // L >= g_gmock_mutex |
| 9072 | virtual void ClearDefaultActionsLocked() { |
| 9073 | g_gmock_mutex.AssertHeld(); |
| 9074 | for (UntypedOnCallSpecs::const_iterator it = |
| 9075 | untyped_on_call_specs_.begin(); |
| 9076 | it != untyped_on_call_specs_.end(); ++it) { |
| 9077 | delete static_cast<const OnCallSpec<F>*>(*it); |
| 9078 | } |
| 9079 | untyped_on_call_specs_.clear(); |
| 9080 | } |
| 9081 | |
| 9082 | protected: |
| 9083 | template <typename Function> |
| 9084 | friend class MockSpec; |
| 9085 | |
| 9086 | typedef ActionResultHolder<Result> ResultHolder; |
| 9087 | |
| 9088 | // Returns the result of invoking this mock function with the given |
| 9089 | // arguments. This function can be safely called from multiple |
| 9090 | // threads concurrently. |
| 9091 | // L < g_gmock_mutex |
| 9092 | Result InvokeWith(const ArgumentTuple& args) { |
| 9093 | return static_cast<const ResultHolder*>( |
| 9094 | this->UntypedInvokeWith(&args))->GetValueAndDelete(); |
| 9095 | } |
| 9096 | |
| 9097 | // Adds and returns a default action spec for this mock function. |
| 9098 | // L < g_gmock_mutex |
| 9099 | OnCallSpec<F>& AddNewOnCallSpec( |
| 9100 | const char* file, int line, |
| 9101 | const ArgumentMatcherTuple& m) { |
| 9102 | Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); |
| 9103 | OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m); |
| 9104 | untyped_on_call_specs_.push_back(on_call_spec); |
| 9105 | return *on_call_spec; |
| 9106 | } |
| 9107 | |
| 9108 | // Adds and returns an expectation spec for this mock function. |
| 9109 | // L < g_gmock_mutex |
| 9110 | TypedExpectation<F>& AddNewExpectation( |
| 9111 | const char* file, |
| 9112 | int line, |
| 9113 | const string& source_text, |
| 9114 | const ArgumentMatcherTuple& m) { |
| 9115 | Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); |
| 9116 | TypedExpectation<F>* const expectation = |
| 9117 | new TypedExpectation<F>(this, file, line, source_text, m); |
| 9118 | const linked_ptr<ExpectationBase> untyped_expectation(expectation); |
| 9119 | untyped_expectations_.push_back(untyped_expectation); |
| 9120 | |
| 9121 | // Adds this expectation into the implicit sequence if there is one. |
| 9122 | Sequence* const implicit_sequence = g_gmock_implicit_sequence.get(); |
| 9123 | if (implicit_sequence != NULL) { |
| 9124 | implicit_sequence->AddExpectation(Expectation(untyped_expectation)); |
| 9125 | } |
| 9126 | |
| 9127 | return *expectation; |
| 9128 | } |
| 9129 | |
| 9130 | // The current spec (either default action spec or expectation spec) |
| 9131 | // being described on this function mocker. |
| 9132 | MockSpec<F>& current_spec() { return current_spec_; } |
| 9133 | |
| 9134 | private: |
| 9135 | template <typename Func> friend class TypedExpectation; |
| 9136 | |
| 9137 | // Some utilities needed for implementing UntypedInvokeWith(). |
| 9138 | |
| 9139 | // Describes what default action will be performed for the given |
| 9140 | // arguments. |
| 9141 | // L = * |
| 9142 | void DescribeDefaultActionTo(const ArgumentTuple& args, |
| 9143 | ::std::ostream* os) const { |
| 9144 | const OnCallSpec<F>* const spec = FindOnCallSpec(args); |
| 9145 | |
| 9146 | if (spec == NULL) { |
| 9147 | *os << (internal::type_equals<Result, void>::value ? |
| 9148 | "returning directly.\n" : |
| 9149 | "returning default value.\n"); |
| 9150 | } else { |
| 9151 | *os << "taking default action specified at:\n" |
| 9152 | << FormatFileLocation(spec->file(), spec->line()) << "\n"; |
| 9153 | } |
| 9154 | } |
| 9155 | |
| 9156 | // Writes a message that the call is uninteresting (i.e. neither |
| 9157 | // explicitly expected nor explicitly unexpected) to the given |
| 9158 | // ostream. |
| 9159 | // L < g_gmock_mutex |
| 9160 | virtual void UntypedDescribeUninterestingCall(const void* untyped_args, |
| 9161 | ::std::ostream* os) const { |
| 9162 | const ArgumentTuple& args = |
| 9163 | *static_cast<const ArgumentTuple*>(untyped_args); |
| 9164 | *os << "Uninteresting mock function call - "; |
| 9165 | DescribeDefaultActionTo(args, os); |
| 9166 | *os << " Function call: " << Name(); |
| 9167 | UniversalPrint(args, os); |
| 9168 | } |
| 9169 | |
| 9170 | // Returns the expectation that matches the given function arguments |
| 9171 | // (or NULL is there's no match); when a match is found, |
| 9172 | // untyped_action is set to point to the action that should be |
| 9173 | // performed (or NULL if the action is "do default"), and |
| 9174 | // is_excessive is modified to indicate whether the call exceeds the |
| 9175 | // expected number. |
| 9176 | // |
| 9177 | // Critical section: We must find the matching expectation and the |
| 9178 | // corresponding action that needs to be taken in an ATOMIC |
| 9179 | // transaction. Otherwise another thread may call this mock |
| 9180 | // method in the middle and mess up the state. |
| 9181 | // |
| 9182 | // However, performing the action has to be left out of the critical |
| 9183 | // section. The reason is that we have no control on what the |
| 9184 | // action does (it can invoke an arbitrary user function or even a |
| 9185 | // mock function) and excessive locking could cause a dead lock. |
| 9186 | // L < g_gmock_mutex |
| 9187 | virtual const ExpectationBase* UntypedFindMatchingExpectation( |
| 9188 | const void* untyped_args, |
| 9189 | const void** untyped_action, bool* is_excessive, |
| 9190 | ::std::ostream* what, ::std::ostream* why) { |
| 9191 | const ArgumentTuple& args = |
| 9192 | *static_cast<const ArgumentTuple*>(untyped_args); |
| 9193 | MutexLock l(&g_gmock_mutex); |
| 9194 | TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args); |
| 9195 | if (exp == NULL) { // A match wasn't found. |
| 9196 | this->FormatUnexpectedCallMessageLocked(args, what, why); |
| 9197 | return NULL; |
| 9198 | } |
| 9199 | |
| 9200 | // This line must be done before calling GetActionForArguments(), |
| 9201 | // which will increment the call count for *exp and thus affect |
| 9202 | // its saturation status. |
| 9203 | *is_excessive = exp->IsSaturated(); |
| 9204 | const Action<F>* action = exp->GetActionForArguments(this, args, what, why); |
| 9205 | if (action != NULL && action->IsDoDefault()) |
| 9206 | action = NULL; // Normalize "do default" to NULL. |
| 9207 | *untyped_action = action; |
| 9208 | return exp; |
| 9209 | } |
| 9210 | |
| 9211 | // Prints the given function arguments to the ostream. |
| 9212 | virtual void UntypedPrintArgs(const void* untyped_args, |
| 9213 | ::std::ostream* os) const { |
| 9214 | const ArgumentTuple& args = |
| 9215 | *static_cast<const ArgumentTuple*>(untyped_args); |
| 9216 | UniversalPrint(args, os); |
| 9217 | } |
| 9218 | |
| 9219 | // Returns the expectation that matches the arguments, or NULL if no |
| 9220 | // expectation matches them. |
| 9221 | // L >= g_gmock_mutex |
| 9222 | TypedExpectation<F>* FindMatchingExpectationLocked( |
| 9223 | const ArgumentTuple& args) const { |
| 9224 | g_gmock_mutex.AssertHeld(); |
| 9225 | for (typename UntypedExpectations::const_reverse_iterator it = |
| 9226 | untyped_expectations_.rbegin(); |
| 9227 | it != untyped_expectations_.rend(); ++it) { |
| 9228 | TypedExpectation<F>* const exp = |
| 9229 | static_cast<TypedExpectation<F>*>(it->get()); |
| 9230 | if (exp->ShouldHandleArguments(args)) { |
| 9231 | return exp; |
| 9232 | } |
| 9233 | } |
| 9234 | return NULL; |
| 9235 | } |
| 9236 | |
| 9237 | // Returns a message that the arguments don't match any expectation. |
| 9238 | // L >= g_gmock_mutex |
| 9239 | void FormatUnexpectedCallMessageLocked(const ArgumentTuple& args, |
| 9240 | ::std::ostream* os, |
| 9241 | ::std::ostream* why) const { |
| 9242 | g_gmock_mutex.AssertHeld(); |
| 9243 | *os << "\nUnexpected mock function call - "; |
| 9244 | DescribeDefaultActionTo(args, os); |
| 9245 | PrintTriedExpectationsLocked(args, why); |
| 9246 | } |
| 9247 | |
| 9248 | // Prints a list of expectations that have been tried against the |
| 9249 | // current mock function call. |
| 9250 | // L >= g_gmock_mutex |
| 9251 | void PrintTriedExpectationsLocked(const ArgumentTuple& args, |
| 9252 | ::std::ostream* why) const { |
| 9253 | g_gmock_mutex.AssertHeld(); |
| 9254 | const int count = static_cast<int>(untyped_expectations_.size()); |
| 9255 | *why << "Google Mock tried the following " << count << " " |
| 9256 | << (count == 1 ? "expectation, but it didn't match" : |
| 9257 | "expectations, but none matched") |
| 9258 | << ":\n"; |
| 9259 | for (int i = 0; i < count; i++) { |
| 9260 | TypedExpectation<F>* const expectation = |
| 9261 | static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get()); |
| 9262 | *why << "\n"; |
| 9263 | expectation->DescribeLocationTo(why); |
| 9264 | if (count > 1) { |
| 9265 | *why << "tried expectation #" << i << ": "; |
| 9266 | } |
| 9267 | *why << expectation->source_text() << "...\n"; |
| 9268 | expectation->ExplainMatchResultTo(args, why); |
| 9269 | expectation->DescribeCallCountTo(why); |
| 9270 | } |
| 9271 | } |
| 9272 | |
| 9273 | // The current spec (either default action spec or expectation spec) |
| 9274 | // being described on this function mocker. |
| 9275 | MockSpec<F> current_spec_; |
| 9276 | |
| 9277 | // There is no generally useful and implementable semantics of |
| 9278 | // copying a mock object, so copying a mock is usually a user error. |
| 9279 | // Thus we disallow copying function mockers. If the user really |
| 9280 | // wants to copy a mock object, he should implement his own copy |
| 9281 | // operation, for example: |
| 9282 | // |
| 9283 | // class MockFoo : public Foo { |
| 9284 | // public: |
| 9285 | // // Defines a copy constructor explicitly. |
| 9286 | // MockFoo(const MockFoo& src) {} |
| 9287 | // ... |
| 9288 | // }; |
| 9289 | GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase); |
| 9290 | }; // class FunctionMockerBase |
| 9291 | |
| 9292 | #ifdef _MSC_VER |
| 9293 | # pragma warning(pop) // Restores the warning state. |
| 9294 | #endif // _MSV_VER |
| 9295 | |
| 9296 | // Implements methods of FunctionMockerBase. |
| 9297 | |
| 9298 | // Verifies that all expectations on this mock function have been |
| 9299 | // satisfied. Reports one or more Google Test non-fatal failures and |
| 9300 | // returns false if not. |
| 9301 | // L >= g_gmock_mutex |
| 9302 | |
| 9303 | // Reports an uninteresting call (whose description is in msg) in the |
| 9304 | // manner specified by 'reaction'. |
| 9305 | void ReportUninterestingCall(CallReaction reaction, const string& msg); |
| 9306 | |
| 9307 | } // namespace internal |
| 9308 | |
| 9309 | // The style guide prohibits "using" statements in a namespace scope |
| 9310 | // inside a header file. However, the MockSpec class template is |
| 9311 | // meant to be defined in the ::testing namespace. The following line |
| 9312 | // is just a trick for working around a bug in MSVC 8.0, which cannot |
| 9313 | // handle it if we define MockSpec in ::testing. |
| 9314 | using internal::MockSpec; |
| 9315 | |
| 9316 | // Const(x) is a convenient function for obtaining a const reference |
| 9317 | // to x. This is useful for setting expectations on an overloaded |
| 9318 | // const mock method, e.g. |
| 9319 | // |
| 9320 | // class MockFoo : public FooInterface { |
| 9321 | // public: |
| 9322 | // MOCK_METHOD0(Bar, int()); |
| 9323 | // MOCK_CONST_METHOD0(Bar, int&()); |
| 9324 | // }; |
| 9325 | // |
| 9326 | // MockFoo foo; |
| 9327 | // // Expects a call to non-const MockFoo::Bar(). |
| 9328 | // EXPECT_CALL(foo, Bar()); |
| 9329 | // // Expects a call to const MockFoo::Bar(). |
| 9330 | // EXPECT_CALL(Const(foo), Bar()); |
| 9331 | template <typename T> |
| 9332 | inline const T& Const(const T& x) { return x; } |
| 9333 | |
| 9334 | // Constructs an Expectation object that references and co-owns exp. |
| 9335 | inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT |
| 9336 | : expectation_base_(exp.GetHandle().expectation_base()) {} |
| 9337 | |
| 9338 | } // namespace testing |
| 9339 | |
| 9340 | // A separate macro is required to avoid compile errors when the name |
| 9341 | // of the method used in call is a result of macro expansion. |
| 9342 | // See CompilesWithMethodNameExpandedFromMacro tests in |
| 9343 | // internal/gmock-spec-builders_test.cc for more details. |
| 9344 | #define GMOCK_ON_CALL_IMPL_(obj, call) \ |
| 9345 | ((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \ |
| 9346 | #obj, #call) |
| 9347 | #define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call) |
| 9348 | |
| 9349 | #define GMOCK_EXPECT_CALL_IMPL_(obj, call) \ |
| 9350 | ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call) |
| 9351 | #define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call) |
| 9352 | |
| 9353 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ |
| 9354 | |
| 9355 | namespace testing { |
| 9356 | namespace internal { |
| 9357 | |
| 9358 | template <typename F> |
| 9359 | class FunctionMockerBase; |
| 9360 | |
| 9361 | // Note: class FunctionMocker really belongs to the ::testing |
| 9362 | // namespace. However if we define it in ::testing, MSVC will |
| 9363 | // complain when classes in ::testing::internal declare it as a |
| 9364 | // friend class template. To workaround this compiler bug, we define |
| 9365 | // FunctionMocker in ::testing::internal and import it into ::testing. |
| 9366 | template <typename F> |
| 9367 | class FunctionMocker; |
| 9368 | |
| 9369 | template <typename R> |
| 9370 | class FunctionMocker<R()> : public |
| 9371 | internal::FunctionMockerBase<R()> { |
| 9372 | public: |
| 9373 | typedef R F(); |
| 9374 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 9375 | |
| 9376 | MockSpec<F>& With() { |
| 9377 | return this->current_spec(); |
| 9378 | } |
| 9379 | |
| 9380 | R Invoke() { |
| 9381 | // Even though gcc and MSVC don't enforce it, 'this->' is required |
| 9382 | // by the C++ standard [14.6.4] here, as the base class type is |
| 9383 | // dependent on the template argument (and thus shouldn't be |
| 9384 | // looked into when resolving InvokeWith). |
| 9385 | return this->InvokeWith(ArgumentTuple()); |
| 9386 | } |
| 9387 | }; |
| 9388 | |
| 9389 | template <typename R, typename A1> |
| 9390 | class FunctionMocker<R(A1)> : public |
| 9391 | internal::FunctionMockerBase<R(A1)> { |
| 9392 | public: |
| 9393 | typedef R F(A1); |
| 9394 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 9395 | |
| 9396 | MockSpec<F>& With(const Matcher<A1>& m1) { |
| 9397 | this->current_spec().SetMatchers(::std::tr1::make_tuple(m1)); |
| 9398 | return this->current_spec(); |
| 9399 | } |
| 9400 | |
| 9401 | R Invoke(A1 a1) { |
| 9402 | // Even though gcc and MSVC don't enforce it, 'this->' is required |
| 9403 | // by the C++ standard [14.6.4] here, as the base class type is |
| 9404 | // dependent on the template argument (and thus shouldn't be |
| 9405 | // looked into when resolving InvokeWith). |
| 9406 | return this->InvokeWith(ArgumentTuple(a1)); |
| 9407 | } |
| 9408 | }; |
| 9409 | |
| 9410 | template <typename R, typename A1, typename A2> |
| 9411 | class FunctionMocker<R(A1, A2)> : public |
| 9412 | internal::FunctionMockerBase<R(A1, A2)> { |
| 9413 | public: |
| 9414 | typedef R F(A1, A2); |
| 9415 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 9416 | |
| 9417 | MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2) { |
| 9418 | this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2)); |
| 9419 | return this->current_spec(); |
| 9420 | } |
| 9421 | |
| 9422 | R Invoke(A1 a1, A2 a2) { |
| 9423 | // Even though gcc and MSVC don't enforce it, 'this->' is required |
| 9424 | // by the C++ standard [14.6.4] here, as the base class type is |
| 9425 | // dependent on the template argument (and thus shouldn't be |
| 9426 | // looked into when resolving InvokeWith). |
| 9427 | return this->InvokeWith(ArgumentTuple(a1, a2)); |
| 9428 | } |
| 9429 | }; |
| 9430 | |
| 9431 | template <typename R, typename A1, typename A2, typename A3> |
| 9432 | class FunctionMocker<R(A1, A2, A3)> : public |
| 9433 | internal::FunctionMockerBase<R(A1, A2, A3)> { |
| 9434 | public: |
| 9435 | typedef R F(A1, A2, A3); |
| 9436 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 9437 | |
| 9438 | MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, |
| 9439 | const Matcher<A3>& m3) { |
| 9440 | this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3)); |
| 9441 | return this->current_spec(); |
| 9442 | } |
| 9443 | |
| 9444 | R Invoke(A1 a1, A2 a2, A3 a3) { |
| 9445 | // Even though gcc and MSVC don't enforce it, 'this->' is required |
| 9446 | // by the C++ standard [14.6.4] here, as the base class type is |
| 9447 | // dependent on the template argument (and thus shouldn't be |
| 9448 | // looked into when resolving InvokeWith). |
| 9449 | return this->InvokeWith(ArgumentTuple(a1, a2, a3)); |
| 9450 | } |
| 9451 | }; |
| 9452 | |
| 9453 | template <typename R, typename A1, typename A2, typename A3, typename A4> |
| 9454 | class FunctionMocker<R(A1, A2, A3, A4)> : public |
| 9455 | internal::FunctionMockerBase<R(A1, A2, A3, A4)> { |
| 9456 | public: |
| 9457 | typedef R F(A1, A2, A3, A4); |
| 9458 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 9459 | |
| 9460 | MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, |
| 9461 | const Matcher<A3>& m3, const Matcher<A4>& m4) { |
| 9462 | this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4)); |
| 9463 | return this->current_spec(); |
| 9464 | } |
| 9465 | |
| 9466 | R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) { |
| 9467 | // Even though gcc and MSVC don't enforce it, 'this->' is required |
| 9468 | // by the C++ standard [14.6.4] here, as the base class type is |
| 9469 | // dependent on the template argument (and thus shouldn't be |
| 9470 | // looked into when resolving InvokeWith). |
| 9471 | return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4)); |
| 9472 | } |
| 9473 | }; |
| 9474 | |
| 9475 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 9476 | typename A5> |
| 9477 | class FunctionMocker<R(A1, A2, A3, A4, A5)> : public |
| 9478 | internal::FunctionMockerBase<R(A1, A2, A3, A4, A5)> { |
| 9479 | public: |
| 9480 | typedef R F(A1, A2, A3, A4, A5); |
| 9481 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 9482 | |
| 9483 | MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, |
| 9484 | const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) { |
| 9485 | this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, |
| 9486 | m5)); |
| 9487 | return this->current_spec(); |
| 9488 | } |
| 9489 | |
| 9490 | R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { |
| 9491 | // Even though gcc and MSVC don't enforce it, 'this->' is required |
| 9492 | // by the C++ standard [14.6.4] here, as the base class type is |
| 9493 | // dependent on the template argument (and thus shouldn't be |
| 9494 | // looked into when resolving InvokeWith). |
| 9495 | return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5)); |
| 9496 | } |
| 9497 | }; |
| 9498 | |
| 9499 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 9500 | typename A5, typename A6> |
| 9501 | class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public |
| 9502 | internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6)> { |
| 9503 | public: |
| 9504 | typedef R F(A1, A2, A3, A4, A5, A6); |
| 9505 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 9506 | |
| 9507 | MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, |
| 9508 | const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, |
| 9509 | const Matcher<A6>& m6) { |
| 9510 | this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, |
| 9511 | m6)); |
| 9512 | return this->current_spec(); |
| 9513 | } |
| 9514 | |
| 9515 | R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { |
| 9516 | // Even though gcc and MSVC don't enforce it, 'this->' is required |
| 9517 | // by the C++ standard [14.6.4] here, as the base class type is |
| 9518 | // dependent on the template argument (and thus shouldn't be |
| 9519 | // looked into when resolving InvokeWith). |
| 9520 | return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6)); |
| 9521 | } |
| 9522 | }; |
| 9523 | |
| 9524 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 9525 | typename A5, typename A6, typename A7> |
| 9526 | class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public |
| 9527 | internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7)> { |
| 9528 | public: |
| 9529 | typedef R F(A1, A2, A3, A4, A5, A6, A7); |
| 9530 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 9531 | |
| 9532 | MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, |
| 9533 | const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, |
| 9534 | const Matcher<A6>& m6, const Matcher<A7>& m7) { |
| 9535 | this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, |
| 9536 | m6, m7)); |
| 9537 | return this->current_spec(); |
| 9538 | } |
| 9539 | |
| 9540 | R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { |
| 9541 | // Even though gcc and MSVC don't enforce it, 'this->' is required |
| 9542 | // by the C++ standard [14.6.4] here, as the base class type is |
| 9543 | // dependent on the template argument (and thus shouldn't be |
| 9544 | // looked into when resolving InvokeWith). |
| 9545 | return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7)); |
| 9546 | } |
| 9547 | }; |
| 9548 | |
| 9549 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 9550 | typename A5, typename A6, typename A7, typename A8> |
| 9551 | class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public |
| 9552 | internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8)> { |
| 9553 | public: |
| 9554 | typedef R F(A1, A2, A3, A4, A5, A6, A7, A8); |
| 9555 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 9556 | |
| 9557 | MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, |
| 9558 | const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, |
| 9559 | const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) { |
| 9560 | this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, |
| 9561 | m6, m7, m8)); |
| 9562 | return this->current_spec(); |
| 9563 | } |
| 9564 | |
| 9565 | R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { |
| 9566 | // Even though gcc and MSVC don't enforce it, 'this->' is required |
| 9567 | // by the C++ standard [14.6.4] here, as the base class type is |
| 9568 | // dependent on the template argument (and thus shouldn't be |
| 9569 | // looked into when resolving InvokeWith). |
| 9570 | return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8)); |
| 9571 | } |
| 9572 | }; |
| 9573 | |
| 9574 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 9575 | typename A5, typename A6, typename A7, typename A8, typename A9> |
| 9576 | class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public |
| 9577 | internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> { |
| 9578 | public: |
| 9579 | typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9); |
| 9580 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 9581 | |
| 9582 | MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, |
| 9583 | const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, |
| 9584 | const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8, |
| 9585 | const Matcher<A9>& m9) { |
| 9586 | this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, |
| 9587 | m6, m7, m8, m9)); |
| 9588 | return this->current_spec(); |
| 9589 | } |
| 9590 | |
| 9591 | R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { |
| 9592 | // Even though gcc and MSVC don't enforce it, 'this->' is required |
| 9593 | // by the C++ standard [14.6.4] here, as the base class type is |
| 9594 | // dependent on the template argument (and thus shouldn't be |
| 9595 | // looked into when resolving InvokeWith). |
| 9596 | return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9)); |
| 9597 | } |
| 9598 | }; |
| 9599 | |
| 9600 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 9601 | typename A5, typename A6, typename A7, typename A8, typename A9, |
| 9602 | typename A10> |
| 9603 | class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public |
| 9604 | internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> { |
| 9605 | public: |
| 9606 | typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); |
| 9607 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 9608 | |
| 9609 | MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, |
| 9610 | const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, |
| 9611 | const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8, |
| 9612 | const Matcher<A9>& m9, const Matcher<A10>& m10) { |
| 9613 | this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, |
| 9614 | m6, m7, m8, m9, m10)); |
| 9615 | return this->current_spec(); |
| 9616 | } |
| 9617 | |
| 9618 | R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, |
| 9619 | A10 a10) { |
| 9620 | // Even though gcc and MSVC don't enforce it, 'this->' is required |
| 9621 | // by the C++ standard [14.6.4] here, as the base class type is |
| 9622 | // dependent on the template argument (and thus shouldn't be |
| 9623 | // looked into when resolving InvokeWith). |
| 9624 | return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9, |
| 9625 | a10)); |
| 9626 | } |
| 9627 | }; |
| 9628 | |
| 9629 | } // namespace internal |
| 9630 | |
| 9631 | // The style guide prohibits "using" statements in a namespace scope |
| 9632 | // inside a header file. However, the FunctionMocker class template |
| 9633 | // is meant to be defined in the ::testing namespace. The following |
| 9634 | // line is just a trick for working around a bug in MSVC 8.0, which |
| 9635 | // cannot handle it if we define FunctionMocker in ::testing. |
| 9636 | using internal::FunctionMocker; |
| 9637 | |
| 9638 | // The result type of function type F. |
| 9639 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9640 | #define GMOCK_RESULT_(tn, F) tn ::testing::internal::Function<F>::Result |
| 9641 | |
| 9642 | // The type of argument N of function type F. |
| 9643 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9644 | #define GMOCK_ARG_(tn, F, N) tn ::testing::internal::Function<F>::Argument##N |
| 9645 | |
| 9646 | // The matcher type for argument N of function type F. |
| 9647 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9648 | #define GMOCK_MATCHER_(tn, F, N) const ::testing::Matcher<GMOCK_ARG_(tn, F, N)>& |
| 9649 | |
| 9650 | // The variable for mocking the given method. |
| 9651 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9652 | #define GMOCK_MOCKER_(arity, constness, Method) \ |
| 9653 | GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) |
| 9654 | |
| 9655 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9656 | #define GMOCK_METHOD0_(tn, constness, ct, Method, F) \ |
| 9657 | GMOCK_RESULT_(tn, F) ct Method() constness { \ |
| 9658 | GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ |
| 9659 | tn ::testing::internal::Function<F>::ArgumentTuple>::value == 0, \ |
| 9660 | this_method_does_not_take_0_arguments); \ |
| 9661 | GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ |
| 9662 | return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ |
| 9663 | } \ |
| 9664 | ::testing::MockSpec<F>& \ |
| 9665 | gmock_##Method() constness { \ |
| 9666 | GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ |
| 9667 | return GMOCK_MOCKER_(0, constness, Method).With(); \ |
| 9668 | } \ |
| 9669 | mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(0, constness, Method) |
| 9670 | |
| 9671 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9672 | #define GMOCK_METHOD1_(tn, constness, ct, Method, F) \ |
| 9673 | GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1) constness { \ |
| 9674 | GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ |
| 9675 | tn ::testing::internal::Function<F>::ArgumentTuple>::value == 1, \ |
| 9676 | this_method_does_not_take_1_argument); \ |
| 9677 | GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ |
| 9678 | return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \ |
| 9679 | } \ |
| 9680 | ::testing::MockSpec<F>& \ |
| 9681 | gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1) constness { \ |
| 9682 | GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ |
| 9683 | return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ |
| 9684 | } \ |
| 9685 | mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(1, constness, Method) |
| 9686 | |
| 9687 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9688 | #define GMOCK_METHOD2_(tn, constness, ct, Method, F) \ |
| 9689 | GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ |
| 9690 | GMOCK_ARG_(tn, F, 2) gmock_a2) constness { \ |
| 9691 | GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ |
| 9692 | tn ::testing::internal::Function<F>::ArgumentTuple>::value == 2, \ |
| 9693 | this_method_does_not_take_2_arguments); \ |
| 9694 | GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ |
| 9695 | return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \ |
| 9696 | } \ |
| 9697 | ::testing::MockSpec<F>& \ |
| 9698 | gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ |
| 9699 | GMOCK_MATCHER_(tn, F, 2) gmock_a2) constness { \ |
| 9700 | GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ |
| 9701 | return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \ |
| 9702 | } \ |
| 9703 | mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(2, constness, Method) |
| 9704 | |
| 9705 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9706 | #define GMOCK_METHOD3_(tn, constness, ct, Method, F) \ |
| 9707 | GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ |
| 9708 | GMOCK_ARG_(tn, F, 2) gmock_a2, \ |
| 9709 | GMOCK_ARG_(tn, F, 3) gmock_a3) constness { \ |
| 9710 | GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ |
| 9711 | tn ::testing::internal::Function<F>::ArgumentTuple>::value == 3, \ |
| 9712 | this_method_does_not_take_3_arguments); \ |
| 9713 | GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ |
| 9714 | return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \ |
| 9715 | gmock_a3); \ |
| 9716 | } \ |
| 9717 | ::testing::MockSpec<F>& \ |
| 9718 | gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ |
| 9719 | GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ |
| 9720 | GMOCK_MATCHER_(tn, F, 3) gmock_a3) constness { \ |
| 9721 | GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \ |
| 9722 | return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \ |
| 9723 | gmock_a3); \ |
| 9724 | } \ |
| 9725 | mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(3, constness, Method) |
| 9726 | |
| 9727 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9728 | #define GMOCK_METHOD4_(tn, constness, ct, Method, F) \ |
| 9729 | GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ |
| 9730 | GMOCK_ARG_(tn, F, 2) gmock_a2, \ |
| 9731 | GMOCK_ARG_(tn, F, 3) gmock_a3, \ |
| 9732 | GMOCK_ARG_(tn, F, 4) gmock_a4) constness { \ |
| 9733 | GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ |
| 9734 | tn ::testing::internal::Function<F>::ArgumentTuple>::value == 4, \ |
| 9735 | this_method_does_not_take_4_arguments); \ |
| 9736 | GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ |
| 9737 | return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \ |
| 9738 | gmock_a3, gmock_a4); \ |
| 9739 | } \ |
| 9740 | ::testing::MockSpec<F>& \ |
| 9741 | gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ |
| 9742 | GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ |
| 9743 | GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ |
| 9744 | GMOCK_MATCHER_(tn, F, 4) gmock_a4) constness { \ |
| 9745 | GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \ |
| 9746 | return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \ |
| 9747 | gmock_a3, gmock_a4); \ |
| 9748 | } \ |
| 9749 | mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(4, constness, Method) |
| 9750 | |
| 9751 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9752 | #define GMOCK_METHOD5_(tn, constness, ct, Method, F) \ |
| 9753 | GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ |
| 9754 | GMOCK_ARG_(tn, F, 2) gmock_a2, \ |
| 9755 | GMOCK_ARG_(tn, F, 3) gmock_a3, \ |
| 9756 | GMOCK_ARG_(tn, F, 4) gmock_a4, \ |
| 9757 | GMOCK_ARG_(tn, F, 5) gmock_a5) constness { \ |
| 9758 | GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ |
| 9759 | tn ::testing::internal::Function<F>::ArgumentTuple>::value == 5, \ |
| 9760 | this_method_does_not_take_5_arguments); \ |
| 9761 | GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ |
| 9762 | return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \ |
| 9763 | gmock_a3, gmock_a4, gmock_a5); \ |
| 9764 | } \ |
| 9765 | ::testing::MockSpec<F>& \ |
| 9766 | gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ |
| 9767 | GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ |
| 9768 | GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ |
| 9769 | GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ |
| 9770 | GMOCK_MATCHER_(tn, F, 5) gmock_a5) constness { \ |
| 9771 | GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \ |
| 9772 | return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \ |
| 9773 | gmock_a3, gmock_a4, gmock_a5); \ |
| 9774 | } \ |
| 9775 | mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(5, constness, Method) |
| 9776 | |
| 9777 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9778 | #define GMOCK_METHOD6_(tn, constness, ct, Method, F) \ |
| 9779 | GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ |
| 9780 | GMOCK_ARG_(tn, F, 2) gmock_a2, \ |
| 9781 | GMOCK_ARG_(tn, F, 3) gmock_a3, \ |
| 9782 | GMOCK_ARG_(tn, F, 4) gmock_a4, \ |
| 9783 | GMOCK_ARG_(tn, F, 5) gmock_a5, \ |
| 9784 | GMOCK_ARG_(tn, F, 6) gmock_a6) constness { \ |
| 9785 | GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ |
| 9786 | tn ::testing::internal::Function<F>::ArgumentTuple>::value == 6, \ |
| 9787 | this_method_does_not_take_6_arguments); \ |
| 9788 | GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ |
| 9789 | return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \ |
| 9790 | gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ |
| 9791 | } \ |
| 9792 | ::testing::MockSpec<F>& \ |
| 9793 | gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ |
| 9794 | GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ |
| 9795 | GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ |
| 9796 | GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ |
| 9797 | GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ |
| 9798 | GMOCK_MATCHER_(tn, F, 6) gmock_a6) constness { \ |
| 9799 | GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \ |
| 9800 | return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \ |
| 9801 | gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ |
| 9802 | } \ |
| 9803 | mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(6, constness, Method) |
| 9804 | |
| 9805 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9806 | #define GMOCK_METHOD7_(tn, constness, ct, Method, F) \ |
| 9807 | GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ |
| 9808 | GMOCK_ARG_(tn, F, 2) gmock_a2, \ |
| 9809 | GMOCK_ARG_(tn, F, 3) gmock_a3, \ |
| 9810 | GMOCK_ARG_(tn, F, 4) gmock_a4, \ |
| 9811 | GMOCK_ARG_(tn, F, 5) gmock_a5, \ |
| 9812 | GMOCK_ARG_(tn, F, 6) gmock_a6, \ |
| 9813 | GMOCK_ARG_(tn, F, 7) gmock_a7) constness { \ |
| 9814 | GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ |
| 9815 | tn ::testing::internal::Function<F>::ArgumentTuple>::value == 7, \ |
| 9816 | this_method_does_not_take_7_arguments); \ |
| 9817 | GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ |
| 9818 | return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \ |
| 9819 | gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ |
| 9820 | } \ |
| 9821 | ::testing::MockSpec<F>& \ |
| 9822 | gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ |
| 9823 | GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ |
| 9824 | GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ |
| 9825 | GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ |
| 9826 | GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ |
| 9827 | GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ |
| 9828 | GMOCK_MATCHER_(tn, F, 7) gmock_a7) constness { \ |
| 9829 | GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \ |
| 9830 | return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \ |
| 9831 | gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ |
| 9832 | } \ |
| 9833 | mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(7, constness, Method) |
| 9834 | |
| 9835 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9836 | #define GMOCK_METHOD8_(tn, constness, ct, Method, F) \ |
| 9837 | GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ |
| 9838 | GMOCK_ARG_(tn, F, 2) gmock_a2, \ |
| 9839 | GMOCK_ARG_(tn, F, 3) gmock_a3, \ |
| 9840 | GMOCK_ARG_(tn, F, 4) gmock_a4, \ |
| 9841 | GMOCK_ARG_(tn, F, 5) gmock_a5, \ |
| 9842 | GMOCK_ARG_(tn, F, 6) gmock_a6, \ |
| 9843 | GMOCK_ARG_(tn, F, 7) gmock_a7, \ |
| 9844 | GMOCK_ARG_(tn, F, 8) gmock_a8) constness { \ |
| 9845 | GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ |
| 9846 | tn ::testing::internal::Function<F>::ArgumentTuple>::value == 8, \ |
| 9847 | this_method_does_not_take_8_arguments); \ |
| 9848 | GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ |
| 9849 | return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \ |
| 9850 | gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ |
| 9851 | } \ |
| 9852 | ::testing::MockSpec<F>& \ |
| 9853 | gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ |
| 9854 | GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ |
| 9855 | GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ |
| 9856 | GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ |
| 9857 | GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ |
| 9858 | GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ |
| 9859 | GMOCK_MATCHER_(tn, F, 7) gmock_a7, \ |
| 9860 | GMOCK_MATCHER_(tn, F, 8) gmock_a8) constness { \ |
| 9861 | GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \ |
| 9862 | return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \ |
| 9863 | gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ |
| 9864 | } \ |
| 9865 | mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(8, constness, Method) |
| 9866 | |
| 9867 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9868 | #define GMOCK_METHOD9_(tn, constness, ct, Method, F) \ |
| 9869 | GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ |
| 9870 | GMOCK_ARG_(tn, F, 2) gmock_a2, \ |
| 9871 | GMOCK_ARG_(tn, F, 3) gmock_a3, \ |
| 9872 | GMOCK_ARG_(tn, F, 4) gmock_a4, \ |
| 9873 | GMOCK_ARG_(tn, F, 5) gmock_a5, \ |
| 9874 | GMOCK_ARG_(tn, F, 6) gmock_a6, \ |
| 9875 | GMOCK_ARG_(tn, F, 7) gmock_a7, \ |
| 9876 | GMOCK_ARG_(tn, F, 8) gmock_a8, \ |
| 9877 | GMOCK_ARG_(tn, F, 9) gmock_a9) constness { \ |
| 9878 | GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ |
| 9879 | tn ::testing::internal::Function<F>::ArgumentTuple>::value == 9, \ |
| 9880 | this_method_does_not_take_9_arguments); \ |
| 9881 | GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ |
| 9882 | return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \ |
| 9883 | gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ |
| 9884 | gmock_a9); \ |
| 9885 | } \ |
| 9886 | ::testing::MockSpec<F>& \ |
| 9887 | gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ |
| 9888 | GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ |
| 9889 | GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ |
| 9890 | GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ |
| 9891 | GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ |
| 9892 | GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ |
| 9893 | GMOCK_MATCHER_(tn, F, 7) gmock_a7, \ |
| 9894 | GMOCK_MATCHER_(tn, F, 8) gmock_a8, \ |
| 9895 | GMOCK_MATCHER_(tn, F, 9) gmock_a9) constness { \ |
| 9896 | GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \ |
| 9897 | return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \ |
| 9898 | gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ |
| 9899 | gmock_a9); \ |
| 9900 | } \ |
| 9901 | mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(9, constness, Method) |
| 9902 | |
| 9903 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! |
| 9904 | #define GMOCK_METHOD10_(tn, constness, ct, Method, F) \ |
| 9905 | GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ |
| 9906 | GMOCK_ARG_(tn, F, 2) gmock_a2, \ |
| 9907 | GMOCK_ARG_(tn, F, 3) gmock_a3, \ |
| 9908 | GMOCK_ARG_(tn, F, 4) gmock_a4, \ |
| 9909 | GMOCK_ARG_(tn, F, 5) gmock_a5, \ |
| 9910 | GMOCK_ARG_(tn, F, 6) gmock_a6, \ |
| 9911 | GMOCK_ARG_(tn, F, 7) gmock_a7, \ |
| 9912 | GMOCK_ARG_(tn, F, 8) gmock_a8, \ |
| 9913 | GMOCK_ARG_(tn, F, 9) gmock_a9, \ |
| 9914 | GMOCK_ARG_(tn, F, 10) gmock_a10) constness { \ |
| 9915 | GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ |
| 9916 | tn ::testing::internal::Function<F>::ArgumentTuple>::value == 10, \ |
| 9917 | this_method_does_not_take_10_arguments); \ |
| 9918 | GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ |
| 9919 | return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \ |
| 9920 | gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ |
| 9921 | gmock_a10); \ |
| 9922 | } \ |
| 9923 | ::testing::MockSpec<F>& \ |
| 9924 | gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ |
| 9925 | GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ |
| 9926 | GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ |
| 9927 | GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ |
| 9928 | GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ |
| 9929 | GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ |
| 9930 | GMOCK_MATCHER_(tn, F, 7) gmock_a7, \ |
| 9931 | GMOCK_MATCHER_(tn, F, 8) gmock_a8, \ |
| 9932 | GMOCK_MATCHER_(tn, F, 9) gmock_a9, \ |
| 9933 | GMOCK_MATCHER_(tn, F, 10) gmock_a10) constness { \ |
| 9934 | GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \ |
| 9935 | return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \ |
| 9936 | gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ |
| 9937 | gmock_a10); \ |
| 9938 | } \ |
| 9939 | mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(10, constness, Method) |
| 9940 | |
| 9941 | #define MOCK_METHOD0(m, F) GMOCK_METHOD0_(, , , m, F) |
| 9942 | #define MOCK_METHOD1(m, F) GMOCK_METHOD1_(, , , m, F) |
| 9943 | #define MOCK_METHOD2(m, F) GMOCK_METHOD2_(, , , m, F) |
| 9944 | #define MOCK_METHOD3(m, F) GMOCK_METHOD3_(, , , m, F) |
| 9945 | #define MOCK_METHOD4(m, F) GMOCK_METHOD4_(, , , m, F) |
| 9946 | #define MOCK_METHOD5(m, F) GMOCK_METHOD5_(, , , m, F) |
| 9947 | #define MOCK_METHOD6(m, F) GMOCK_METHOD6_(, , , m, F) |
| 9948 | #define MOCK_METHOD7(m, F) GMOCK_METHOD7_(, , , m, F) |
| 9949 | #define MOCK_METHOD8(m, F) GMOCK_METHOD8_(, , , m, F) |
| 9950 | #define MOCK_METHOD9(m, F) GMOCK_METHOD9_(, , , m, F) |
| 9951 | #define MOCK_METHOD10(m, F) GMOCK_METHOD10_(, , , m, F) |
| 9952 | |
| 9953 | #define MOCK_CONST_METHOD0(m, F) GMOCK_METHOD0_(, const, , m, F) |
| 9954 | #define MOCK_CONST_METHOD1(m, F) GMOCK_METHOD1_(, const, , m, F) |
| 9955 | #define MOCK_CONST_METHOD2(m, F) GMOCK_METHOD2_(, const, , m, F) |
| 9956 | #define MOCK_CONST_METHOD3(m, F) GMOCK_METHOD3_(, const, , m, F) |
| 9957 | #define MOCK_CONST_METHOD4(m, F) GMOCK_METHOD4_(, const, , m, F) |
| 9958 | #define MOCK_CONST_METHOD5(m, F) GMOCK_METHOD5_(, const, , m, F) |
| 9959 | #define MOCK_CONST_METHOD6(m, F) GMOCK_METHOD6_(, const, , m, F) |
| 9960 | #define MOCK_CONST_METHOD7(m, F) GMOCK_METHOD7_(, const, , m, F) |
| 9961 | #define MOCK_CONST_METHOD8(m, F) GMOCK_METHOD8_(, const, , m, F) |
| 9962 | #define MOCK_CONST_METHOD9(m, F) GMOCK_METHOD9_(, const, , m, F) |
| 9963 | #define MOCK_CONST_METHOD10(m, F) GMOCK_METHOD10_(, const, , m, F) |
| 9964 | |
| 9965 | #define MOCK_METHOD0_T(m, F) GMOCK_METHOD0_(typename, , , m, F) |
| 9966 | #define MOCK_METHOD1_T(m, F) GMOCK_METHOD1_(typename, , , m, F) |
| 9967 | #define MOCK_METHOD2_T(m, F) GMOCK_METHOD2_(typename, , , m, F) |
| 9968 | #define MOCK_METHOD3_T(m, F) GMOCK_METHOD3_(typename, , , m, F) |
| 9969 | #define MOCK_METHOD4_T(m, F) GMOCK_METHOD4_(typename, , , m, F) |
| 9970 | #define MOCK_METHOD5_T(m, F) GMOCK_METHOD5_(typename, , , m, F) |
| 9971 | #define MOCK_METHOD6_T(m, F) GMOCK_METHOD6_(typename, , , m, F) |
| 9972 | #define MOCK_METHOD7_T(m, F) GMOCK_METHOD7_(typename, , , m, F) |
| 9973 | #define MOCK_METHOD8_T(m, F) GMOCK_METHOD8_(typename, , , m, F) |
| 9974 | #define MOCK_METHOD9_T(m, F) GMOCK_METHOD9_(typename, , , m, F) |
| 9975 | #define MOCK_METHOD10_T(m, F) GMOCK_METHOD10_(typename, , , m, F) |
| 9976 | |
| 9977 | #define MOCK_CONST_METHOD0_T(m, F) GMOCK_METHOD0_(typename, const, , m, F) |
| 9978 | #define MOCK_CONST_METHOD1_T(m, F) GMOCK_METHOD1_(typename, const, , m, F) |
| 9979 | #define MOCK_CONST_METHOD2_T(m, F) GMOCK_METHOD2_(typename, const, , m, F) |
| 9980 | #define MOCK_CONST_METHOD3_T(m, F) GMOCK_METHOD3_(typename, const, , m, F) |
| 9981 | #define MOCK_CONST_METHOD4_T(m, F) GMOCK_METHOD4_(typename, const, , m, F) |
| 9982 | #define MOCK_CONST_METHOD5_T(m, F) GMOCK_METHOD5_(typename, const, , m, F) |
| 9983 | #define MOCK_CONST_METHOD6_T(m, F) GMOCK_METHOD6_(typename, const, , m, F) |
| 9984 | #define MOCK_CONST_METHOD7_T(m, F) GMOCK_METHOD7_(typename, const, , m, F) |
| 9985 | #define MOCK_CONST_METHOD8_T(m, F) GMOCK_METHOD8_(typename, const, , m, F) |
| 9986 | #define MOCK_CONST_METHOD9_T(m, F) GMOCK_METHOD9_(typename, const, , m, F) |
| 9987 | #define MOCK_CONST_METHOD10_T(m, F) GMOCK_METHOD10_(typename, const, , m, F) |
| 9988 | |
| 9989 | #define MOCK_METHOD0_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD0_(, , ct, m, F) |
| 9990 | #define MOCK_METHOD1_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD1_(, , ct, m, F) |
| 9991 | #define MOCK_METHOD2_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD2_(, , ct, m, F) |
| 9992 | #define MOCK_METHOD3_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD3_(, , ct, m, F) |
| 9993 | #define MOCK_METHOD4_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD4_(, , ct, m, F) |
| 9994 | #define MOCK_METHOD5_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD5_(, , ct, m, F) |
| 9995 | #define MOCK_METHOD6_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD6_(, , ct, m, F) |
| 9996 | #define MOCK_METHOD7_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD7_(, , ct, m, F) |
| 9997 | #define MOCK_METHOD8_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD8_(, , ct, m, F) |
| 9998 | #define MOCK_METHOD9_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD9_(, , ct, m, F) |
| 9999 | #define MOCK_METHOD10_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD10_(, , ct, m, F) |
| 10000 | |
| 10001 | #define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, F) \ |
| 10002 | GMOCK_METHOD0_(, const, ct, m, F) |
| 10003 | #define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, F) \ |
| 10004 | GMOCK_METHOD1_(, const, ct, m, F) |
| 10005 | #define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, F) \ |
| 10006 | GMOCK_METHOD2_(, const, ct, m, F) |
| 10007 | #define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, F) \ |
| 10008 | GMOCK_METHOD3_(, const, ct, m, F) |
| 10009 | #define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, F) \ |
| 10010 | GMOCK_METHOD4_(, const, ct, m, F) |
| 10011 | #define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, F) \ |
| 10012 | GMOCK_METHOD5_(, const, ct, m, F) |
| 10013 | #define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, F) \ |
| 10014 | GMOCK_METHOD6_(, const, ct, m, F) |
| 10015 | #define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, F) \ |
| 10016 | GMOCK_METHOD7_(, const, ct, m, F) |
| 10017 | #define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, F) \ |
| 10018 | GMOCK_METHOD8_(, const, ct, m, F) |
| 10019 | #define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, F) \ |
| 10020 | GMOCK_METHOD9_(, const, ct, m, F) |
| 10021 | #define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, F) \ |
| 10022 | GMOCK_METHOD10_(, const, ct, m, F) |
| 10023 | |
| 10024 | #define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, F) \ |
| 10025 | GMOCK_METHOD0_(typename, , ct, m, F) |
| 10026 | #define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, F) \ |
| 10027 | GMOCK_METHOD1_(typename, , ct, m, F) |
| 10028 | #define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, F) \ |
| 10029 | GMOCK_METHOD2_(typename, , ct, m, F) |
| 10030 | #define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, F) \ |
| 10031 | GMOCK_METHOD3_(typename, , ct, m, F) |
| 10032 | #define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, F) \ |
| 10033 | GMOCK_METHOD4_(typename, , ct, m, F) |
| 10034 | #define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, F) \ |
| 10035 | GMOCK_METHOD5_(typename, , ct, m, F) |
| 10036 | #define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, F) \ |
| 10037 | GMOCK_METHOD6_(typename, , ct, m, F) |
| 10038 | #define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, F) \ |
| 10039 | GMOCK_METHOD7_(typename, , ct, m, F) |
| 10040 | #define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, F) \ |
| 10041 | GMOCK_METHOD8_(typename, , ct, m, F) |
| 10042 | #define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, F) \ |
| 10043 | GMOCK_METHOD9_(typename, , ct, m, F) |
| 10044 | #define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, F) \ |
| 10045 | GMOCK_METHOD10_(typename, , ct, m, F) |
| 10046 | |
| 10047 | #define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, F) \ |
| 10048 | GMOCK_METHOD0_(typename, const, ct, m, F) |
| 10049 | #define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, F) \ |
| 10050 | GMOCK_METHOD1_(typename, const, ct, m, F) |
| 10051 | #define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, F) \ |
| 10052 | GMOCK_METHOD2_(typename, const, ct, m, F) |
| 10053 | #define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, F) \ |
| 10054 | GMOCK_METHOD3_(typename, const, ct, m, F) |
| 10055 | #define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, F) \ |
| 10056 | GMOCK_METHOD4_(typename, const, ct, m, F) |
| 10057 | #define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, F) \ |
| 10058 | GMOCK_METHOD5_(typename, const, ct, m, F) |
| 10059 | #define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, F) \ |
| 10060 | GMOCK_METHOD6_(typename, const, ct, m, F) |
| 10061 | #define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, F) \ |
| 10062 | GMOCK_METHOD7_(typename, const, ct, m, F) |
| 10063 | #define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, F) \ |
| 10064 | GMOCK_METHOD8_(typename, const, ct, m, F) |
| 10065 | #define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, F) \ |
| 10066 | GMOCK_METHOD9_(typename, const, ct, m, F) |
| 10067 | #define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, F) \ |
| 10068 | GMOCK_METHOD10_(typename, const, ct, m, F) |
| 10069 | |
| 10070 | // A MockFunction<F> class has one mock method whose type is F. It is |
| 10071 | // useful when you just want your test code to emit some messages and |
| 10072 | // have Google Mock verify the right messages are sent (and perhaps at |
| 10073 | // the right times). For example, if you are exercising code: |
| 10074 | // |
| 10075 | // Foo(1); |
| 10076 | // Foo(2); |
| 10077 | // Foo(3); |
| 10078 | // |
| 10079 | // and want to verify that Foo(1) and Foo(3) both invoke |
| 10080 | // mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: |
| 10081 | // |
| 10082 | // TEST(FooTest, InvokesBarCorrectly) { |
| 10083 | // MyMock mock; |
| 10084 | // MockFunction<void(string check_point_name)> check; |
| 10085 | // { |
| 10086 | // InSequence s; |
| 10087 | // |
| 10088 | // EXPECT_CALL(mock, Bar("a")); |
| 10089 | // EXPECT_CALL(check, Call("1")); |
| 10090 | // EXPECT_CALL(check, Call("2")); |
| 10091 | // EXPECT_CALL(mock, Bar("a")); |
| 10092 | // } |
| 10093 | // Foo(1); |
| 10094 | // check.Call("1"); |
| 10095 | // Foo(2); |
| 10096 | // check.Call("2"); |
| 10097 | // Foo(3); |
| 10098 | // } |
| 10099 | // |
| 10100 | // The expectation spec says that the first Bar("a") must happen |
| 10101 | // before check point "1", the second Bar("a") must happen after check |
| 10102 | // point "2", and nothing should happen between the two check |
| 10103 | // points. The explicit check points make it easy to tell which |
| 10104 | // Bar("a") is called by which call to Foo(). |
| 10105 | template <typename F> |
| 10106 | class MockFunction; |
| 10107 | |
| 10108 | template <typename R> |
| 10109 | class MockFunction<R()> { |
| 10110 | public: |
| 10111 | MockFunction() {} |
| 10112 | |
| 10113 | MOCK_METHOD0_T(Call, R()); |
| 10114 | |
| 10115 | private: |
| 10116 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); |
| 10117 | }; |
| 10118 | |
| 10119 | template <typename R, typename A0> |
| 10120 | class MockFunction<R(A0)> { |
| 10121 | public: |
| 10122 | MockFunction() {} |
| 10123 | |
| 10124 | MOCK_METHOD1_T(Call, R(A0)); |
| 10125 | |
| 10126 | private: |
| 10127 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); |
| 10128 | }; |
| 10129 | |
| 10130 | template <typename R, typename A0, typename A1> |
| 10131 | class MockFunction<R(A0, A1)> { |
| 10132 | public: |
| 10133 | MockFunction() {} |
| 10134 | |
| 10135 | MOCK_METHOD2_T(Call, R(A0, A1)); |
| 10136 | |
| 10137 | private: |
| 10138 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); |
| 10139 | }; |
| 10140 | |
| 10141 | template <typename R, typename A0, typename A1, typename A2> |
| 10142 | class MockFunction<R(A0, A1, A2)> { |
| 10143 | public: |
| 10144 | MockFunction() {} |
| 10145 | |
| 10146 | MOCK_METHOD3_T(Call, R(A0, A1, A2)); |
| 10147 | |
| 10148 | private: |
| 10149 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); |
| 10150 | }; |
| 10151 | |
| 10152 | template <typename R, typename A0, typename A1, typename A2, typename A3> |
| 10153 | class MockFunction<R(A0, A1, A2, A3)> { |
| 10154 | public: |
| 10155 | MockFunction() {} |
| 10156 | |
| 10157 | MOCK_METHOD4_T(Call, R(A0, A1, A2, A3)); |
| 10158 | |
| 10159 | private: |
| 10160 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); |
| 10161 | }; |
| 10162 | |
| 10163 | template <typename R, typename A0, typename A1, typename A2, typename A3, |
| 10164 | typename A4> |
| 10165 | class MockFunction<R(A0, A1, A2, A3, A4)> { |
| 10166 | public: |
| 10167 | MockFunction() {} |
| 10168 | |
| 10169 | MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4)); |
| 10170 | |
| 10171 | private: |
| 10172 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); |
| 10173 | }; |
| 10174 | |
| 10175 | template <typename R, typename A0, typename A1, typename A2, typename A3, |
| 10176 | typename A4, typename A5> |
| 10177 | class MockFunction<R(A0, A1, A2, A3, A4, A5)> { |
| 10178 | public: |
| 10179 | MockFunction() {} |
| 10180 | |
| 10181 | MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5)); |
| 10182 | |
| 10183 | private: |
| 10184 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); |
| 10185 | }; |
| 10186 | |
| 10187 | template <typename R, typename A0, typename A1, typename A2, typename A3, |
| 10188 | typename A4, typename A5, typename A6> |
| 10189 | class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> { |
| 10190 | public: |
| 10191 | MockFunction() {} |
| 10192 | |
| 10193 | MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6)); |
| 10194 | |
| 10195 | private: |
| 10196 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); |
| 10197 | }; |
| 10198 | |
| 10199 | template <typename R, typename A0, typename A1, typename A2, typename A3, |
| 10200 | typename A4, typename A5, typename A6, typename A7> |
| 10201 | class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> { |
| 10202 | public: |
| 10203 | MockFunction() {} |
| 10204 | |
| 10205 | MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7)); |
| 10206 | |
| 10207 | private: |
| 10208 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); |
| 10209 | }; |
| 10210 | |
| 10211 | template <typename R, typename A0, typename A1, typename A2, typename A3, |
| 10212 | typename A4, typename A5, typename A6, typename A7, typename A8> |
| 10213 | class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> { |
| 10214 | public: |
| 10215 | MockFunction() {} |
| 10216 | |
| 10217 | MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8)); |
| 10218 | |
| 10219 | private: |
| 10220 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); |
| 10221 | }; |
| 10222 | |
| 10223 | template <typename R, typename A0, typename A1, typename A2, typename A3, |
| 10224 | typename A4, typename A5, typename A6, typename A7, typename A8, |
| 10225 | typename A9> |
| 10226 | class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> { |
| 10227 | public: |
| 10228 | MockFunction() {} |
| 10229 | |
| 10230 | MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)); |
| 10231 | |
| 10232 | private: |
| 10233 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); |
| 10234 | }; |
| 10235 | |
| 10236 | } // namespace testing |
| 10237 | |
| 10238 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ |
| 10239 | // This file was GENERATED by command: |
| 10240 | // pump.py gmock-generated-matchers.h.pump |
| 10241 | // DO NOT EDIT BY HAND!!! |
| 10242 | |
| 10243 | // Copyright 2008, Google Inc. |
| 10244 | // All rights reserved. |
| 10245 | // |
| 10246 | // Redistribution and use in source and binary forms, with or without |
| 10247 | // modification, are permitted provided that the following conditions are |
| 10248 | // met: |
| 10249 | // |
| 10250 | // * Redistributions of source code must retain the above copyright |
| 10251 | // notice, this list of conditions and the following disclaimer. |
| 10252 | // * Redistributions in binary form must reproduce the above |
| 10253 | // copyright notice, this list of conditions and the following disclaimer |
| 10254 | // in the documentation and/or other materials provided with the |
| 10255 | // distribution. |
| 10256 | // * Neither the name of Google Inc. nor the names of its |
| 10257 | // contributors may be used to endorse or promote products derived from |
| 10258 | // this software without specific prior written permission. |
| 10259 | // |
| 10260 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 10261 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 10262 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 10263 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 10264 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 10265 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 10266 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 10267 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 10268 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 10269 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 10270 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 10271 | |
| 10272 | // Google Mock - a framework for writing C++ mock classes. |
| 10273 | // |
| 10274 | // This file implements some commonly used variadic matchers. |
| 10275 | |
| 10276 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ |
| 10277 | #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ |
| 10278 | |
| 10279 | #include <sstream> |
| 10280 | #include <string> |
| 10281 | #include <vector> |
| 10282 | |
| 10283 | namespace testing { |
| 10284 | namespace internal { |
| 10285 | |
| 10286 | // The type of the i-th (0-based) field of Tuple. |
| 10287 | #define GMOCK_FIELD_TYPE_(Tuple, i) \ |
| 10288 | typename ::std::tr1::tuple_element<i, Tuple>::type |
| 10289 | |
| 10290 | // TupleFields<Tuple, k0, ..., kn> is for selecting fields from a |
| 10291 | // tuple of type Tuple. It has two members: |
| 10292 | // |
| 10293 | // type: a tuple type whose i-th field is the ki-th field of Tuple. |
| 10294 | // GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple. |
| 10295 | // |
| 10296 | // For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have: |
| 10297 | // |
| 10298 | // type is tuple<int, bool>, and |
| 10299 | // GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true). |
| 10300 | |
| 10301 | template <class Tuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1, |
| 10302 | int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1, |
| 10303 | int k9 = -1> |
| 10304 | class TupleFields; |
| 10305 | |
| 10306 | // This generic version is used when there are 10 selectors. |
| 10307 | template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6, |
| 10308 | int k7, int k8, int k9> |
| 10309 | class TupleFields { |
| 10310 | public: |
| 10311 | typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), |
| 10312 | GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), |
| 10313 | GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4), |
| 10314 | GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6), |
| 10315 | GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8), |
| 10316 | GMOCK_FIELD_TYPE_(Tuple, k9)> type; |
| 10317 | static type GetSelectedFields(const Tuple& t) { |
| 10318 | using ::std::tr1::get; |
| 10319 | return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t), |
| 10320 | get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t), get<k9>(t)); |
| 10321 | } |
| 10322 | }; |
| 10323 | |
| 10324 | // The following specialization is used for 0 ~ 9 selectors. |
| 10325 | |
| 10326 | template <class Tuple> |
| 10327 | class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { |
| 10328 | public: |
| 10329 | typedef ::std::tr1::tuple<> type; |
| 10330 | static type GetSelectedFields(const Tuple& /* t */) { |
| 10331 | using ::std::tr1::get; |
| 10332 | return type(); |
| 10333 | } |
| 10334 | }; |
| 10335 | |
| 10336 | template <class Tuple, int k0> |
| 10337 | class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> { |
| 10338 | public: |
| 10339 | typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type; |
| 10340 | static type GetSelectedFields(const Tuple& t) { |
| 10341 | using ::std::tr1::get; |
| 10342 | return type(get<k0>(t)); |
| 10343 | } |
| 10344 | }; |
| 10345 | |
| 10346 | template <class Tuple, int k0, int k1> |
| 10347 | class TupleFields<Tuple, k0, k1, -1, -1, -1, -1, -1, -1, -1, -1> { |
| 10348 | public: |
| 10349 | typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), |
| 10350 | GMOCK_FIELD_TYPE_(Tuple, k1)> type; |
| 10351 | static type GetSelectedFields(const Tuple& t) { |
| 10352 | using ::std::tr1::get; |
| 10353 | return type(get<k0>(t), get<k1>(t)); |
| 10354 | } |
| 10355 | }; |
| 10356 | |
| 10357 | template <class Tuple, int k0, int k1, int k2> |
| 10358 | class TupleFields<Tuple, k0, k1, k2, -1, -1, -1, -1, -1, -1, -1> { |
| 10359 | public: |
| 10360 | typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), |
| 10361 | GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2)> type; |
| 10362 | static type GetSelectedFields(const Tuple& t) { |
| 10363 | using ::std::tr1::get; |
| 10364 | return type(get<k0>(t), get<k1>(t), get<k2>(t)); |
| 10365 | } |
| 10366 | }; |
| 10367 | |
| 10368 | template <class Tuple, int k0, int k1, int k2, int k3> |
| 10369 | class TupleFields<Tuple, k0, k1, k2, k3, -1, -1, -1, -1, -1, -1> { |
| 10370 | public: |
| 10371 | typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), |
| 10372 | GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), |
| 10373 | GMOCK_FIELD_TYPE_(Tuple, k3)> type; |
| 10374 | static type GetSelectedFields(const Tuple& t) { |
| 10375 | using ::std::tr1::get; |
| 10376 | return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t)); |
| 10377 | } |
| 10378 | }; |
| 10379 | |
| 10380 | template <class Tuple, int k0, int k1, int k2, int k3, int k4> |
| 10381 | class TupleFields<Tuple, k0, k1, k2, k3, k4, -1, -1, -1, -1, -1> { |
| 10382 | public: |
| 10383 | typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), |
| 10384 | GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), |
| 10385 | GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4)> type; |
| 10386 | static type GetSelectedFields(const Tuple& t) { |
| 10387 | using ::std::tr1::get; |
| 10388 | return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t)); |
| 10389 | } |
| 10390 | }; |
| 10391 | |
| 10392 | template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5> |
| 10393 | class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, -1, -1, -1, -1> { |
| 10394 | public: |
| 10395 | typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), |
| 10396 | GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), |
| 10397 | GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4), |
| 10398 | GMOCK_FIELD_TYPE_(Tuple, k5)> type; |
| 10399 | static type GetSelectedFields(const Tuple& t) { |
| 10400 | using ::std::tr1::get; |
| 10401 | return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t), |
| 10402 | get<k5>(t)); |
| 10403 | } |
| 10404 | }; |
| 10405 | |
| 10406 | template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6> |
| 10407 | class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, -1, -1, -1> { |
| 10408 | public: |
| 10409 | typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), |
| 10410 | GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), |
| 10411 | GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4), |
| 10412 | GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6)> type; |
| 10413 | static type GetSelectedFields(const Tuple& t) { |
| 10414 | using ::std::tr1::get; |
| 10415 | return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t), |
| 10416 | get<k5>(t), get<k6>(t)); |
| 10417 | } |
| 10418 | }; |
| 10419 | |
| 10420 | template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6, |
| 10421 | int k7> |
| 10422 | class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, -1, -1> { |
| 10423 | public: |
| 10424 | typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), |
| 10425 | GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), |
| 10426 | GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4), |
| 10427 | GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6), |
| 10428 | GMOCK_FIELD_TYPE_(Tuple, k7)> type; |
| 10429 | static type GetSelectedFields(const Tuple& t) { |
| 10430 | using ::std::tr1::get; |
| 10431 | return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t), |
| 10432 | get<k5>(t), get<k6>(t), get<k7>(t)); |
| 10433 | } |
| 10434 | }; |
| 10435 | |
| 10436 | template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6, |
| 10437 | int k7, int k8> |
| 10438 | class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, -1> { |
| 10439 | public: |
| 10440 | typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), |
| 10441 | GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2), |
| 10442 | GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4), |
| 10443 | GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6), |
| 10444 | GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8)> type; |
| 10445 | static type GetSelectedFields(const Tuple& t) { |
| 10446 | using ::std::tr1::get; |
| 10447 | return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t), |
| 10448 | get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t)); |
| 10449 | } |
| 10450 | }; |
| 10451 | |
| 10452 | #undef GMOCK_FIELD_TYPE_ |
| 10453 | |
| 10454 | // Implements the Args() matcher. |
| 10455 | template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1, |
| 10456 | int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1, |
| 10457 | int k9 = -1> |
| 10458 | class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> { |
| 10459 | public: |
| 10460 | // ArgsTuple may have top-level const or reference modifiers. |
| 10461 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple; |
| 10462 | typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, |
| 10463 | k6, k7, k8, k9>::type SelectedArgs; |
| 10464 | typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher; |
| 10465 | |
| 10466 | template <typename InnerMatcher> |
| 10467 | explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) |
| 10468 | : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {} |
| 10469 | |
| 10470 | virtual bool MatchAndExplain(ArgsTuple args, |
| 10471 | MatchResultListener* listener) const { |
| 10472 | const SelectedArgs& selected_args = GetSelectedArgs(args); |
| 10473 | if (!listener->IsInterested()) |
| 10474 | return inner_matcher_.Matches(selected_args); |
| 10475 | |
| 10476 | PrintIndices(listener->stream()); |
| 10477 | *listener << "are " << PrintToString(selected_args); |
| 10478 | |
| 10479 | StringMatchResultListener inner_listener; |
| 10480 | const bool match = inner_matcher_.MatchAndExplain(selected_args, |
| 10481 | &inner_listener); |
| 10482 | PrintIfNotEmpty(inner_listener.str(), listener->stream()); |
| 10483 | return match; |
| 10484 | } |
| 10485 | |
| 10486 | virtual void DescribeTo(::std::ostream* os) const { |
| 10487 | *os << "are a tuple "; |
| 10488 | PrintIndices(os); |
| 10489 | inner_matcher_.DescribeTo(os); |
| 10490 | } |
| 10491 | |
| 10492 | virtual void DescribeNegationTo(::std::ostream* os) const { |
| 10493 | *os << "are a tuple "; |
| 10494 | PrintIndices(os); |
| 10495 | inner_matcher_.DescribeNegationTo(os); |
| 10496 | } |
| 10497 | |
| 10498 | private: |
| 10499 | static SelectedArgs GetSelectedArgs(ArgsTuple args) { |
| 10500 | return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, |
| 10501 | k9>::GetSelectedFields(args); |
| 10502 | } |
| 10503 | |
| 10504 | // Prints the indices of the selected fields. |
| 10505 | static void PrintIndices(::std::ostream* os) { |
| 10506 | *os << "whose fields ("; |
| 10507 | const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 }; |
| 10508 | for (int i = 0; i < 10; i++) { |
| 10509 | if (indices[i] < 0) |
| 10510 | break; |
| 10511 | |
| 10512 | if (i >= 1) |
| 10513 | *os << ", "; |
| 10514 | |
| 10515 | *os << "#" << indices[i]; |
| 10516 | } |
| 10517 | *os << ") "; |
| 10518 | } |
| 10519 | |
| 10520 | const MonomorphicInnerMatcher inner_matcher_; |
| 10521 | |
| 10522 | GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl); |
| 10523 | }; |
| 10524 | |
| 10525 | template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1, |
| 10526 | int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, |
| 10527 | int k8 = -1, int k9 = -1> |
| 10528 | class ArgsMatcher { |
| 10529 | public: |
| 10530 | explicit ArgsMatcher(const InnerMatcher& inner_matcher) |
| 10531 | : inner_matcher_(inner_matcher) {} |
| 10532 | |
| 10533 | template <typename ArgsTuple> |
| 10534 | operator Matcher<ArgsTuple>() const { |
| 10535 | return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k5, |
| 10536 | k6, k7, k8, k9>(inner_matcher_)); |
| 10537 | } |
| 10538 | |
| 10539 | private: |
| 10540 | const InnerMatcher inner_matcher_; |
| 10541 | |
| 10542 | GTEST_DISALLOW_ASSIGN_(ArgsMatcher); |
| 10543 | }; |
| 10544 | |
| 10545 | // Implements ElementsAre() of 1-10 arguments. |
| 10546 | |
| 10547 | template <typename T1> |
| 10548 | class ElementsAreMatcher1 { |
| 10549 | public: |
| 10550 | explicit ElementsAreMatcher1(const T1& e1) : e1_(e1) {} |
| 10551 | |
| 10552 | template <typename Container> |
| 10553 | operator Matcher<Container>() const { |
| 10554 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 10555 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 10556 | Element; |
| 10557 | |
| 10558 | // Nokia's Symbian Compiler has a nasty bug where the object put |
| 10559 | // in a one-element local array is not destructed when the array |
| 10560 | // goes out of scope. This leads to obvious badness as we've |
| 10561 | // added the linked_ptr in it to our other linked_ptrs list. |
| 10562 | // Hence we implement ElementsAreMatcher1 specially to avoid using |
| 10563 | // a local array. |
| 10564 | const Matcher<const Element&> matcher = |
| 10565 | MatcherCast<const Element&>(e1_); |
| 10566 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(&matcher, 1)); |
| 10567 | } |
| 10568 | |
| 10569 | private: |
| 10570 | const T1& e1_; |
| 10571 | |
| 10572 | GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher1); |
| 10573 | }; |
| 10574 | |
| 10575 | template <typename T1, typename T2> |
| 10576 | class ElementsAreMatcher2 { |
| 10577 | public: |
| 10578 | ElementsAreMatcher2(const T1& e1, const T2& e2) : e1_(e1), e2_(e2) {} |
| 10579 | |
| 10580 | template <typename Container> |
| 10581 | operator Matcher<Container>() const { |
| 10582 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 10583 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 10584 | Element; |
| 10585 | |
| 10586 | const Matcher<const Element&> matchers[] = { |
| 10587 | MatcherCast<const Element&>(e1_), |
| 10588 | MatcherCast<const Element&>(e2_), |
| 10589 | }; |
| 10590 | |
| 10591 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 2)); |
| 10592 | } |
| 10593 | |
| 10594 | private: |
| 10595 | const T1& e1_; |
| 10596 | const T2& e2_; |
| 10597 | |
| 10598 | GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher2); |
| 10599 | }; |
| 10600 | |
| 10601 | template <typename T1, typename T2, typename T3> |
| 10602 | class ElementsAreMatcher3 { |
| 10603 | public: |
| 10604 | ElementsAreMatcher3(const T1& e1, const T2& e2, const T3& e3) : e1_(e1), |
| 10605 | e2_(e2), e3_(e3) {} |
| 10606 | |
| 10607 | template <typename Container> |
| 10608 | operator Matcher<Container>() const { |
| 10609 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 10610 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 10611 | Element; |
| 10612 | |
| 10613 | const Matcher<const Element&> matchers[] = { |
| 10614 | MatcherCast<const Element&>(e1_), |
| 10615 | MatcherCast<const Element&>(e2_), |
| 10616 | MatcherCast<const Element&>(e3_), |
| 10617 | }; |
| 10618 | |
| 10619 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 3)); |
| 10620 | } |
| 10621 | |
| 10622 | private: |
| 10623 | const T1& e1_; |
| 10624 | const T2& e2_; |
| 10625 | const T3& e3_; |
| 10626 | |
| 10627 | GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher3); |
| 10628 | }; |
| 10629 | |
| 10630 | template <typename T1, typename T2, typename T3, typename T4> |
| 10631 | class ElementsAreMatcher4 { |
| 10632 | public: |
| 10633 | ElementsAreMatcher4(const T1& e1, const T2& e2, const T3& e3, |
| 10634 | const T4& e4) : e1_(e1), e2_(e2), e3_(e3), e4_(e4) {} |
| 10635 | |
| 10636 | template <typename Container> |
| 10637 | operator Matcher<Container>() const { |
| 10638 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 10639 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 10640 | Element; |
| 10641 | |
| 10642 | const Matcher<const Element&> matchers[] = { |
| 10643 | MatcherCast<const Element&>(e1_), |
| 10644 | MatcherCast<const Element&>(e2_), |
| 10645 | MatcherCast<const Element&>(e3_), |
| 10646 | MatcherCast<const Element&>(e4_), |
| 10647 | }; |
| 10648 | |
| 10649 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 4)); |
| 10650 | } |
| 10651 | |
| 10652 | private: |
| 10653 | const T1& e1_; |
| 10654 | const T2& e2_; |
| 10655 | const T3& e3_; |
| 10656 | const T4& e4_; |
| 10657 | |
| 10658 | GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher4); |
| 10659 | }; |
| 10660 | |
| 10661 | template <typename T1, typename T2, typename T3, typename T4, typename T5> |
| 10662 | class ElementsAreMatcher5 { |
| 10663 | public: |
| 10664 | ElementsAreMatcher5(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 10665 | const T5& e5) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5) {} |
| 10666 | |
| 10667 | template <typename Container> |
| 10668 | operator Matcher<Container>() const { |
| 10669 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 10670 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 10671 | Element; |
| 10672 | |
| 10673 | const Matcher<const Element&> matchers[] = { |
| 10674 | MatcherCast<const Element&>(e1_), |
| 10675 | MatcherCast<const Element&>(e2_), |
| 10676 | MatcherCast<const Element&>(e3_), |
| 10677 | MatcherCast<const Element&>(e4_), |
| 10678 | MatcherCast<const Element&>(e5_), |
| 10679 | }; |
| 10680 | |
| 10681 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 5)); |
| 10682 | } |
| 10683 | |
| 10684 | private: |
| 10685 | const T1& e1_; |
| 10686 | const T2& e2_; |
| 10687 | const T3& e3_; |
| 10688 | const T4& e4_; |
| 10689 | const T5& e5_; |
| 10690 | |
| 10691 | GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher5); |
| 10692 | }; |
| 10693 | |
| 10694 | template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 10695 | typename T6> |
| 10696 | class ElementsAreMatcher6 { |
| 10697 | public: |
| 10698 | ElementsAreMatcher6(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 10699 | const T5& e5, const T6& e6) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), |
| 10700 | e5_(e5), e6_(e6) {} |
| 10701 | |
| 10702 | template <typename Container> |
| 10703 | operator Matcher<Container>() const { |
| 10704 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 10705 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 10706 | Element; |
| 10707 | |
| 10708 | const Matcher<const Element&> matchers[] = { |
| 10709 | MatcherCast<const Element&>(e1_), |
| 10710 | MatcherCast<const Element&>(e2_), |
| 10711 | MatcherCast<const Element&>(e3_), |
| 10712 | MatcherCast<const Element&>(e4_), |
| 10713 | MatcherCast<const Element&>(e5_), |
| 10714 | MatcherCast<const Element&>(e6_), |
| 10715 | }; |
| 10716 | |
| 10717 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 6)); |
| 10718 | } |
| 10719 | |
| 10720 | private: |
| 10721 | const T1& e1_; |
| 10722 | const T2& e2_; |
| 10723 | const T3& e3_; |
| 10724 | const T4& e4_; |
| 10725 | const T5& e5_; |
| 10726 | const T6& e6_; |
| 10727 | |
| 10728 | GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher6); |
| 10729 | }; |
| 10730 | |
| 10731 | template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 10732 | typename T6, typename T7> |
| 10733 | class ElementsAreMatcher7 { |
| 10734 | public: |
| 10735 | ElementsAreMatcher7(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 10736 | const T5& e5, const T6& e6, const T7& e7) : e1_(e1), e2_(e2), e3_(e3), |
| 10737 | e4_(e4), e5_(e5), e6_(e6), e7_(e7) {} |
| 10738 | |
| 10739 | template <typename Container> |
| 10740 | operator Matcher<Container>() const { |
| 10741 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 10742 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 10743 | Element; |
| 10744 | |
| 10745 | const Matcher<const Element&> matchers[] = { |
| 10746 | MatcherCast<const Element&>(e1_), |
| 10747 | MatcherCast<const Element&>(e2_), |
| 10748 | MatcherCast<const Element&>(e3_), |
| 10749 | MatcherCast<const Element&>(e4_), |
| 10750 | MatcherCast<const Element&>(e5_), |
| 10751 | MatcherCast<const Element&>(e6_), |
| 10752 | MatcherCast<const Element&>(e7_), |
| 10753 | }; |
| 10754 | |
| 10755 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 7)); |
| 10756 | } |
| 10757 | |
| 10758 | private: |
| 10759 | const T1& e1_; |
| 10760 | const T2& e2_; |
| 10761 | const T3& e3_; |
| 10762 | const T4& e4_; |
| 10763 | const T5& e5_; |
| 10764 | const T6& e6_; |
| 10765 | const T7& e7_; |
| 10766 | |
| 10767 | GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher7); |
| 10768 | }; |
| 10769 | |
| 10770 | template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 10771 | typename T6, typename T7, typename T8> |
| 10772 | class ElementsAreMatcher8 { |
| 10773 | public: |
| 10774 | ElementsAreMatcher8(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 10775 | const T5& e5, const T6& e6, const T7& e7, const T8& e8) : e1_(e1), |
| 10776 | e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6), e7_(e7), e8_(e8) {} |
| 10777 | |
| 10778 | template <typename Container> |
| 10779 | operator Matcher<Container>() const { |
| 10780 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 10781 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 10782 | Element; |
| 10783 | |
| 10784 | const Matcher<const Element&> matchers[] = { |
| 10785 | MatcherCast<const Element&>(e1_), |
| 10786 | MatcherCast<const Element&>(e2_), |
| 10787 | MatcherCast<const Element&>(e3_), |
| 10788 | MatcherCast<const Element&>(e4_), |
| 10789 | MatcherCast<const Element&>(e5_), |
| 10790 | MatcherCast<const Element&>(e6_), |
| 10791 | MatcherCast<const Element&>(e7_), |
| 10792 | MatcherCast<const Element&>(e8_), |
| 10793 | }; |
| 10794 | |
| 10795 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 8)); |
| 10796 | } |
| 10797 | |
| 10798 | private: |
| 10799 | const T1& e1_; |
| 10800 | const T2& e2_; |
| 10801 | const T3& e3_; |
| 10802 | const T4& e4_; |
| 10803 | const T5& e5_; |
| 10804 | const T6& e6_; |
| 10805 | const T7& e7_; |
| 10806 | const T8& e8_; |
| 10807 | |
| 10808 | GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher8); |
| 10809 | }; |
| 10810 | |
| 10811 | template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 10812 | typename T6, typename T7, typename T8, typename T9> |
| 10813 | class ElementsAreMatcher9 { |
| 10814 | public: |
| 10815 | ElementsAreMatcher9(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 10816 | const T5& e5, const T6& e6, const T7& e7, const T8& e8, |
| 10817 | const T9& e9) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6), |
| 10818 | e7_(e7), e8_(e8), e9_(e9) {} |
| 10819 | |
| 10820 | template <typename Container> |
| 10821 | operator Matcher<Container>() const { |
| 10822 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 10823 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 10824 | Element; |
| 10825 | |
| 10826 | const Matcher<const Element&> matchers[] = { |
| 10827 | MatcherCast<const Element&>(e1_), |
| 10828 | MatcherCast<const Element&>(e2_), |
| 10829 | MatcherCast<const Element&>(e3_), |
| 10830 | MatcherCast<const Element&>(e4_), |
| 10831 | MatcherCast<const Element&>(e5_), |
| 10832 | MatcherCast<const Element&>(e6_), |
| 10833 | MatcherCast<const Element&>(e7_), |
| 10834 | MatcherCast<const Element&>(e8_), |
| 10835 | MatcherCast<const Element&>(e9_), |
| 10836 | }; |
| 10837 | |
| 10838 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 9)); |
| 10839 | } |
| 10840 | |
| 10841 | private: |
| 10842 | const T1& e1_; |
| 10843 | const T2& e2_; |
| 10844 | const T3& e3_; |
| 10845 | const T4& e4_; |
| 10846 | const T5& e5_; |
| 10847 | const T6& e6_; |
| 10848 | const T7& e7_; |
| 10849 | const T8& e8_; |
| 10850 | const T9& e9_; |
| 10851 | |
| 10852 | GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher9); |
| 10853 | }; |
| 10854 | |
| 10855 | template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 10856 | typename T6, typename T7, typename T8, typename T9, typename T10> |
| 10857 | class ElementsAreMatcher10 { |
| 10858 | public: |
| 10859 | ElementsAreMatcher10(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 10860 | const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9, |
| 10861 | const T10& e10) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6), |
| 10862 | e7_(e7), e8_(e8), e9_(e9), e10_(e10) {} |
| 10863 | |
| 10864 | template <typename Container> |
| 10865 | operator Matcher<Container>() const { |
| 10866 | typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 10867 | typedef typename internal::StlContainerView<RawContainer>::type::value_type |
| 10868 | Element; |
| 10869 | |
| 10870 | const Matcher<const Element&> matchers[] = { |
| 10871 | MatcherCast<const Element&>(e1_), |
| 10872 | MatcherCast<const Element&>(e2_), |
| 10873 | MatcherCast<const Element&>(e3_), |
| 10874 | MatcherCast<const Element&>(e4_), |
| 10875 | MatcherCast<const Element&>(e5_), |
| 10876 | MatcherCast<const Element&>(e6_), |
| 10877 | MatcherCast<const Element&>(e7_), |
| 10878 | MatcherCast<const Element&>(e8_), |
| 10879 | MatcherCast<const Element&>(e9_), |
| 10880 | MatcherCast<const Element&>(e10_), |
| 10881 | }; |
| 10882 | |
| 10883 | return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 10)); |
| 10884 | } |
| 10885 | |
| 10886 | private: |
| 10887 | const T1& e1_; |
| 10888 | const T2& e2_; |
| 10889 | const T3& e3_; |
| 10890 | const T4& e4_; |
| 10891 | const T5& e5_; |
| 10892 | const T6& e6_; |
| 10893 | const T7& e7_; |
| 10894 | const T8& e8_; |
| 10895 | const T9& e9_; |
| 10896 | const T10& e10_; |
| 10897 | |
| 10898 | GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher10); |
| 10899 | }; |
| 10900 | |
| 10901 | } // namespace internal |
| 10902 | |
| 10903 | // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected |
| 10904 | // fields of it matches a_matcher. C++ doesn't support default |
| 10905 | // arguments for function templates, so we have to overload it. |
| 10906 | template <typename InnerMatcher> |
| 10907 | inline internal::ArgsMatcher<InnerMatcher> |
| 10908 | Args(const InnerMatcher& matcher) { |
| 10909 | return internal::ArgsMatcher<InnerMatcher>(matcher); |
| 10910 | } |
| 10911 | |
| 10912 | template <int k1, typename InnerMatcher> |
| 10913 | inline internal::ArgsMatcher<InnerMatcher, k1> |
| 10914 | Args(const InnerMatcher& matcher) { |
| 10915 | return internal::ArgsMatcher<InnerMatcher, k1>(matcher); |
| 10916 | } |
| 10917 | |
| 10918 | template <int k1, int k2, typename InnerMatcher> |
| 10919 | inline internal::ArgsMatcher<InnerMatcher, k1, k2> |
| 10920 | Args(const InnerMatcher& matcher) { |
| 10921 | return internal::ArgsMatcher<InnerMatcher, k1, k2>(matcher); |
| 10922 | } |
| 10923 | |
| 10924 | template <int k1, int k2, int k3, typename InnerMatcher> |
| 10925 | inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3> |
| 10926 | Args(const InnerMatcher& matcher) { |
| 10927 | return internal::ArgsMatcher<InnerMatcher, k1, k2, k3>(matcher); |
| 10928 | } |
| 10929 | |
| 10930 | template <int k1, int k2, int k3, int k4, typename InnerMatcher> |
| 10931 | inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4> |
| 10932 | Args(const InnerMatcher& matcher) { |
| 10933 | return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>(matcher); |
| 10934 | } |
| 10935 | |
| 10936 | template <int k1, int k2, int k3, int k4, int k5, typename InnerMatcher> |
| 10937 | inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5> |
| 10938 | Args(const InnerMatcher& matcher) { |
| 10939 | return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>(matcher); |
| 10940 | } |
| 10941 | |
| 10942 | template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerMatcher> |
| 10943 | inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6> |
| 10944 | Args(const InnerMatcher& matcher) { |
| 10945 | return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>(matcher); |
| 10946 | } |
| 10947 | |
| 10948 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, |
| 10949 | typename InnerMatcher> |
| 10950 | inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7> |
| 10951 | Args(const InnerMatcher& matcher) { |
| 10952 | return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, |
| 10953 | k7>(matcher); |
| 10954 | } |
| 10955 | |
| 10956 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, |
| 10957 | typename InnerMatcher> |
| 10958 | inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8> |
| 10959 | Args(const InnerMatcher& matcher) { |
| 10960 | return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, |
| 10961 | k8>(matcher); |
| 10962 | } |
| 10963 | |
| 10964 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, |
| 10965 | int k9, typename InnerMatcher> |
| 10966 | inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9> |
| 10967 | Args(const InnerMatcher& matcher) { |
| 10968 | return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, |
| 10969 | k9>(matcher); |
| 10970 | } |
| 10971 | |
| 10972 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, |
| 10973 | int k9, int k10, typename InnerMatcher> |
| 10974 | inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9, |
| 10975 | k10> |
| 10976 | Args(const InnerMatcher& matcher) { |
| 10977 | return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, |
| 10978 | k9, k10>(matcher); |
| 10979 | } |
| 10980 | |
| 10981 | // ElementsAre(e0, e1, ..., e_n) matches an STL-style container with |
| 10982 | // (n + 1) elements, where the i-th element in the container must |
| 10983 | // match the i-th argument in the list. Each argument of |
| 10984 | // ElementsAre() can be either a value or a matcher. We support up to |
| 10985 | // 10 arguments. |
| 10986 | // |
| 10987 | // NOTE: Since ElementsAre() cares about the order of the elements, it |
| 10988 | // must not be used with containers whose elements's order is |
| 10989 | // undefined (e.g. hash_map). |
| 10990 | |
| 10991 | inline internal::ElementsAreMatcher0 ElementsAre() { |
| 10992 | return internal::ElementsAreMatcher0(); |
| 10993 | } |
| 10994 | |
| 10995 | template <typename T1> |
| 10996 | inline internal::ElementsAreMatcher1<T1> ElementsAre(const T1& e1) { |
| 10997 | return internal::ElementsAreMatcher1<T1>(e1); |
| 10998 | } |
| 10999 | |
| 11000 | template <typename T1, typename T2> |
| 11001 | inline internal::ElementsAreMatcher2<T1, T2> ElementsAre(const T1& e1, |
| 11002 | const T2& e2) { |
| 11003 | return internal::ElementsAreMatcher2<T1, T2>(e1, e2); |
| 11004 | } |
| 11005 | |
| 11006 | template <typename T1, typename T2, typename T3> |
| 11007 | inline internal::ElementsAreMatcher3<T1, T2, T3> ElementsAre(const T1& e1, |
| 11008 | const T2& e2, const T3& e3) { |
| 11009 | return internal::ElementsAreMatcher3<T1, T2, T3>(e1, e2, e3); |
| 11010 | } |
| 11011 | |
| 11012 | template <typename T1, typename T2, typename T3, typename T4> |
| 11013 | inline internal::ElementsAreMatcher4<T1, T2, T3, T4> ElementsAre(const T1& e1, |
| 11014 | const T2& e2, const T3& e3, const T4& e4) { |
| 11015 | return internal::ElementsAreMatcher4<T1, T2, T3, T4>(e1, e2, e3, e4); |
| 11016 | } |
| 11017 | |
| 11018 | template <typename T1, typename T2, typename T3, typename T4, typename T5> |
| 11019 | inline internal::ElementsAreMatcher5<T1, T2, T3, T4, |
| 11020 | T5> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 11021 | const T5& e5) { |
| 11022 | return internal::ElementsAreMatcher5<T1, T2, T3, T4, T5>(e1, e2, e3, e4, e5); |
| 11023 | } |
| 11024 | |
| 11025 | template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 11026 | typename T6> |
| 11027 | inline internal::ElementsAreMatcher6<T1, T2, T3, T4, T5, |
| 11028 | T6> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 11029 | const T5& e5, const T6& e6) { |
| 11030 | return internal::ElementsAreMatcher6<T1, T2, T3, T4, T5, T6>(e1, e2, e3, e4, |
| 11031 | e5, e6); |
| 11032 | } |
| 11033 | |
| 11034 | template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 11035 | typename T6, typename T7> |
| 11036 | inline internal::ElementsAreMatcher7<T1, T2, T3, T4, T5, T6, |
| 11037 | T7> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 11038 | const T5& e5, const T6& e6, const T7& e7) { |
| 11039 | return internal::ElementsAreMatcher7<T1, T2, T3, T4, T5, T6, T7>(e1, e2, e3, |
| 11040 | e4, e5, e6, e7); |
| 11041 | } |
| 11042 | |
| 11043 | template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 11044 | typename T6, typename T7, typename T8> |
| 11045 | inline internal::ElementsAreMatcher8<T1, T2, T3, T4, T5, T6, T7, |
| 11046 | T8> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 11047 | const T5& e5, const T6& e6, const T7& e7, const T8& e8) { |
| 11048 | return internal::ElementsAreMatcher8<T1, T2, T3, T4, T5, T6, T7, T8>(e1, e2, |
| 11049 | e3, e4, e5, e6, e7, e8); |
| 11050 | } |
| 11051 | |
| 11052 | template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 11053 | typename T6, typename T7, typename T8, typename T9> |
| 11054 | inline internal::ElementsAreMatcher9<T1, T2, T3, T4, T5, T6, T7, T8, |
| 11055 | T9> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 11056 | const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) { |
| 11057 | return internal::ElementsAreMatcher9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(e1, |
| 11058 | e2, e3, e4, e5, e6, e7, e8, e9); |
| 11059 | } |
| 11060 | |
| 11061 | template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 11062 | typename T6, typename T7, typename T8, typename T9, typename T10> |
| 11063 | inline internal::ElementsAreMatcher10<T1, T2, T3, T4, T5, T6, T7, T8, T9, |
| 11064 | T10> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, |
| 11065 | const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9, |
| 11066 | const T10& e10) { |
| 11067 | return internal::ElementsAreMatcher10<T1, T2, T3, T4, T5, T6, T7, T8, T9, |
| 11068 | T10>(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); |
| 11069 | } |
| 11070 | |
| 11071 | // ElementsAreArray(array) and ElementAreArray(array, count) are like |
| 11072 | // ElementsAre(), except that they take an array of values or |
| 11073 | // matchers. The former form infers the size of 'array', which must |
| 11074 | // be a static C-style array. In the latter form, 'array' can either |
| 11075 | // be a static array or a pointer to a dynamically created array. |
| 11076 | |
| 11077 | template <typename T> |
| 11078 | inline internal::ElementsAreArrayMatcher<T> ElementsAreArray( |
| 11079 | const T* first, size_t count) { |
| 11080 | return internal::ElementsAreArrayMatcher<T>(first, count); |
| 11081 | } |
| 11082 | |
| 11083 | template <typename T, size_t N> |
| 11084 | inline internal::ElementsAreArrayMatcher<T> |
| 11085 | ElementsAreArray(const T (&array)[N]) { |
| 11086 | return internal::ElementsAreArrayMatcher<T>(array, N); |
| 11087 | } |
| 11088 | |
| 11089 | // AllOf(m1, m2, ..., mk) matches any value that matches all of the given |
| 11090 | // sub-matchers. AllOf is called fully qualified to prevent ADL from firing. |
| 11091 | |
| 11092 | template <typename Matcher1, typename Matcher2> |
| 11093 | inline internal::BothOfMatcher<Matcher1, Matcher2> |
| 11094 | AllOf(Matcher1 m1, Matcher2 m2) { |
| 11095 | return internal::BothOfMatcher<Matcher1, Matcher2>(m1, m2); |
| 11096 | } |
| 11097 | |
| 11098 | template <typename Matcher1, typename Matcher2, typename Matcher3> |
| 11099 | inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, |
| 11100 | Matcher3> > |
| 11101 | AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) { |
| 11102 | return ::testing::AllOf(m1, ::testing::AllOf(m2, m3)); |
| 11103 | } |
| 11104 | |
| 11105 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11106 | typename Matcher4> |
| 11107 | inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, |
| 11108 | internal::BothOfMatcher<Matcher3, Matcher4> > > |
| 11109 | AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) { |
| 11110 | return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4)); |
| 11111 | } |
| 11112 | |
| 11113 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11114 | typename Matcher4, typename Matcher5> |
| 11115 | inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, |
| 11116 | internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, |
| 11117 | Matcher5> > > > |
| 11118 | AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) { |
| 11119 | return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5)); |
| 11120 | } |
| 11121 | |
| 11122 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11123 | typename Matcher4, typename Matcher5, typename Matcher6> |
| 11124 | inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, |
| 11125 | internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, |
| 11126 | internal::BothOfMatcher<Matcher5, Matcher6> > > > > |
| 11127 | AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, |
| 11128 | Matcher6 m6) { |
| 11129 | return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6)); |
| 11130 | } |
| 11131 | |
| 11132 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11133 | typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7> |
| 11134 | inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, |
| 11135 | internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, |
| 11136 | internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6, |
| 11137 | Matcher7> > > > > > |
| 11138 | AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, |
| 11139 | Matcher6 m6, Matcher7 m7) { |
| 11140 | return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7)); |
| 11141 | } |
| 11142 | |
| 11143 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11144 | typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, |
| 11145 | typename Matcher8> |
| 11146 | inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, |
| 11147 | internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, |
| 11148 | internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6, |
| 11149 | internal::BothOfMatcher<Matcher7, Matcher8> > > > > > > |
| 11150 | AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, |
| 11151 | Matcher6 m6, Matcher7 m7, Matcher8 m8) { |
| 11152 | return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8)); |
| 11153 | } |
| 11154 | |
| 11155 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11156 | typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, |
| 11157 | typename Matcher8, typename Matcher9> |
| 11158 | inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, |
| 11159 | internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, |
| 11160 | internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6, |
| 11161 | internal::BothOfMatcher<Matcher7, internal::BothOfMatcher<Matcher8, |
| 11162 | Matcher9> > > > > > > > |
| 11163 | AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, |
| 11164 | Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9) { |
| 11165 | return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8, m9)); |
| 11166 | } |
| 11167 | |
| 11168 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11169 | typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, |
| 11170 | typename Matcher8, typename Matcher9, typename Matcher10> |
| 11171 | inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, |
| 11172 | internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, |
| 11173 | internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6, |
| 11174 | internal::BothOfMatcher<Matcher7, internal::BothOfMatcher<Matcher8, |
| 11175 | internal::BothOfMatcher<Matcher9, Matcher10> > > > > > > > > |
| 11176 | AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, |
| 11177 | Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9, Matcher10 m10) { |
| 11178 | return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8, m9, |
| 11179 | m10)); |
| 11180 | } |
| 11181 | |
| 11182 | // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given |
| 11183 | // sub-matchers. AnyOf is called fully qualified to prevent ADL from firing. |
| 11184 | |
| 11185 | template <typename Matcher1, typename Matcher2> |
| 11186 | inline internal::EitherOfMatcher<Matcher1, Matcher2> |
| 11187 | AnyOf(Matcher1 m1, Matcher2 m2) { |
| 11188 | return internal::EitherOfMatcher<Matcher1, Matcher2>(m1, m2); |
| 11189 | } |
| 11190 | |
| 11191 | template <typename Matcher1, typename Matcher2, typename Matcher3> |
| 11192 | inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, |
| 11193 | Matcher3> > |
| 11194 | AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) { |
| 11195 | return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3)); |
| 11196 | } |
| 11197 | |
| 11198 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11199 | typename Matcher4> |
| 11200 | inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, |
| 11201 | internal::EitherOfMatcher<Matcher3, Matcher4> > > |
| 11202 | AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) { |
| 11203 | return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4)); |
| 11204 | } |
| 11205 | |
| 11206 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11207 | typename Matcher4, typename Matcher5> |
| 11208 | inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, |
| 11209 | internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, |
| 11210 | Matcher5> > > > |
| 11211 | AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) { |
| 11212 | return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5)); |
| 11213 | } |
| 11214 | |
| 11215 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11216 | typename Matcher4, typename Matcher5, typename Matcher6> |
| 11217 | inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, |
| 11218 | internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, |
| 11219 | internal::EitherOfMatcher<Matcher5, Matcher6> > > > > |
| 11220 | AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, |
| 11221 | Matcher6 m6) { |
| 11222 | return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6)); |
| 11223 | } |
| 11224 | |
| 11225 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11226 | typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7> |
| 11227 | inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, |
| 11228 | internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, |
| 11229 | internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6, |
| 11230 | Matcher7> > > > > > |
| 11231 | AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, |
| 11232 | Matcher6 m6, Matcher7 m7) { |
| 11233 | return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7)); |
| 11234 | } |
| 11235 | |
| 11236 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11237 | typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, |
| 11238 | typename Matcher8> |
| 11239 | inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, |
| 11240 | internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, |
| 11241 | internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6, |
| 11242 | internal::EitherOfMatcher<Matcher7, Matcher8> > > > > > > |
| 11243 | AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, |
| 11244 | Matcher6 m6, Matcher7 m7, Matcher8 m8) { |
| 11245 | return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8)); |
| 11246 | } |
| 11247 | |
| 11248 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11249 | typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, |
| 11250 | typename Matcher8, typename Matcher9> |
| 11251 | inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, |
| 11252 | internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, |
| 11253 | internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6, |
| 11254 | internal::EitherOfMatcher<Matcher7, internal::EitherOfMatcher<Matcher8, |
| 11255 | Matcher9> > > > > > > > |
| 11256 | AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, |
| 11257 | Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9) { |
| 11258 | return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8, m9)); |
| 11259 | } |
| 11260 | |
| 11261 | template <typename Matcher1, typename Matcher2, typename Matcher3, |
| 11262 | typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, |
| 11263 | typename Matcher8, typename Matcher9, typename Matcher10> |
| 11264 | inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, |
| 11265 | internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, |
| 11266 | internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6, |
| 11267 | internal::EitherOfMatcher<Matcher7, internal::EitherOfMatcher<Matcher8, |
| 11268 | internal::EitherOfMatcher<Matcher9, Matcher10> > > > > > > > > |
| 11269 | AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, |
| 11270 | Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9, Matcher10 m10) { |
| 11271 | return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8, m9, |
| 11272 | m10)); |
| 11273 | } |
| 11274 | |
| 11275 | } // namespace testing |
| 11276 | |
| 11277 | |
| 11278 | // The MATCHER* family of macros can be used in a namespace scope to |
| 11279 | // define custom matchers easily. |
| 11280 | // |
| 11281 | // Basic Usage |
| 11282 | // =========== |
| 11283 | // |
| 11284 | // The syntax |
| 11285 | // |
| 11286 | // MATCHER(name, description_string) { statements; } |
| 11287 | // |
| 11288 | // defines a matcher with the given name that executes the statements, |
| 11289 | // which must return a bool to indicate if the match succeeds. Inside |
| 11290 | // the statements, you can refer to the value being matched by 'arg', |
| 11291 | // and refer to its type by 'arg_type'. |
| 11292 | // |
| 11293 | // The description string documents what the matcher does, and is used |
| 11294 | // to generate the failure message when the match fails. Since a |
| 11295 | // MATCHER() is usually defined in a header file shared by multiple |
| 11296 | // C++ source files, we require the description to be a C-string |
| 11297 | // literal to avoid possible side effects. It can be empty, in which |
| 11298 | // case we'll use the sequence of words in the matcher name as the |
| 11299 | // description. |
| 11300 | // |
| 11301 | // For example: |
| 11302 | // |
| 11303 | // MATCHER(IsEven, "") { return (arg % 2) == 0; } |
| 11304 | // |
| 11305 | // allows you to write |
| 11306 | // |
| 11307 | // // Expects mock_foo.Bar(n) to be called where n is even. |
| 11308 | // EXPECT_CALL(mock_foo, Bar(IsEven())); |
| 11309 | // |
| 11310 | // or, |
| 11311 | // |
| 11312 | // // Verifies that the value of some_expression is even. |
| 11313 | // EXPECT_THAT(some_expression, IsEven()); |
| 11314 | // |
| 11315 | // If the above assertion fails, it will print something like: |
| 11316 | // |
| 11317 | // Value of: some_expression |
| 11318 | // Expected: is even |
| 11319 | // Actual: 7 |
| 11320 | // |
| 11321 | // where the description "is even" is automatically calculated from the |
| 11322 | // matcher name IsEven. |
| 11323 | // |
| 11324 | // Argument Type |
| 11325 | // ============= |
| 11326 | // |
| 11327 | // Note that the type of the value being matched (arg_type) is |
| 11328 | // determined by the context in which you use the matcher and is |
| 11329 | // supplied to you by the compiler, so you don't need to worry about |
| 11330 | // declaring it (nor can you). This allows the matcher to be |
| 11331 | // polymorphic. For example, IsEven() can be used to match any type |
| 11332 | // where the value of "(arg % 2) == 0" can be implicitly converted to |
| 11333 | // a bool. In the "Bar(IsEven())" example above, if method Bar() |
| 11334 | // takes an int, 'arg_type' will be int; if it takes an unsigned long, |
| 11335 | // 'arg_type' will be unsigned long; and so on. |
| 11336 | // |
| 11337 | // Parameterizing Matchers |
| 11338 | // ======================= |
| 11339 | // |
| 11340 | // Sometimes you'll want to parameterize the matcher. For that you |
| 11341 | // can use another macro: |
| 11342 | // |
| 11343 | // MATCHER_P(name, param_name, description_string) { statements; } |
| 11344 | // |
| 11345 | // For example: |
| 11346 | // |
| 11347 | // MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; } |
| 11348 | // |
| 11349 | // will allow you to write: |
| 11350 | // |
| 11351 | // EXPECT_THAT(Blah("a"), HasAbsoluteValue(n)); |
| 11352 | // |
| 11353 | // which may lead to this message (assuming n is 10): |
| 11354 | // |
| 11355 | // Value of: Blah("a") |
| 11356 | // Expected: has absolute value 10 |
| 11357 | // Actual: -9 |
| 11358 | // |
| 11359 | // Note that both the matcher description and its parameter are |
| 11360 | // printed, making the message human-friendly. |
| 11361 | // |
| 11362 | // In the matcher definition body, you can write 'foo_type' to |
| 11363 | // reference the type of a parameter named 'foo'. For example, in the |
| 11364 | // body of MATCHER_P(HasAbsoluteValue, value) above, you can write |
| 11365 | // 'value_type' to refer to the type of 'value'. |
| 11366 | // |
| 11367 | // We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to |
| 11368 | // support multi-parameter matchers. |
| 11369 | // |
| 11370 | // Describing Parameterized Matchers |
| 11371 | // ================================= |
| 11372 | // |
| 11373 | // The last argument to MATCHER*() is a string-typed expression. The |
| 11374 | // expression can reference all of the matcher's parameters and a |
| 11375 | // special bool-typed variable named 'negation'. When 'negation' is |
| 11376 | // false, the expression should evaluate to the matcher's description; |
| 11377 | // otherwise it should evaluate to the description of the negation of |
| 11378 | // the matcher. For example, |
| 11379 | // |
| 11380 | // using testing::PrintToString; |
| 11381 | // |
| 11382 | // MATCHER_P2(InClosedRange, low, hi, |
| 11383 | // string(negation ? "is not" : "is") + " in range [" + |
| 11384 | // PrintToString(low) + ", " + PrintToString(hi) + "]") { |
| 11385 | // return low <= arg && arg <= hi; |
| 11386 | // } |
| 11387 | // ... |
| 11388 | // EXPECT_THAT(3, InClosedRange(4, 6)); |
| 11389 | // EXPECT_THAT(3, Not(InClosedRange(2, 4))); |
| 11390 | // |
| 11391 | // would generate two failures that contain the text: |
| 11392 | // |
| 11393 | // Expected: is in range [4, 6] |
| 11394 | // ... |
| 11395 | // Expected: is not in range [2, 4] |
| 11396 | // |
| 11397 | // If you specify "" as the description, the failure message will |
| 11398 | // contain the sequence of words in the matcher name followed by the |
| 11399 | // parameter values printed as a tuple. For example, |
| 11400 | // |
| 11401 | // MATCHER_P2(InClosedRange, low, hi, "") { ... } |
| 11402 | // ... |
| 11403 | // EXPECT_THAT(3, InClosedRange(4, 6)); |
| 11404 | // EXPECT_THAT(3, Not(InClosedRange(2, 4))); |
| 11405 | // |
| 11406 | // would generate two failures that contain the text: |
| 11407 | // |
| 11408 | // Expected: in closed range (4, 6) |
| 11409 | // ... |
| 11410 | // Expected: not (in closed range (2, 4)) |
| 11411 | // |
| 11412 | // Types of Matcher Parameters |
| 11413 | // =========================== |
| 11414 | // |
| 11415 | // For the purpose of typing, you can view |
| 11416 | // |
| 11417 | // MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... } |
| 11418 | // |
| 11419 | // as shorthand for |
| 11420 | // |
| 11421 | // template <typename p1_type, ..., typename pk_type> |
| 11422 | // FooMatcherPk<p1_type, ..., pk_type> |
| 11423 | // Foo(p1_type p1, ..., pk_type pk) { ... } |
| 11424 | // |
| 11425 | // When you write Foo(v1, ..., vk), the compiler infers the types of |
| 11426 | // the parameters v1, ..., and vk for you. If you are not happy with |
| 11427 | // the result of the type inference, you can specify the types by |
| 11428 | // explicitly instantiating the template, as in Foo<long, bool>(5, |
| 11429 | // false). As said earlier, you don't get to (or need to) specify |
| 11430 | // 'arg_type' as that's determined by the context in which the matcher |
| 11431 | // is used. You can assign the result of expression Foo(p1, ..., pk) |
| 11432 | // to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This |
| 11433 | // can be useful when composing matchers. |
| 11434 | // |
| 11435 | // While you can instantiate a matcher template with reference types, |
| 11436 | // passing the parameters by pointer usually makes your code more |
| 11437 | // readable. If, however, you still want to pass a parameter by |
| 11438 | // reference, be aware that in the failure message generated by the |
| 11439 | // matcher you will see the value of the referenced object but not its |
| 11440 | // address. |
| 11441 | // |
| 11442 | // Explaining Match Results |
| 11443 | // ======================== |
| 11444 | // |
| 11445 | // Sometimes the matcher description alone isn't enough to explain why |
| 11446 | // the match has failed or succeeded. For example, when expecting a |
| 11447 | // long string, it can be very helpful to also print the diff between |
| 11448 | // the expected string and the actual one. To achieve that, you can |
| 11449 | // optionally stream additional information to a special variable |
| 11450 | // named result_listener, whose type is a pointer to class |
| 11451 | // MatchResultListener: |
| 11452 | // |
| 11453 | // MATCHER_P(EqualsLongString, str, "") { |
| 11454 | // if (arg == str) return true; |
| 11455 | // |
| 11456 | // *result_listener << "the difference: " |
| 11457 | /// << DiffStrings(str, arg); |
| 11458 | // return false; |
| 11459 | // } |
| 11460 | // |
| 11461 | // Overloading Matchers |
| 11462 | // ==================== |
| 11463 | // |
| 11464 | // You can overload matchers with different numbers of parameters: |
| 11465 | // |
| 11466 | // MATCHER_P(Blah, a, description_string1) { ... } |
| 11467 | // MATCHER_P2(Blah, a, b, description_string2) { ... } |
| 11468 | // |
| 11469 | // Caveats |
| 11470 | // ======= |
| 11471 | // |
| 11472 | // When defining a new matcher, you should also consider implementing |
| 11473 | // MatcherInterface or using MakePolymorphicMatcher(). These |
| 11474 | // approaches require more work than the MATCHER* macros, but also |
| 11475 | // give you more control on the types of the value being matched and |
| 11476 | // the matcher parameters, which may leads to better compiler error |
| 11477 | // messages when the matcher is used wrong. They also allow |
| 11478 | // overloading matchers based on parameter types (as opposed to just |
| 11479 | // based on the number of parameters). |
| 11480 | // |
| 11481 | // MATCHER*() can only be used in a namespace scope. The reason is |
| 11482 | // that C++ doesn't yet allow function-local types to be used to |
| 11483 | // instantiate templates. The up-coming C++0x standard will fix this. |
| 11484 | // Once that's done, we'll consider supporting using MATCHER*() inside |
| 11485 | // a function. |
| 11486 | // |
| 11487 | // More Information |
| 11488 | // ================ |
| 11489 | // |
| 11490 | // To learn more about using these macros, please search for 'MATCHER' |
| 11491 | // on http://code.google.com/p/googlemock/wiki/CookBook. |
| 11492 | |
| 11493 | #define MATCHER(name, description)\ |
| 11494 | class name##Matcher {\ |
| 11495 | public:\ |
| 11496 | template <typename arg_type>\ |
| 11497 | class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 11498 | public:\ |
| 11499 | gmock_Impl()\ |
| 11500 | {}\ |
| 11501 | virtual bool MatchAndExplain(\ |
| 11502 | arg_type arg, ::testing::MatchResultListener* result_listener) const;\ |
| 11503 | virtual void DescribeTo(::std::ostream* gmock_os) const {\ |
| 11504 | *gmock_os << FormatDescription(false);\ |
| 11505 | }\ |
| 11506 | virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ |
| 11507 | *gmock_os << FormatDescription(true);\ |
| 11508 | }\ |
| 11509 | private:\ |
| 11510 | ::testing::internal::string FormatDescription(bool negation) const {\ |
| 11511 | const ::testing::internal::string gmock_description = (description);\ |
| 11512 | if (!gmock_description.empty())\ |
| 11513 | return gmock_description;\ |
| 11514 | return ::testing::internal::FormatMatcherDescription(\ |
| 11515 | negation, #name,\ |
| 11516 | ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ |
| 11517 | ::std::tr1::tuple<>()));\ |
| 11518 | }\ |
| 11519 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 11520 | };\ |
| 11521 | template <typename arg_type>\ |
| 11522 | operator ::testing::Matcher<arg_type>() const {\ |
| 11523 | return ::testing::Matcher<arg_type>(\ |
| 11524 | new gmock_Impl<arg_type>());\ |
| 11525 | }\ |
| 11526 | name##Matcher() {\ |
| 11527 | }\ |
| 11528 | private:\ |
| 11529 | GTEST_DISALLOW_ASSIGN_(name##Matcher);\ |
| 11530 | };\ |
| 11531 | inline name##Matcher name() {\ |
| 11532 | return name##Matcher();\ |
| 11533 | }\ |
| 11534 | template <typename arg_type>\ |
| 11535 | bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\ |
| 11536 | arg_type arg,\ |
| 11537 | ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ |
| 11538 | const |
| 11539 | |
| 11540 | #define MATCHER_P(name, p0, description)\ |
| 11541 | template <typename p0##_type>\ |
| 11542 | class name##MatcherP {\ |
| 11543 | public:\ |
| 11544 | template <typename arg_type>\ |
| 11545 | class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 11546 | public:\ |
| 11547 | explicit gmock_Impl(p0##_type gmock_p0)\ |
| 11548 | : p0(gmock_p0) {}\ |
| 11549 | virtual bool MatchAndExplain(\ |
| 11550 | arg_type arg, ::testing::MatchResultListener* result_listener) const;\ |
| 11551 | virtual void DescribeTo(::std::ostream* gmock_os) const {\ |
| 11552 | *gmock_os << FormatDescription(false);\ |
| 11553 | }\ |
| 11554 | virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ |
| 11555 | *gmock_os << FormatDescription(true);\ |
| 11556 | }\ |
| 11557 | p0##_type p0;\ |
| 11558 | private:\ |
| 11559 | ::testing::internal::string FormatDescription(bool negation) const {\ |
| 11560 | const ::testing::internal::string gmock_description = (description);\ |
| 11561 | if (!gmock_description.empty())\ |
| 11562 | return gmock_description;\ |
| 11563 | return ::testing::internal::FormatMatcherDescription(\ |
| 11564 | negation, #name,\ |
| 11565 | ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ |
| 11566 | ::std::tr1::tuple<p0##_type>(p0)));\ |
| 11567 | }\ |
| 11568 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 11569 | };\ |
| 11570 | template <typename arg_type>\ |
| 11571 | operator ::testing::Matcher<arg_type>() const {\ |
| 11572 | return ::testing::Matcher<arg_type>(\ |
| 11573 | new gmock_Impl<arg_type>(p0));\ |
| 11574 | }\ |
| 11575 | name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\ |
| 11576 | }\ |
| 11577 | p0##_type p0;\ |
| 11578 | private:\ |
| 11579 | GTEST_DISALLOW_ASSIGN_(name##MatcherP);\ |
| 11580 | };\ |
| 11581 | template <typename p0##_type>\ |
| 11582 | inline name##MatcherP<p0##_type> name(p0##_type p0) {\ |
| 11583 | return name##MatcherP<p0##_type>(p0);\ |
| 11584 | }\ |
| 11585 | template <typename p0##_type>\ |
| 11586 | template <typename arg_type>\ |
| 11587 | bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ |
| 11588 | arg_type arg,\ |
| 11589 | ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ |
| 11590 | const |
| 11591 | |
| 11592 | #define MATCHER_P2(name, p0, p1, description)\ |
| 11593 | template <typename p0##_type, typename p1##_type>\ |
| 11594 | class name##MatcherP2 {\ |
| 11595 | public:\ |
| 11596 | template <typename arg_type>\ |
| 11597 | class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 11598 | public:\ |
| 11599 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\ |
| 11600 | : p0(gmock_p0), p1(gmock_p1) {}\ |
| 11601 | virtual bool MatchAndExplain(\ |
| 11602 | arg_type arg, ::testing::MatchResultListener* result_listener) const;\ |
| 11603 | virtual void DescribeTo(::std::ostream* gmock_os) const {\ |
| 11604 | *gmock_os << FormatDescription(false);\ |
| 11605 | }\ |
| 11606 | virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ |
| 11607 | *gmock_os << FormatDescription(true);\ |
| 11608 | }\ |
| 11609 | p0##_type p0;\ |
| 11610 | p1##_type p1;\ |
| 11611 | private:\ |
| 11612 | ::testing::internal::string FormatDescription(bool negation) const {\ |
| 11613 | const ::testing::internal::string gmock_description = (description);\ |
| 11614 | if (!gmock_description.empty())\ |
| 11615 | return gmock_description;\ |
| 11616 | return ::testing::internal::FormatMatcherDescription(\ |
| 11617 | negation, #name,\ |
| 11618 | ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ |
| 11619 | ::std::tr1::tuple<p0##_type, p1##_type>(p0, p1)));\ |
| 11620 | }\ |
| 11621 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 11622 | };\ |
| 11623 | template <typename arg_type>\ |
| 11624 | operator ::testing::Matcher<arg_type>() const {\ |
| 11625 | return ::testing::Matcher<arg_type>(\ |
| 11626 | new gmock_Impl<arg_type>(p0, p1));\ |
| 11627 | }\ |
| 11628 | name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ |
| 11629 | p1(gmock_p1) {\ |
| 11630 | }\ |
| 11631 | p0##_type p0;\ |
| 11632 | p1##_type p1;\ |
| 11633 | private:\ |
| 11634 | GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\ |
| 11635 | };\ |
| 11636 | template <typename p0##_type, typename p1##_type>\ |
| 11637 | inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \ |
| 11638 | p1##_type p1) {\ |
| 11639 | return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\ |
| 11640 | }\ |
| 11641 | template <typename p0##_type, typename p1##_type>\ |
| 11642 | template <typename arg_type>\ |
| 11643 | bool name##MatcherP2<p0##_type, \ |
| 11644 | p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ |
| 11645 | arg_type arg,\ |
| 11646 | ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ |
| 11647 | const |
| 11648 | |
| 11649 | #define MATCHER_P3(name, p0, p1, p2, description)\ |
| 11650 | template <typename p0##_type, typename p1##_type, typename p2##_type>\ |
| 11651 | class name##MatcherP3 {\ |
| 11652 | public:\ |
| 11653 | template <typename arg_type>\ |
| 11654 | class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 11655 | public:\ |
| 11656 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\ |
| 11657 | : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ |
| 11658 | virtual bool MatchAndExplain(\ |
| 11659 | arg_type arg, ::testing::MatchResultListener* result_listener) const;\ |
| 11660 | virtual void DescribeTo(::std::ostream* gmock_os) const {\ |
| 11661 | *gmock_os << FormatDescription(false);\ |
| 11662 | }\ |
| 11663 | virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ |
| 11664 | *gmock_os << FormatDescription(true);\ |
| 11665 | }\ |
| 11666 | p0##_type p0;\ |
| 11667 | p1##_type p1;\ |
| 11668 | p2##_type p2;\ |
| 11669 | private:\ |
| 11670 | ::testing::internal::string FormatDescription(bool negation) const {\ |
| 11671 | const ::testing::internal::string gmock_description = (description);\ |
| 11672 | if (!gmock_description.empty())\ |
| 11673 | return gmock_description;\ |
| 11674 | return ::testing::internal::FormatMatcherDescription(\ |
| 11675 | negation, #name,\ |
| 11676 | ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ |
| 11677 | ::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \ |
| 11678 | p2)));\ |
| 11679 | }\ |
| 11680 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 11681 | };\ |
| 11682 | template <typename arg_type>\ |
| 11683 | operator ::testing::Matcher<arg_type>() const {\ |
| 11684 | return ::testing::Matcher<arg_type>(\ |
| 11685 | new gmock_Impl<arg_type>(p0, p1, p2));\ |
| 11686 | }\ |
| 11687 | name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 11688 | p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\ |
| 11689 | }\ |
| 11690 | p0##_type p0;\ |
| 11691 | p1##_type p1;\ |
| 11692 | p2##_type p2;\ |
| 11693 | private:\ |
| 11694 | GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\ |
| 11695 | };\ |
| 11696 | template <typename p0##_type, typename p1##_type, typename p2##_type>\ |
| 11697 | inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \ |
| 11698 | p1##_type p1, p2##_type p2) {\ |
| 11699 | return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\ |
| 11700 | }\ |
| 11701 | template <typename p0##_type, typename p1##_type, typename p2##_type>\ |
| 11702 | template <typename arg_type>\ |
| 11703 | bool name##MatcherP3<p0##_type, p1##_type, \ |
| 11704 | p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ |
| 11705 | arg_type arg,\ |
| 11706 | ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ |
| 11707 | const |
| 11708 | |
| 11709 | #define MATCHER_P4(name, p0, p1, p2, p3, description)\ |
| 11710 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 11711 | typename p3##_type>\ |
| 11712 | class name##MatcherP4 {\ |
| 11713 | public:\ |
| 11714 | template <typename arg_type>\ |
| 11715 | class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 11716 | public:\ |
| 11717 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 11718 | p3##_type gmock_p3)\ |
| 11719 | : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\ |
| 11720 | virtual bool MatchAndExplain(\ |
| 11721 | arg_type arg, ::testing::MatchResultListener* result_listener) const;\ |
| 11722 | virtual void DescribeTo(::std::ostream* gmock_os) const {\ |
| 11723 | *gmock_os << FormatDescription(false);\ |
| 11724 | }\ |
| 11725 | virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ |
| 11726 | *gmock_os << FormatDescription(true);\ |
| 11727 | }\ |
| 11728 | p0##_type p0;\ |
| 11729 | p1##_type p1;\ |
| 11730 | p2##_type p2;\ |
| 11731 | p3##_type p3;\ |
| 11732 | private:\ |
| 11733 | ::testing::internal::string FormatDescription(bool negation) const {\ |
| 11734 | const ::testing::internal::string gmock_description = (description);\ |
| 11735 | if (!gmock_description.empty())\ |
| 11736 | return gmock_description;\ |
| 11737 | return ::testing::internal::FormatMatcherDescription(\ |
| 11738 | negation, #name,\ |
| 11739 | ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ |
| 11740 | ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \ |
| 11741 | p3##_type>(p0, p1, p2, p3)));\ |
| 11742 | }\ |
| 11743 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 11744 | };\ |
| 11745 | template <typename arg_type>\ |
| 11746 | operator ::testing::Matcher<arg_type>() const {\ |
| 11747 | return ::testing::Matcher<arg_type>(\ |
| 11748 | new gmock_Impl<arg_type>(p0, p1, p2, p3));\ |
| 11749 | }\ |
| 11750 | name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 11751 | p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ |
| 11752 | p2(gmock_p2), p3(gmock_p3) {\ |
| 11753 | }\ |
| 11754 | p0##_type p0;\ |
| 11755 | p1##_type p1;\ |
| 11756 | p2##_type p2;\ |
| 11757 | p3##_type p3;\ |
| 11758 | private:\ |
| 11759 | GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\ |
| 11760 | };\ |
| 11761 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 11762 | typename p3##_type>\ |
| 11763 | inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \ |
| 11764 | p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ |
| 11765 | p3##_type p3) {\ |
| 11766 | return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \ |
| 11767 | p1, p2, p3);\ |
| 11768 | }\ |
| 11769 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 11770 | typename p3##_type>\ |
| 11771 | template <typename arg_type>\ |
| 11772 | bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \ |
| 11773 | p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ |
| 11774 | arg_type arg,\ |
| 11775 | ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ |
| 11776 | const |
| 11777 | |
| 11778 | #define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\ |
| 11779 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 11780 | typename p3##_type, typename p4##_type>\ |
| 11781 | class name##MatcherP5 {\ |
| 11782 | public:\ |
| 11783 | template <typename arg_type>\ |
| 11784 | class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 11785 | public:\ |
| 11786 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 11787 | p3##_type gmock_p3, p4##_type gmock_p4)\ |
| 11788 | : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ |
| 11789 | p4(gmock_p4) {}\ |
| 11790 | virtual bool MatchAndExplain(\ |
| 11791 | arg_type arg, ::testing::MatchResultListener* result_listener) const;\ |
| 11792 | virtual void DescribeTo(::std::ostream* gmock_os) const {\ |
| 11793 | *gmock_os << FormatDescription(false);\ |
| 11794 | }\ |
| 11795 | virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ |
| 11796 | *gmock_os << FormatDescription(true);\ |
| 11797 | }\ |
| 11798 | p0##_type p0;\ |
| 11799 | p1##_type p1;\ |
| 11800 | p2##_type p2;\ |
| 11801 | p3##_type p3;\ |
| 11802 | p4##_type p4;\ |
| 11803 | private:\ |
| 11804 | ::testing::internal::string FormatDescription(bool negation) const {\ |
| 11805 | const ::testing::internal::string gmock_description = (description);\ |
| 11806 | if (!gmock_description.empty())\ |
| 11807 | return gmock_description;\ |
| 11808 | return ::testing::internal::FormatMatcherDescription(\ |
| 11809 | negation, #name,\ |
| 11810 | ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ |
| 11811 | ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 11812 | p4##_type>(p0, p1, p2, p3, p4)));\ |
| 11813 | }\ |
| 11814 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 11815 | };\ |
| 11816 | template <typename arg_type>\ |
| 11817 | operator ::testing::Matcher<arg_type>() const {\ |
| 11818 | return ::testing::Matcher<arg_type>(\ |
| 11819 | new gmock_Impl<arg_type>(p0, p1, p2, p3, p4));\ |
| 11820 | }\ |
| 11821 | name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 11822 | p2##_type gmock_p2, p3##_type gmock_p3, \ |
| 11823 | p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 11824 | p3(gmock_p3), p4(gmock_p4) {\ |
| 11825 | }\ |
| 11826 | p0##_type p0;\ |
| 11827 | p1##_type p1;\ |
| 11828 | p2##_type p2;\ |
| 11829 | p3##_type p3;\ |
| 11830 | p4##_type p4;\ |
| 11831 | private:\ |
| 11832 | GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\ |
| 11833 | };\ |
| 11834 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 11835 | typename p3##_type, typename p4##_type>\ |
| 11836 | inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 11837 | p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
| 11838 | p4##_type p4) {\ |
| 11839 | return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 11840 | p4##_type>(p0, p1, p2, p3, p4);\ |
| 11841 | }\ |
| 11842 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 11843 | typename p3##_type, typename p4##_type>\ |
| 11844 | template <typename arg_type>\ |
| 11845 | bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 11846 | p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ |
| 11847 | arg_type arg,\ |
| 11848 | ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ |
| 11849 | const |
| 11850 | |
| 11851 | #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\ |
| 11852 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 11853 | typename p3##_type, typename p4##_type, typename p5##_type>\ |
| 11854 | class name##MatcherP6 {\ |
| 11855 | public:\ |
| 11856 | template <typename arg_type>\ |
| 11857 | class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 11858 | public:\ |
| 11859 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 11860 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\ |
| 11861 | : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ |
| 11862 | p4(gmock_p4), p5(gmock_p5) {}\ |
| 11863 | virtual bool MatchAndExplain(\ |
| 11864 | arg_type arg, ::testing::MatchResultListener* result_listener) const;\ |
| 11865 | virtual void DescribeTo(::std::ostream* gmock_os) const {\ |
| 11866 | *gmock_os << FormatDescription(false);\ |
| 11867 | }\ |
| 11868 | virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ |
| 11869 | *gmock_os << FormatDescription(true);\ |
| 11870 | }\ |
| 11871 | p0##_type p0;\ |
| 11872 | p1##_type p1;\ |
| 11873 | p2##_type p2;\ |
| 11874 | p3##_type p3;\ |
| 11875 | p4##_type p4;\ |
| 11876 | p5##_type p5;\ |
| 11877 | private:\ |
| 11878 | ::testing::internal::string FormatDescription(bool negation) const {\ |
| 11879 | const ::testing::internal::string gmock_description = (description);\ |
| 11880 | if (!gmock_description.empty())\ |
| 11881 | return gmock_description;\ |
| 11882 | return ::testing::internal::FormatMatcherDescription(\ |
| 11883 | negation, #name,\ |
| 11884 | ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ |
| 11885 | ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 11886 | p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\ |
| 11887 | }\ |
| 11888 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 11889 | };\ |
| 11890 | template <typename arg_type>\ |
| 11891 | operator ::testing::Matcher<arg_type>() const {\ |
| 11892 | return ::testing::Matcher<arg_type>(\ |
| 11893 | new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5));\ |
| 11894 | }\ |
| 11895 | name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 11896 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 11897 | p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 11898 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\ |
| 11899 | }\ |
| 11900 | p0##_type p0;\ |
| 11901 | p1##_type p1;\ |
| 11902 | p2##_type p2;\ |
| 11903 | p3##_type p3;\ |
| 11904 | p4##_type p4;\ |
| 11905 | p5##_type p5;\ |
| 11906 | private:\ |
| 11907 | GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\ |
| 11908 | };\ |
| 11909 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 11910 | typename p3##_type, typename p4##_type, typename p5##_type>\ |
| 11911 | inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 11912 | p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ |
| 11913 | p3##_type p3, p4##_type p4, p5##_type p5) {\ |
| 11914 | return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 11915 | p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\ |
| 11916 | }\ |
| 11917 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 11918 | typename p3##_type, typename p4##_type, typename p5##_type>\ |
| 11919 | template <typename arg_type>\ |
| 11920 | bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 11921 | p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ |
| 11922 | arg_type arg,\ |
| 11923 | ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ |
| 11924 | const |
| 11925 | |
| 11926 | #define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\ |
| 11927 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 11928 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 11929 | typename p6##_type>\ |
| 11930 | class name##MatcherP7 {\ |
| 11931 | public:\ |
| 11932 | template <typename arg_type>\ |
| 11933 | class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 11934 | public:\ |
| 11935 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 11936 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 11937 | p6##_type gmock_p6)\ |
| 11938 | : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ |
| 11939 | p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ |
| 11940 | virtual bool MatchAndExplain(\ |
| 11941 | arg_type arg, ::testing::MatchResultListener* result_listener) const;\ |
| 11942 | virtual void DescribeTo(::std::ostream* gmock_os) const {\ |
| 11943 | *gmock_os << FormatDescription(false);\ |
| 11944 | }\ |
| 11945 | virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ |
| 11946 | *gmock_os << FormatDescription(true);\ |
| 11947 | }\ |
| 11948 | p0##_type p0;\ |
| 11949 | p1##_type p1;\ |
| 11950 | p2##_type p2;\ |
| 11951 | p3##_type p3;\ |
| 11952 | p4##_type p4;\ |
| 11953 | p5##_type p5;\ |
| 11954 | p6##_type p6;\ |
| 11955 | private:\ |
| 11956 | ::testing::internal::string FormatDescription(bool negation) const {\ |
| 11957 | const ::testing::internal::string gmock_description = (description);\ |
| 11958 | if (!gmock_description.empty())\ |
| 11959 | return gmock_description;\ |
| 11960 | return ::testing::internal::FormatMatcherDescription(\ |
| 11961 | negation, #name,\ |
| 11962 | ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ |
| 11963 | ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 11964 | p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \ |
| 11965 | p6)));\ |
| 11966 | }\ |
| 11967 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 11968 | };\ |
| 11969 | template <typename arg_type>\ |
| 11970 | operator ::testing::Matcher<arg_type>() const {\ |
| 11971 | return ::testing::Matcher<arg_type>(\ |
| 11972 | new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6));\ |
| 11973 | }\ |
| 11974 | name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 11975 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 11976 | p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \ |
| 11977 | p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ |
| 11978 | p6(gmock_p6) {\ |
| 11979 | }\ |
| 11980 | p0##_type p0;\ |
| 11981 | p1##_type p1;\ |
| 11982 | p2##_type p2;\ |
| 11983 | p3##_type p3;\ |
| 11984 | p4##_type p4;\ |
| 11985 | p5##_type p5;\ |
| 11986 | p6##_type p6;\ |
| 11987 | private:\ |
| 11988 | GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\ |
| 11989 | };\ |
| 11990 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 11991 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 11992 | typename p6##_type>\ |
| 11993 | inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 11994 | p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \ |
| 11995 | p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ |
| 11996 | p6##_type p6) {\ |
| 11997 | return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 11998 | p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\ |
| 11999 | }\ |
| 12000 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 12001 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 12002 | typename p6##_type>\ |
| 12003 | template <typename arg_type>\ |
| 12004 | bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 12005 | p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ |
| 12006 | arg_type arg,\ |
| 12007 | ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ |
| 12008 | const |
| 12009 | |
| 12010 | #define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\ |
| 12011 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 12012 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 12013 | typename p6##_type, typename p7##_type>\ |
| 12014 | class name##MatcherP8 {\ |
| 12015 | public:\ |
| 12016 | template <typename arg_type>\ |
| 12017 | class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 12018 | public:\ |
| 12019 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 12020 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 12021 | p6##_type gmock_p6, p7##_type gmock_p7)\ |
| 12022 | : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ |
| 12023 | p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\ |
| 12024 | virtual bool MatchAndExplain(\ |
| 12025 | arg_type arg, ::testing::MatchResultListener* result_listener) const;\ |
| 12026 | virtual void DescribeTo(::std::ostream* gmock_os) const {\ |
| 12027 | *gmock_os << FormatDescription(false);\ |
| 12028 | }\ |
| 12029 | virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ |
| 12030 | *gmock_os << FormatDescription(true);\ |
| 12031 | }\ |
| 12032 | p0##_type p0;\ |
| 12033 | p1##_type p1;\ |
| 12034 | p2##_type p2;\ |
| 12035 | p3##_type p3;\ |
| 12036 | p4##_type p4;\ |
| 12037 | p5##_type p5;\ |
| 12038 | p6##_type p6;\ |
| 12039 | p7##_type p7;\ |
| 12040 | private:\ |
| 12041 | ::testing::internal::string FormatDescription(bool negation) const {\ |
| 12042 | const ::testing::internal::string gmock_description = (description);\ |
| 12043 | if (!gmock_description.empty())\ |
| 12044 | return gmock_description;\ |
| 12045 | return ::testing::internal::FormatMatcherDescription(\ |
| 12046 | negation, #name,\ |
| 12047 | ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ |
| 12048 | ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 12049 | p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \ |
| 12050 | p3, p4, p5, p6, p7)));\ |
| 12051 | }\ |
| 12052 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 12053 | };\ |
| 12054 | template <typename arg_type>\ |
| 12055 | operator ::testing::Matcher<arg_type>() const {\ |
| 12056 | return ::testing::Matcher<arg_type>(\ |
| 12057 | new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7));\ |
| 12058 | }\ |
| 12059 | name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 12060 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 12061 | p5##_type gmock_p5, p6##_type gmock_p6, \ |
| 12062 | p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 12063 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ |
| 12064 | p7(gmock_p7) {\ |
| 12065 | }\ |
| 12066 | p0##_type p0;\ |
| 12067 | p1##_type p1;\ |
| 12068 | p2##_type p2;\ |
| 12069 | p3##_type p3;\ |
| 12070 | p4##_type p4;\ |
| 12071 | p5##_type p5;\ |
| 12072 | p6##_type p6;\ |
| 12073 | p7##_type p7;\ |
| 12074 | private:\ |
| 12075 | GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\ |
| 12076 | };\ |
| 12077 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 12078 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 12079 | typename p6##_type, typename p7##_type>\ |
| 12080 | inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 12081 | p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \ |
| 12082 | p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ |
| 12083 | p6##_type p6, p7##_type p7) {\ |
| 12084 | return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 12085 | p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \ |
| 12086 | p6, p7);\ |
| 12087 | }\ |
| 12088 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 12089 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 12090 | typename p6##_type, typename p7##_type>\ |
| 12091 | template <typename arg_type>\ |
| 12092 | bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 12093 | p5##_type, p6##_type, \ |
| 12094 | p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ |
| 12095 | arg_type arg,\ |
| 12096 | ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ |
| 12097 | const |
| 12098 | |
| 12099 | #define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\ |
| 12100 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 12101 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 12102 | typename p6##_type, typename p7##_type, typename p8##_type>\ |
| 12103 | class name##MatcherP9 {\ |
| 12104 | public:\ |
| 12105 | template <typename arg_type>\ |
| 12106 | class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 12107 | public:\ |
| 12108 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 12109 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 12110 | p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\ |
| 12111 | : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ |
| 12112 | p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ |
| 12113 | p8(gmock_p8) {}\ |
| 12114 | virtual bool MatchAndExplain(\ |
| 12115 | arg_type arg, ::testing::MatchResultListener* result_listener) const;\ |
| 12116 | virtual void DescribeTo(::std::ostream* gmock_os) const {\ |
| 12117 | *gmock_os << FormatDescription(false);\ |
| 12118 | }\ |
| 12119 | virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ |
| 12120 | *gmock_os << FormatDescription(true);\ |
| 12121 | }\ |
| 12122 | p0##_type p0;\ |
| 12123 | p1##_type p1;\ |
| 12124 | p2##_type p2;\ |
| 12125 | p3##_type p3;\ |
| 12126 | p4##_type p4;\ |
| 12127 | p5##_type p5;\ |
| 12128 | p6##_type p6;\ |
| 12129 | p7##_type p7;\ |
| 12130 | p8##_type p8;\ |
| 12131 | private:\ |
| 12132 | ::testing::internal::string FormatDescription(bool negation) const {\ |
| 12133 | const ::testing::internal::string gmock_description = (description);\ |
| 12134 | if (!gmock_description.empty())\ |
| 12135 | return gmock_description;\ |
| 12136 | return ::testing::internal::FormatMatcherDescription(\ |
| 12137 | negation, #name,\ |
| 12138 | ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ |
| 12139 | ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 12140 | p4##_type, p5##_type, p6##_type, p7##_type, \ |
| 12141 | p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\ |
| 12142 | }\ |
| 12143 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 12144 | };\ |
| 12145 | template <typename arg_type>\ |
| 12146 | operator ::testing::Matcher<arg_type>() const {\ |
| 12147 | return ::testing::Matcher<arg_type>(\ |
| 12148 | new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\ |
| 12149 | }\ |
| 12150 | name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 12151 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 12152 | p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ |
| 12153 | p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 12154 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ |
| 12155 | p8(gmock_p8) {\ |
| 12156 | }\ |
| 12157 | p0##_type p0;\ |
| 12158 | p1##_type p1;\ |
| 12159 | p2##_type p2;\ |
| 12160 | p3##_type p3;\ |
| 12161 | p4##_type p4;\ |
| 12162 | p5##_type p5;\ |
| 12163 | p6##_type p6;\ |
| 12164 | p7##_type p7;\ |
| 12165 | p8##_type p8;\ |
| 12166 | private:\ |
| 12167 | GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\ |
| 12168 | };\ |
| 12169 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 12170 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 12171 | typename p6##_type, typename p7##_type, typename p8##_type>\ |
| 12172 | inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 12173 | p4##_type, p5##_type, p6##_type, p7##_type, \ |
| 12174 | p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
| 12175 | p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ |
| 12176 | p8##_type p8) {\ |
| 12177 | return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 12178 | p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \ |
| 12179 | p3, p4, p5, p6, p7, p8);\ |
| 12180 | }\ |
| 12181 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 12182 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 12183 | typename p6##_type, typename p7##_type, typename p8##_type>\ |
| 12184 | template <typename arg_type>\ |
| 12185 | bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 12186 | p5##_type, p6##_type, p7##_type, \ |
| 12187 | p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ |
| 12188 | arg_type arg,\ |
| 12189 | ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ |
| 12190 | const |
| 12191 | |
| 12192 | #define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\ |
| 12193 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 12194 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 12195 | typename p6##_type, typename p7##_type, typename p8##_type, \ |
| 12196 | typename p9##_type>\ |
| 12197 | class name##MatcherP10 {\ |
| 12198 | public:\ |
| 12199 | template <typename arg_type>\ |
| 12200 | class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 12201 | public:\ |
| 12202 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 12203 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 12204 | p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ |
| 12205 | p9##_type gmock_p9)\ |
| 12206 | : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ |
| 12207 | p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ |
| 12208 | p8(gmock_p8), p9(gmock_p9) {}\ |
| 12209 | virtual bool MatchAndExplain(\ |
| 12210 | arg_type arg, ::testing::MatchResultListener* result_listener) const;\ |
| 12211 | virtual void DescribeTo(::std::ostream* gmock_os) const {\ |
| 12212 | *gmock_os << FormatDescription(false);\ |
| 12213 | }\ |
| 12214 | virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ |
| 12215 | *gmock_os << FormatDescription(true);\ |
| 12216 | }\ |
| 12217 | p0##_type p0;\ |
| 12218 | p1##_type p1;\ |
| 12219 | p2##_type p2;\ |
| 12220 | p3##_type p3;\ |
| 12221 | p4##_type p4;\ |
| 12222 | p5##_type p5;\ |
| 12223 | p6##_type p6;\ |
| 12224 | p7##_type p7;\ |
| 12225 | p8##_type p8;\ |
| 12226 | p9##_type p9;\ |
| 12227 | private:\ |
| 12228 | ::testing::internal::string FormatDescription(bool negation) const {\ |
| 12229 | const ::testing::internal::string gmock_description = (description);\ |
| 12230 | if (!gmock_description.empty())\ |
| 12231 | return gmock_description;\ |
| 12232 | return ::testing::internal::FormatMatcherDescription(\ |
| 12233 | negation, #name,\ |
| 12234 | ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ |
| 12235 | ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 12236 | p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ |
| 12237 | p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\ |
| 12238 | }\ |
| 12239 | GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ |
| 12240 | };\ |
| 12241 | template <typename arg_type>\ |
| 12242 | operator ::testing::Matcher<arg_type>() const {\ |
| 12243 | return ::testing::Matcher<arg_type>(\ |
| 12244 | new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\ |
| 12245 | }\ |
| 12246 | name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 12247 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 12248 | p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ |
| 12249 | p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \ |
| 12250 | p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ |
| 12251 | p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\ |
| 12252 | }\ |
| 12253 | p0##_type p0;\ |
| 12254 | p1##_type p1;\ |
| 12255 | p2##_type p2;\ |
| 12256 | p3##_type p3;\ |
| 12257 | p4##_type p4;\ |
| 12258 | p5##_type p5;\ |
| 12259 | p6##_type p6;\ |
| 12260 | p7##_type p7;\ |
| 12261 | p8##_type p8;\ |
| 12262 | p9##_type p9;\ |
| 12263 | private:\ |
| 12264 | GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\ |
| 12265 | };\ |
| 12266 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 12267 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 12268 | typename p6##_type, typename p7##_type, typename p8##_type, \ |
| 12269 | typename p9##_type>\ |
| 12270 | inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 12271 | p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ |
| 12272 | p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
| 12273 | p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ |
| 12274 | p9##_type p9) {\ |
| 12275 | return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 12276 | p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \ |
| 12277 | p1, p2, p3, p4, p5, p6, p7, p8, p9);\ |
| 12278 | }\ |
| 12279 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 12280 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 12281 | typename p6##_type, typename p7##_type, typename p8##_type, \ |
| 12282 | typename p9##_type>\ |
| 12283 | template <typename arg_type>\ |
| 12284 | bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 12285 | p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ |
| 12286 | p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ |
| 12287 | arg_type arg,\ |
| 12288 | ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ |
| 12289 | const |
| 12290 | |
| 12291 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ |
| 12292 | // Copyright 2007, Google Inc. |
| 12293 | // All rights reserved. |
| 12294 | // |
| 12295 | // Redistribution and use in source and binary forms, with or without |
| 12296 | // modification, are permitted provided that the following conditions are |
| 12297 | // met: |
| 12298 | // |
| 12299 | // * Redistributions of source code must retain the above copyright |
| 12300 | // notice, this list of conditions and the following disclaimer. |
| 12301 | // * Redistributions in binary form must reproduce the above |
| 12302 | // copyright notice, this list of conditions and the following disclaimer |
| 12303 | // in the documentation and/or other materials provided with the |
| 12304 | // distribution. |
| 12305 | // * Neither the name of Google Inc. nor the names of its |
| 12306 | // contributors may be used to endorse or promote products derived from |
| 12307 | // this software without specific prior written permission. |
| 12308 | // |
| 12309 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 12310 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 12311 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 12312 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 12313 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 12314 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 12315 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 12316 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 12317 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 12318 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 12319 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 12320 | // |
| 12321 | // Author: wan@google.com (Zhanyong Wan) |
| 12322 | |
| 12323 | // Google Mock - a framework for writing C++ mock classes. |
| 12324 | // |
| 12325 | // This file implements some actions that depend on gmock-generated-actions.h. |
| 12326 | |
| 12327 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ |
| 12328 | #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ |
| 12329 | |
| 12330 | #include <algorithm> |
| 12331 | |
| 12332 | |
| 12333 | namespace testing { |
| 12334 | namespace internal { |
| 12335 | |
| 12336 | // Implements the Invoke(f) action. The template argument |
| 12337 | // FunctionImpl is the implementation type of f, which can be either a |
| 12338 | // function pointer or a functor. Invoke(f) can be used as an |
| 12339 | // Action<F> as long as f's type is compatible with F (i.e. f can be |
| 12340 | // assigned to a tr1::function<F>). |
| 12341 | template <typename FunctionImpl> |
| 12342 | class InvokeAction { |
| 12343 | public: |
| 12344 | // The c'tor makes a copy of function_impl (either a function |
| 12345 | // pointer or a functor). |
| 12346 | explicit InvokeAction(FunctionImpl function_impl) |
| 12347 | : function_impl_(function_impl) {} |
| 12348 | |
| 12349 | template <typename Result, typename ArgumentTuple> |
| 12350 | Result Perform(const ArgumentTuple& args) { |
| 12351 | return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args); |
| 12352 | } |
| 12353 | |
| 12354 | private: |
| 12355 | FunctionImpl function_impl_; |
| 12356 | |
| 12357 | GTEST_DISALLOW_ASSIGN_(InvokeAction); |
| 12358 | }; |
| 12359 | |
| 12360 | // Implements the Invoke(object_ptr, &Class::Method) action. |
| 12361 | template <class Class, typename MethodPtr> |
| 12362 | class InvokeMethodAction { |
| 12363 | public: |
| 12364 | InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr) |
| 12365 | : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} |
| 12366 | |
| 12367 | template <typename Result, typename ArgumentTuple> |
| 12368 | Result Perform(const ArgumentTuple& args) const { |
| 12369 | return InvokeHelper<Result, ArgumentTuple>::InvokeMethod( |
| 12370 | obj_ptr_, method_ptr_, args); |
| 12371 | } |
| 12372 | |
| 12373 | private: |
| 12374 | Class* const obj_ptr_; |
| 12375 | const MethodPtr method_ptr_; |
| 12376 | |
| 12377 | GTEST_DISALLOW_ASSIGN_(InvokeMethodAction); |
| 12378 | }; |
| 12379 | |
| 12380 | } // namespace internal |
| 12381 | |
| 12382 | // Various overloads for Invoke(). |
| 12383 | |
| 12384 | // Creates an action that invokes 'function_impl' with the mock |
| 12385 | // function's arguments. |
| 12386 | template <typename FunctionImpl> |
| 12387 | PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke( |
| 12388 | FunctionImpl function_impl) { |
| 12389 | return MakePolymorphicAction( |
| 12390 | internal::InvokeAction<FunctionImpl>(function_impl)); |
| 12391 | } |
| 12392 | |
| 12393 | // Creates an action that invokes the given method on the given object |
| 12394 | // with the mock function's arguments. |
| 12395 | template <class Class, typename MethodPtr> |
| 12396 | PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke( |
| 12397 | Class* obj_ptr, MethodPtr method_ptr) { |
| 12398 | return MakePolymorphicAction( |
| 12399 | internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr)); |
| 12400 | } |
| 12401 | |
| 12402 | // WithoutArgs(inner_action) can be used in a mock function with a |
| 12403 | // non-empty argument list to perform inner_action, which takes no |
| 12404 | // argument. In other words, it adapts an action accepting no |
| 12405 | // argument to one that accepts (and ignores) arguments. |
| 12406 | template <typename InnerAction> |
| 12407 | inline internal::WithArgsAction<InnerAction> |
| 12408 | WithoutArgs(const InnerAction& action) { |
| 12409 | return internal::WithArgsAction<InnerAction>(action); |
| 12410 | } |
| 12411 | |
| 12412 | // WithArg<k>(an_action) creates an action that passes the k-th |
| 12413 | // (0-based) argument of the mock function to an_action and performs |
| 12414 | // it. It adapts an action accepting one argument to one that accepts |
| 12415 | // multiple arguments. For convenience, we also provide |
| 12416 | // WithArgs<k>(an_action) (defined below) as a synonym. |
| 12417 | template <int k, typename InnerAction> |
| 12418 | inline internal::WithArgsAction<InnerAction, k> |
| 12419 | WithArg(const InnerAction& action) { |
| 12420 | return internal::WithArgsAction<InnerAction, k>(action); |
| 12421 | } |
| 12422 | |
| 12423 | // The ACTION*() macros trigger warning C4100 (unreferenced formal |
| 12424 | // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in |
| 12425 | // the macro definition, as the warnings are generated when the macro |
| 12426 | // is expanded and macro expansion cannot contain #pragma. Therefore |
| 12427 | // we suppress them here. |
| 12428 | #ifdef _MSC_VER |
| 12429 | # pragma warning(push) |
| 12430 | # pragma warning(disable:4100) |
| 12431 | #endif |
| 12432 | |
| 12433 | // Action ReturnArg<k>() returns the k-th argument of the mock function. |
| 12434 | ACTION_TEMPLATE(ReturnArg, |
| 12435 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 12436 | AND_0_VALUE_PARAMS()) { |
| 12437 | return std::tr1::get<k>(args); |
| 12438 | } |
| 12439 | |
| 12440 | // Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the |
| 12441 | // mock function to *pointer. |
| 12442 | ACTION_TEMPLATE(SaveArg, |
| 12443 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 12444 | AND_1_VALUE_PARAMS(pointer)) { |
| 12445 | *pointer = ::std::tr1::get<k>(args); |
| 12446 | } |
| 12447 | |
| 12448 | // Action SaveArgPointee<k>(pointer) saves the value pointed to |
| 12449 | // by the k-th (0-based) argument of the mock function to *pointer. |
| 12450 | ACTION_TEMPLATE(SaveArgPointee, |
| 12451 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 12452 | AND_1_VALUE_PARAMS(pointer)) { |
| 12453 | *pointer = *::std::tr1::get<k>(args); |
| 12454 | } |
| 12455 | |
| 12456 | // Action SetArgReferee<k>(value) assigns 'value' to the variable |
| 12457 | // referenced by the k-th (0-based) argument of the mock function. |
| 12458 | ACTION_TEMPLATE(SetArgReferee, |
| 12459 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 12460 | AND_1_VALUE_PARAMS(value)) { |
| 12461 | typedef typename ::std::tr1::tuple_element<k, args_type>::type argk_type; |
| 12462 | // Ensures that argument #k is a reference. If you get a compiler |
| 12463 | // error on the next line, you are using SetArgReferee<k>(value) in |
| 12464 | // a mock function whose k-th (0-based) argument is not a reference. |
| 12465 | GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value, |
| 12466 | SetArgReferee_must_be_used_with_a_reference_argument); |
| 12467 | ::std::tr1::get<k>(args) = value; |
| 12468 | } |
| 12469 | |
| 12470 | // Action SetArrayArgument<k>(first, last) copies the elements in |
| 12471 | // source range [first, last) to the array pointed to by the k-th |
| 12472 | // (0-based) argument, which can be either a pointer or an |
| 12473 | // iterator. The action does not take ownership of the elements in the |
| 12474 | // source range. |
| 12475 | ACTION_TEMPLATE(SetArrayArgument, |
| 12476 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 12477 | AND_2_VALUE_PARAMS(first, last)) { |
| 12478 | // Microsoft compiler deprecates ::std::copy, so we want to suppress warning |
| 12479 | // 4996 (Function call with parameters that may be unsafe) there. |
| 12480 | #ifdef _MSC_VER |
| 12481 | # pragma warning(push) // Saves the current warning state. |
| 12482 | # pragma warning(disable:4996) // Temporarily disables warning 4996. |
| 12483 | #endif |
| 12484 | ::std::copy(first, last, ::std::tr1::get<k>(args)); |
| 12485 | #ifdef _MSC_VER |
| 12486 | # pragma warning(pop) // Restores the warning state. |
| 12487 | #endif |
| 12488 | } |
| 12489 | |
| 12490 | // Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock |
| 12491 | // function. |
| 12492 | ACTION_TEMPLATE(DeleteArg, |
| 12493 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 12494 | AND_0_VALUE_PARAMS()) { |
| 12495 | delete ::std::tr1::get<k>(args); |
| 12496 | } |
| 12497 | |
| 12498 | // This action returns the value pointed to by 'pointer'. |
| 12499 | ACTION_P(ReturnPointee, pointer) { return *pointer; } |
| 12500 | |
| 12501 | // Action Throw(exception) can be used in a mock function of any type |
| 12502 | // to throw the given exception. Any copyable value can be thrown. |
| 12503 | #if GTEST_HAS_EXCEPTIONS |
| 12504 | |
| 12505 | // Suppresses the 'unreachable code' warning that VC generates in opt modes. |
| 12506 | # ifdef _MSC_VER |
| 12507 | # pragma warning(push) // Saves the current warning state. |
| 12508 | # pragma warning(disable:4702) // Temporarily disables warning 4702. |
| 12509 | # endif |
| 12510 | ACTION_P(Throw, exception) { throw exception; } |
| 12511 | # ifdef _MSC_VER |
| 12512 | # pragma warning(pop) // Restores the warning state. |
| 12513 | # endif |
| 12514 | |
| 12515 | #endif // GTEST_HAS_EXCEPTIONS |
| 12516 | |
| 12517 | #ifdef _MSC_VER |
| 12518 | # pragma warning(pop) |
| 12519 | #endif |
| 12520 | |
| 12521 | } // namespace testing |
| 12522 | |
| 12523 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ |
| 12524 | // This file was GENERATED by a script. DO NOT EDIT BY HAND!!! |
| 12525 | |
| 12526 | // Copyright 2008, Google Inc. |
| 12527 | // All rights reserved. |
| 12528 | // |
| 12529 | // Redistribution and use in source and binary forms, with or without |
| 12530 | // modification, are permitted provided that the following conditions are |
| 12531 | // met: |
| 12532 | // |
| 12533 | // * Redistributions of source code must retain the above copyright |
| 12534 | // notice, this list of conditions and the following disclaimer. |
| 12535 | // * Redistributions in binary form must reproduce the above |
| 12536 | // copyright notice, this list of conditions and the following disclaimer |
| 12537 | // in the documentation and/or other materials provided with the |
| 12538 | // distribution. |
| 12539 | // * Neither the name of Google Inc. nor the names of its |
| 12540 | // contributors may be used to endorse or promote products derived from |
| 12541 | // this software without specific prior written permission. |
| 12542 | // |
| 12543 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 12544 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 12545 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 12546 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 12547 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 12548 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 12549 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 12550 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 12551 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 12552 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 12553 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 12554 | // |
| 12555 | // Author: wan@google.com (Zhanyong Wan) |
| 12556 | |
| 12557 | // Implements class templates NiceMock and StrictMock. |
| 12558 | // |
| 12559 | // Given a mock class MockFoo that is created using Google Mock, |
| 12560 | // NiceMock<MockFoo> is a subclass of MockFoo that allows |
| 12561 | // uninteresting calls (i.e. calls to mock methods that have no |
| 12562 | // EXPECT_CALL specs), and StrictMock<MockFoo> is a subclass of |
| 12563 | // MockFoo that treats all uninteresting calls as errors. |
| 12564 | // |
| 12565 | // NiceMock and StrictMock "inherits" the constructors of their |
| 12566 | // respective base class, with up-to 10 arguments. Therefore you can |
| 12567 | // write NiceMock<MockFoo>(5, "a") to construct a nice mock where |
| 12568 | // MockFoo has a constructor that accepts (int, const char*), for |
| 12569 | // example. |
| 12570 | // |
| 12571 | // A known limitation is that NiceMock<MockFoo> and |
| 12572 | // StrictMock<MockFoo> only works for mock methods defined using the |
| 12573 | // MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. If a |
| 12574 | // mock method is defined in a base class of MockFoo, the "nice" or |
| 12575 | // "strict" modifier may not affect it, depending on the compiler. In |
| 12576 | // particular, nesting NiceMock and StrictMock is NOT supported. |
| 12577 | // |
| 12578 | // Another known limitation is that the constructors of the base mock |
| 12579 | // cannot have arguments passed by non-const reference, which are |
| 12580 | // banned by the Google C++ style guide anyway. |
| 12581 | |
| 12582 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ |
| 12583 | #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ |
| 12584 | |
| 12585 | |
| 12586 | namespace testing { |
| 12587 | |
| 12588 | template <class MockClass> |
| 12589 | class NiceMock : public MockClass { |
| 12590 | public: |
| 12591 | // We don't factor out the constructor body to a common method, as |
| 12592 | // we have to avoid a possible clash with members of MockClass. |
| 12593 | NiceMock() { |
| 12594 | ::testing::Mock::AllowUninterestingCalls( |
| 12595 | internal::ImplicitCast_<MockClass*>(this)); |
| 12596 | } |
| 12597 | |
| 12598 | // C++ doesn't (yet) allow inheritance of constructors, so we have |
| 12599 | // to define it for each arity. |
| 12600 | template <typename A1> |
| 12601 | explicit NiceMock(const A1& a1) : MockClass(a1) { |
| 12602 | ::testing::Mock::AllowUninterestingCalls( |
| 12603 | internal::ImplicitCast_<MockClass*>(this)); |
| 12604 | } |
| 12605 | template <typename A1, typename A2> |
| 12606 | NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { |
| 12607 | ::testing::Mock::AllowUninterestingCalls( |
| 12608 | internal::ImplicitCast_<MockClass*>(this)); |
| 12609 | } |
| 12610 | |
| 12611 | template <typename A1, typename A2, typename A3> |
| 12612 | NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { |
| 12613 | ::testing::Mock::AllowUninterestingCalls( |
| 12614 | internal::ImplicitCast_<MockClass*>(this)); |
| 12615 | } |
| 12616 | |
| 12617 | template <typename A1, typename A2, typename A3, typename A4> |
| 12618 | NiceMock(const A1& a1, const A2& a2, const A3& a3, |
| 12619 | const A4& a4) : MockClass(a1, a2, a3, a4) { |
| 12620 | ::testing::Mock::AllowUninterestingCalls( |
| 12621 | internal::ImplicitCast_<MockClass*>(this)); |
| 12622 | } |
| 12623 | |
| 12624 | template <typename A1, typename A2, typename A3, typename A4, typename A5> |
| 12625 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12626 | const A5& a5) : MockClass(a1, a2, a3, a4, a5) { |
| 12627 | ::testing::Mock::AllowUninterestingCalls( |
| 12628 | internal::ImplicitCast_<MockClass*>(this)); |
| 12629 | } |
| 12630 | |
| 12631 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 12632 | typename A6> |
| 12633 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12634 | const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { |
| 12635 | ::testing::Mock::AllowUninterestingCalls( |
| 12636 | internal::ImplicitCast_<MockClass*>(this)); |
| 12637 | } |
| 12638 | |
| 12639 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 12640 | typename A6, typename A7> |
| 12641 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12642 | const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, |
| 12643 | a6, a7) { |
| 12644 | ::testing::Mock::AllowUninterestingCalls( |
| 12645 | internal::ImplicitCast_<MockClass*>(this)); |
| 12646 | } |
| 12647 | |
| 12648 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 12649 | typename A6, typename A7, typename A8> |
| 12650 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12651 | const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, |
| 12652 | a2, a3, a4, a5, a6, a7, a8) { |
| 12653 | ::testing::Mock::AllowUninterestingCalls( |
| 12654 | internal::ImplicitCast_<MockClass*>(this)); |
| 12655 | } |
| 12656 | |
| 12657 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 12658 | typename A6, typename A7, typename A8, typename A9> |
| 12659 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12660 | const A5& a5, const A6& a6, const A7& a7, const A8& a8, |
| 12661 | const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { |
| 12662 | ::testing::Mock::AllowUninterestingCalls( |
| 12663 | internal::ImplicitCast_<MockClass*>(this)); |
| 12664 | } |
| 12665 | |
| 12666 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 12667 | typename A6, typename A7, typename A8, typename A9, typename A10> |
| 12668 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12669 | const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, |
| 12670 | const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { |
| 12671 | ::testing::Mock::AllowUninterestingCalls( |
| 12672 | internal::ImplicitCast_<MockClass*>(this)); |
| 12673 | } |
| 12674 | |
| 12675 | virtual ~NiceMock() { |
| 12676 | ::testing::Mock::UnregisterCallReaction( |
| 12677 | internal::ImplicitCast_<MockClass*>(this)); |
| 12678 | } |
| 12679 | |
| 12680 | private: |
| 12681 | GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); |
| 12682 | }; |
| 12683 | |
| 12684 | template <class MockClass> |
| 12685 | class StrictMock : public MockClass { |
| 12686 | public: |
| 12687 | // We don't factor out the constructor body to a common method, as |
| 12688 | // we have to avoid a possible clash with members of MockClass. |
| 12689 | StrictMock() { |
| 12690 | ::testing::Mock::FailUninterestingCalls( |
| 12691 | internal::ImplicitCast_<MockClass*>(this)); |
| 12692 | } |
| 12693 | |
| 12694 | template <typename A1> |
| 12695 | explicit StrictMock(const A1& a1) : MockClass(a1) { |
| 12696 | ::testing::Mock::FailUninterestingCalls( |
| 12697 | internal::ImplicitCast_<MockClass*>(this)); |
| 12698 | } |
| 12699 | template <typename A1, typename A2> |
| 12700 | StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { |
| 12701 | ::testing::Mock::FailUninterestingCalls( |
| 12702 | internal::ImplicitCast_<MockClass*>(this)); |
| 12703 | } |
| 12704 | |
| 12705 | template <typename A1, typename A2, typename A3> |
| 12706 | StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { |
| 12707 | ::testing::Mock::FailUninterestingCalls( |
| 12708 | internal::ImplicitCast_<MockClass*>(this)); |
| 12709 | } |
| 12710 | |
| 12711 | template <typename A1, typename A2, typename A3, typename A4> |
| 12712 | StrictMock(const A1& a1, const A2& a2, const A3& a3, |
| 12713 | const A4& a4) : MockClass(a1, a2, a3, a4) { |
| 12714 | ::testing::Mock::FailUninterestingCalls( |
| 12715 | internal::ImplicitCast_<MockClass*>(this)); |
| 12716 | } |
| 12717 | |
| 12718 | template <typename A1, typename A2, typename A3, typename A4, typename A5> |
| 12719 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12720 | const A5& a5) : MockClass(a1, a2, a3, a4, a5) { |
| 12721 | ::testing::Mock::FailUninterestingCalls( |
| 12722 | internal::ImplicitCast_<MockClass*>(this)); |
| 12723 | } |
| 12724 | |
| 12725 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 12726 | typename A6> |
| 12727 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12728 | const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { |
| 12729 | ::testing::Mock::FailUninterestingCalls( |
| 12730 | internal::ImplicitCast_<MockClass*>(this)); |
| 12731 | } |
| 12732 | |
| 12733 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 12734 | typename A6, typename A7> |
| 12735 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12736 | const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, |
| 12737 | a6, a7) { |
| 12738 | ::testing::Mock::FailUninterestingCalls( |
| 12739 | internal::ImplicitCast_<MockClass*>(this)); |
| 12740 | } |
| 12741 | |
| 12742 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 12743 | typename A6, typename A7, typename A8> |
| 12744 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12745 | const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, |
| 12746 | a2, a3, a4, a5, a6, a7, a8) { |
| 12747 | ::testing::Mock::FailUninterestingCalls( |
| 12748 | internal::ImplicitCast_<MockClass*>(this)); |
| 12749 | } |
| 12750 | |
| 12751 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 12752 | typename A6, typename A7, typename A8, typename A9> |
| 12753 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12754 | const A5& a5, const A6& a6, const A7& a7, const A8& a8, |
| 12755 | const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { |
| 12756 | ::testing::Mock::FailUninterestingCalls( |
| 12757 | internal::ImplicitCast_<MockClass*>(this)); |
| 12758 | } |
| 12759 | |
| 12760 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 12761 | typename A6, typename A7, typename A8, typename A9, typename A10> |
| 12762 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 12763 | const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, |
| 12764 | const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { |
| 12765 | ::testing::Mock::FailUninterestingCalls( |
| 12766 | internal::ImplicitCast_<MockClass*>(this)); |
| 12767 | } |
| 12768 | |
| 12769 | virtual ~StrictMock() { |
| 12770 | ::testing::Mock::UnregisterCallReaction( |
| 12771 | internal::ImplicitCast_<MockClass*>(this)); |
| 12772 | } |
| 12773 | |
| 12774 | private: |
| 12775 | GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); |
| 12776 | }; |
| 12777 | |
| 12778 | // The following specializations catch some (relatively more common) |
| 12779 | // user errors of nesting nice and strict mocks. They do NOT catch |
| 12780 | // all possible errors. |
| 12781 | |
| 12782 | // These specializations are declared but not defined, as NiceMock and |
| 12783 | // StrictMock cannot be nested. |
| 12784 | template <typename MockClass> |
| 12785 | class NiceMock<NiceMock<MockClass> >; |
| 12786 | template <typename MockClass> |
| 12787 | class NiceMock<StrictMock<MockClass> >; |
| 12788 | template <typename MockClass> |
| 12789 | class StrictMock<NiceMock<MockClass> >; |
| 12790 | template <typename MockClass> |
| 12791 | class StrictMock<StrictMock<MockClass> >; |
| 12792 | |
| 12793 | } // namespace testing |
| 12794 | |
| 12795 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ |
| 12796 | |
| 12797 | namespace testing { |
| 12798 | |
| 12799 | // Declares Google Mock flags that we want a user to use programmatically. |
| 12800 | GMOCK_DECLARE_bool_(catch_leaked_mocks); |
| 12801 | GMOCK_DECLARE_string_(verbose); |
| 12802 | |
| 12803 | // Initializes Google Mock. This must be called before running the |
| 12804 | // tests. In particular, it parses the command line for the flags |
| 12805 | // that Google Mock recognizes. Whenever a Google Mock flag is seen, |
| 12806 | // it is removed from argv, and *argc is decremented. |
| 12807 | // |
| 12808 | // No value is returned. Instead, the Google Mock flag variables are |
| 12809 | // updated. |
| 12810 | // |
| 12811 | // Since Google Test is needed for Google Mock to work, this function |
| 12812 | // also initializes Google Test and parses its flags, if that hasn't |
| 12813 | // been done. |
| 12814 | void InitGoogleMock(int* argc, char** argv); |
| 12815 | |
| 12816 | // This overloaded version can be used in Windows programs compiled in |
| 12817 | // UNICODE mode. |
| 12818 | void InitGoogleMock(int* argc, wchar_t** argv); |
| 12819 | |
| 12820 | } // namespace testing |
| 12821 | |
| 12822 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_ |