shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 1 | // This file was GENERATED by a script. DO NOT EDIT BY HAND!!! |
| 2 | |
| 3 | // Copyright 2007, Google Inc. |
| 4 | // All rights reserved. |
| 5 | // |
| 6 | // Redistribution and use in source and binary forms, with or without |
| 7 | // modification, are permitted provided that the following conditions are |
| 8 | // met: |
| 9 | // |
| 10 | // * Redistributions of source code must retain the above copyright |
| 11 | // notice, this list of conditions and the following disclaimer. |
| 12 | // * Redistributions in binary form must reproduce the above |
| 13 | // copyright notice, this list of conditions and the following disclaimer |
| 14 | // in the documentation and/or other materials provided with the |
| 15 | // distribution. |
| 16 | // * Neither the name of Google Inc. nor the names of its |
| 17 | // contributors may be used to endorse or promote products derived from |
| 18 | // this software without specific prior written permission. |
| 19 | // |
| 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | // |
| 32 | // Author: wan@google.com (Zhanyong Wan) |
| 33 | |
| 34 | // Google Mock - a framework for writing C++ mock classes. |
| 35 | // |
| 36 | // This file implements some commonly used variadic actions. |
| 37 | |
| 38 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ |
| 39 | #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ |
| 40 | |
| 41 | #include <gmock/gmock-actions.h> |
| 42 | #include <gmock/internal/gmock-port.h> |
| 43 | |
| 44 | namespace testing { |
| 45 | namespace internal { |
| 46 | |
| 47 | // InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary |
| 48 | // function or method with the unpacked values, where F is a function |
| 49 | // type that takes N arguments. |
| 50 | template <typename Result, typename ArgumentTuple> |
| 51 | class InvokeHelper; |
| 52 | |
| 53 | template <typename R> |
| 54 | class InvokeHelper<R, ::std::tr1::tuple<> > { |
| 55 | public: |
| 56 | template <typename Function> |
| 57 | static R Invoke(Function function, const ::std::tr1::tuple<>&) { |
| 58 | return function(); |
| 59 | } |
| 60 | |
| 61 | template <class Class, typename MethodPtr> |
| 62 | static R InvokeMethod(Class* obj_ptr, |
| 63 | MethodPtr method_ptr, |
| 64 | const ::std::tr1::tuple<>&) { |
| 65 | return (obj_ptr->*method_ptr)(); |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | template <typename R, typename A1> |
| 70 | class InvokeHelper<R, ::std::tr1::tuple<A1> > { |
| 71 | public: |
| 72 | template <typename Function> |
| 73 | static R Invoke(Function function, const ::std::tr1::tuple<A1>& args) { |
| 74 | using ::std::tr1::get; |
| 75 | return function(get<0>(args)); |
| 76 | } |
| 77 | |
| 78 | template <class Class, typename MethodPtr> |
| 79 | static R InvokeMethod(Class* obj_ptr, |
| 80 | MethodPtr method_ptr, |
| 81 | const ::std::tr1::tuple<A1>& args) { |
| 82 | using ::std::tr1::get; |
| 83 | return (obj_ptr->*method_ptr)(get<0>(args)); |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | template <typename R, typename A1, typename A2> |
| 88 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2> > { |
| 89 | public: |
| 90 | template <typename Function> |
| 91 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2>& args) { |
| 92 | using ::std::tr1::get; |
| 93 | return function(get<0>(args), get<1>(args)); |
| 94 | } |
| 95 | |
| 96 | template <class Class, typename MethodPtr> |
| 97 | static R InvokeMethod(Class* obj_ptr, |
| 98 | MethodPtr method_ptr, |
| 99 | const ::std::tr1::tuple<A1, A2>& args) { |
| 100 | using ::std::tr1::get; |
| 101 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args)); |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | template <typename R, typename A1, typename A2, typename A3> |
| 106 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3> > { |
| 107 | public: |
| 108 | template <typename Function> |
| 109 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, |
| 110 | A3>& args) { |
| 111 | using ::std::tr1::get; |
| 112 | return function(get<0>(args), get<1>(args), get<2>(args)); |
| 113 | } |
| 114 | |
| 115 | template <class Class, typename MethodPtr> |
| 116 | static R InvokeMethod(Class* obj_ptr, |
| 117 | MethodPtr method_ptr, |
| 118 | const ::std::tr1::tuple<A1, A2, A3>& args) { |
| 119 | using ::std::tr1::get; |
| 120 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args)); |
| 121 | } |
| 122 | }; |
| 123 | |
| 124 | template <typename R, typename A1, typename A2, typename A3, typename A4> |
| 125 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4> > { |
| 126 | public: |
| 127 | template <typename Function> |
| 128 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, |
| 129 | A4>& args) { |
| 130 | using ::std::tr1::get; |
| 131 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args)); |
| 132 | } |
| 133 | |
| 134 | template <class Class, typename MethodPtr> |
| 135 | static R InvokeMethod(Class* obj_ptr, |
| 136 | MethodPtr method_ptr, |
| 137 | const ::std::tr1::tuple<A1, A2, A3, A4>& args) { |
| 138 | using ::std::tr1::get; |
| 139 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 140 | get<3>(args)); |
| 141 | } |
| 142 | }; |
| 143 | |
| 144 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 145 | typename A5> |
| 146 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5> > { |
| 147 | public: |
| 148 | template <typename Function> |
| 149 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 150 | A5>& args) { |
| 151 | using ::std::tr1::get; |
| 152 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 153 | get<4>(args)); |
| 154 | } |
| 155 | |
| 156 | template <class Class, typename MethodPtr> |
| 157 | static R InvokeMethod(Class* obj_ptr, |
| 158 | MethodPtr method_ptr, |
| 159 | const ::std::tr1::tuple<A1, A2, A3, A4, A5>& args) { |
| 160 | using ::std::tr1::get; |
| 161 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 162 | get<3>(args), get<4>(args)); |
| 163 | } |
| 164 | }; |
| 165 | |
| 166 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 167 | typename A5, typename A6> |
| 168 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > { |
| 169 | public: |
| 170 | template <typename Function> |
| 171 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 172 | A5, A6>& args) { |
| 173 | using ::std::tr1::get; |
| 174 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 175 | get<4>(args), get<5>(args)); |
| 176 | } |
| 177 | |
| 178 | template <class Class, typename MethodPtr> |
| 179 | static R InvokeMethod(Class* obj_ptr, |
| 180 | MethodPtr method_ptr, |
| 181 | const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6>& args) { |
| 182 | using ::std::tr1::get; |
| 183 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 184 | get<3>(args), get<4>(args), get<5>(args)); |
| 185 | } |
| 186 | }; |
| 187 | |
| 188 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 189 | typename A5, typename A6, typename A7> |
| 190 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > { |
| 191 | public: |
| 192 | template <typename Function> |
| 193 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 194 | A5, A6, A7>& args) { |
| 195 | using ::std::tr1::get; |
| 196 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 197 | get<4>(args), get<5>(args), get<6>(args)); |
| 198 | } |
| 199 | |
| 200 | template <class Class, typename MethodPtr> |
| 201 | static R InvokeMethod(Class* obj_ptr, |
| 202 | MethodPtr method_ptr, |
| 203 | const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, |
| 204 | A7>& args) { |
| 205 | using ::std::tr1::get; |
| 206 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 207 | get<3>(args), get<4>(args), get<5>(args), get<6>(args)); |
| 208 | } |
| 209 | }; |
| 210 | |
| 211 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 212 | typename A5, typename A6, typename A7, typename A8> |
| 213 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > { |
| 214 | public: |
| 215 | template <typename Function> |
| 216 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 217 | A5, A6, A7, A8>& args) { |
| 218 | using ::std::tr1::get; |
| 219 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 220 | get<4>(args), get<5>(args), get<6>(args), get<7>(args)); |
| 221 | } |
| 222 | |
| 223 | template <class Class, typename MethodPtr> |
| 224 | static R InvokeMethod(Class* obj_ptr, |
| 225 | MethodPtr method_ptr, |
| 226 | const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, |
| 227 | A8>& args) { |
| 228 | using ::std::tr1::get; |
| 229 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 230 | get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args)); |
| 231 | } |
| 232 | }; |
| 233 | |
| 234 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 235 | typename A5, typename A6, typename A7, typename A8, typename A9> |
| 236 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > { |
| 237 | public: |
| 238 | template <typename Function> |
| 239 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 240 | A5, A6, A7, A8, A9>& args) { |
| 241 | using ::std::tr1::get; |
| 242 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 243 | get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args)); |
| 244 | } |
| 245 | |
| 246 | template <class Class, typename MethodPtr> |
| 247 | static R InvokeMethod(Class* obj_ptr, |
| 248 | MethodPtr method_ptr, |
| 249 | const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, |
| 250 | A9>& args) { |
| 251 | using ::std::tr1::get; |
| 252 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 253 | get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), |
| 254 | get<8>(args)); |
| 255 | } |
| 256 | }; |
| 257 | |
| 258 | template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 259 | typename A5, typename A6, typename A7, typename A8, typename A9, |
| 260 | typename A10> |
| 261 | class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, |
| 262 | A10> > { |
| 263 | public: |
| 264 | template <typename Function> |
| 265 | static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4, |
| 266 | A5, A6, A7, A8, A9, A10>& args) { |
| 267 | using ::std::tr1::get; |
| 268 | return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), |
| 269 | get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), |
| 270 | get<9>(args)); |
| 271 | } |
| 272 | |
| 273 | template <class Class, typename MethodPtr> |
| 274 | static R InvokeMethod(Class* obj_ptr, |
| 275 | MethodPtr method_ptr, |
| 276 | const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, |
| 277 | A9, A10>& args) { |
| 278 | using ::std::tr1::get; |
| 279 | return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), |
| 280 | get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), |
| 281 | get<8>(args), get<9>(args)); |
| 282 | } |
| 283 | }; |
| 284 | |
| 285 | |
| 286 | // Implements the Invoke(f) action. The template argument |
| 287 | // FunctionImpl is the implementation type of f, which can be either a |
| 288 | // function pointer or a functor. Invoke(f) can be used as an |
| 289 | // Action<F> as long as f's type is compatible with F (i.e. f can be |
| 290 | // assigned to a tr1::function<F>). |
| 291 | template <typename FunctionImpl> |
| 292 | class InvokeAction { |
| 293 | public: |
| 294 | // The c'tor makes a copy of function_impl (either a function |
| 295 | // pointer or a functor). |
| 296 | explicit InvokeAction(FunctionImpl function_impl) |
| 297 | : function_impl_(function_impl) {} |
| 298 | |
| 299 | template <typename Result, typename ArgumentTuple> |
| 300 | Result Perform(const ArgumentTuple& args) { |
| 301 | return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args); |
| 302 | } |
| 303 | private: |
| 304 | FunctionImpl function_impl_; |
| 305 | }; |
| 306 | |
| 307 | // Implements the Invoke(object_ptr, &Class::Method) action. |
| 308 | template <class Class, typename MethodPtr> |
| 309 | class InvokeMethodAction { |
| 310 | public: |
| 311 | InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr) |
| 312 | : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} |
| 313 | |
| 314 | template <typename Result, typename ArgumentTuple> |
| 315 | Result Perform(const ArgumentTuple& args) const { |
| 316 | return InvokeHelper<Result, ArgumentTuple>::InvokeMethod( |
| 317 | obj_ptr_, method_ptr_, args); |
| 318 | } |
| 319 | private: |
| 320 | Class* const obj_ptr_; |
| 321 | const MethodPtr method_ptr_; |
| 322 | }; |
| 323 | |
| 324 | // A ReferenceWrapper<T> object represents a reference to type T, |
| 325 | // which can be either const or not. It can be explicitly converted |
| 326 | // from, and implicitly converted to, a T&. Unlike a reference, |
| 327 | // ReferenceWrapper<T> can be copied and can survive template type |
| 328 | // inference. This is used to support by-reference arguments in the |
| 329 | // InvokeArgument<N>(...) action. The idea was from "reference |
| 330 | // wrappers" in tr1, which we don't have in our source tree yet. |
| 331 | template <typename T> |
| 332 | class ReferenceWrapper { |
| 333 | public: |
| 334 | // Constructs a ReferenceWrapper<T> object from a T&. |
| 335 | explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT |
| 336 | |
| 337 | // Allows a ReferenceWrapper<T> object to be implicitly converted to |
| 338 | // a T&. |
| 339 | operator T&() const { return *pointer_; } |
| 340 | private: |
| 341 | T* pointer_; |
| 342 | }; |
| 343 | |
| 344 | // CallableHelper has static methods for invoking "callables", |
| 345 | // i.e. function pointers and functors. It uses overloading to |
| 346 | // provide a uniform interface for invoking different kinds of |
| 347 | // callables. In particular, you can use: |
| 348 | // |
| 349 | // CallableHelper<R>::Call(callable, a1, a2, ..., an) |
| 350 | // |
| 351 | // to invoke an n-ary callable, where R is its return type. If an |
| 352 | // argument, say a2, needs to be passed by reference, you should write |
| 353 | // ByRef(a2) instead of a2 in the above expression. |
| 354 | template <typename R> |
| 355 | class CallableHelper { |
| 356 | public: |
| 357 | // Calls a nullary callable. |
| 358 | template <typename Function> |
| 359 | static R Call(Function function) { return function(); } |
| 360 | |
| 361 | // Calls a unary callable. |
| 362 | |
| 363 | // We deliberately pass a1 by value instead of const reference here |
| 364 | // in case it is a C-string literal. If we had declared the |
| 365 | // parameter as 'const A1& a1' and write Call(function, "Hi"), the |
| 366 | // compiler would've thought A1 is 'char[3]', which causes trouble |
| 367 | // when you need to copy a value of type A1. By declaring the |
| 368 | // parameter as 'A1 a1', the compiler will correctly infer that A1 |
| 369 | // is 'const char*' when it sees Call(function, "Hi"). |
| 370 | // |
| 371 | // Since this function is defined inline, the compiler can get rid |
| 372 | // of the copying of the arguments. Therefore the performance won't |
| 373 | // be hurt. |
| 374 | template <typename Function, typename A1> |
| 375 | static R Call(Function function, A1 a1) { return function(a1); } |
| 376 | |
| 377 | // Calls a binary callable. |
| 378 | template <typename Function, typename A1, typename A2> |
| 379 | static R Call(Function function, A1 a1, A2 a2) { |
| 380 | return function(a1, a2); |
| 381 | } |
| 382 | |
| 383 | // Calls a ternary callable. |
| 384 | template <typename Function, typename A1, typename A2, typename A3> |
| 385 | static R Call(Function function, A1 a1, A2 a2, A3 a3) { |
| 386 | return function(a1, a2, a3); |
| 387 | } |
| 388 | |
| 389 | // Calls a 4-ary callable. |
| 390 | template <typename Function, typename A1, typename A2, typename A3, |
| 391 | typename A4> |
| 392 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4) { |
| 393 | return function(a1, a2, a3, a4); |
| 394 | } |
| 395 | |
| 396 | // Calls a 5-ary callable. |
| 397 | template <typename Function, typename A1, typename A2, typename A3, |
| 398 | typename A4, typename A5> |
| 399 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { |
| 400 | return function(a1, a2, a3, a4, a5); |
| 401 | } |
| 402 | |
| 403 | // Calls a 6-ary callable. |
| 404 | template <typename Function, typename A1, typename A2, typename A3, |
| 405 | typename A4, typename A5, typename A6> |
| 406 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { |
| 407 | return function(a1, a2, a3, a4, a5, a6); |
| 408 | } |
| 409 | |
| 410 | // Calls a 7-ary callable. |
| 411 | template <typename Function, typename A1, typename A2, typename A3, |
| 412 | typename A4, typename A5, typename A6, typename A7> |
| 413 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, |
| 414 | A7 a7) { |
| 415 | return function(a1, a2, a3, a4, a5, a6, a7); |
| 416 | } |
| 417 | |
| 418 | // Calls a 8-ary callable. |
| 419 | template <typename Function, typename A1, typename A2, typename A3, |
| 420 | typename A4, typename A5, typename A6, typename A7, typename A8> |
| 421 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, |
| 422 | A7 a7, A8 a8) { |
| 423 | return function(a1, a2, a3, a4, a5, a6, a7, a8); |
| 424 | } |
| 425 | |
| 426 | // Calls a 9-ary callable. |
| 427 | template <typename Function, typename A1, typename A2, typename A3, |
| 428 | typename A4, typename A5, typename A6, typename A7, typename A8, |
| 429 | typename A9> |
| 430 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, |
| 431 | A7 a7, A8 a8, A9 a9) { |
| 432 | return function(a1, a2, a3, a4, a5, a6, a7, a8, a9); |
| 433 | } |
| 434 | |
| 435 | // Calls a 10-ary callable. |
| 436 | template <typename Function, typename A1, typename A2, typename A3, |
| 437 | typename A4, typename A5, typename A6, typename A7, typename A8, |
| 438 | typename A9, typename A10> |
| 439 | static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, |
| 440 | A7 a7, A8 a8, A9 a9, A10 a10) { |
| 441 | return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); |
| 442 | } |
| 443 | |
| 444 | }; // class CallableHelper |
| 445 | |
| 446 | // Invokes a nullary callable argument. |
| 447 | template <size_t N> |
| 448 | class InvokeArgumentAction0 { |
| 449 | public: |
| 450 | template <typename Result, typename ArgumentTuple> |
| 451 | static Result Perform(const ArgumentTuple& args) { |
| 452 | return CallableHelper<Result>::Call(::std::tr1::get<N>(args)); |
| 453 | } |
| 454 | }; |
| 455 | |
| 456 | // Invokes a unary callable argument with the given argument. |
| 457 | template <size_t N, typename A1> |
| 458 | class InvokeArgumentAction1 { |
| 459 | public: |
| 460 | // We deliberately pass a1 by value instead of const reference here |
| 461 | // in case it is a C-string literal. |
| 462 | // |
| 463 | // Since this function is defined inline, the compiler can get rid |
| 464 | // of the copying of the arguments. Therefore the performance won't |
| 465 | // be hurt. |
| 466 | explicit InvokeArgumentAction1(A1 a1) : arg1_(a1) {} |
| 467 | |
| 468 | template <typename Result, typename ArgumentTuple> |
| 469 | Result Perform(const ArgumentTuple& args) { |
| 470 | return CallableHelper<Result>::Call(::std::tr1::get<N>(args), arg1_); |
| 471 | } |
| 472 | private: |
| 473 | const A1 arg1_; |
| 474 | }; |
| 475 | |
| 476 | // Invokes a binary callable argument with the given arguments. |
| 477 | template <size_t N, typename A1, typename A2> |
| 478 | class InvokeArgumentAction2 { |
| 479 | public: |
| 480 | InvokeArgumentAction2(A1 a1, A2 a2) : |
| 481 | arg1_(a1), arg2_(a2) {} |
| 482 | |
| 483 | template <typename Result, typename ArgumentTuple> |
| 484 | Result Perform(const ArgumentTuple& args) { |
| 485 | return CallableHelper<Result>::Call(::std::tr1::get<N>(args), arg1_, arg2_); |
| 486 | } |
| 487 | private: |
| 488 | const A1 arg1_; |
| 489 | const A2 arg2_; |
| 490 | }; |
| 491 | |
| 492 | // Invokes a ternary callable argument with the given arguments. |
| 493 | template <size_t N, typename A1, typename A2, typename A3> |
| 494 | class InvokeArgumentAction3 { |
| 495 | public: |
| 496 | InvokeArgumentAction3(A1 a1, A2 a2, A3 a3) : |
| 497 | arg1_(a1), arg2_(a2), arg3_(a3) {} |
| 498 | |
| 499 | template <typename Result, typename ArgumentTuple> |
| 500 | Result Perform(const ArgumentTuple& args) { |
| 501 | return CallableHelper<Result>::Call(::std::tr1::get<N>(args), arg1_, arg2_, |
| 502 | arg3_); |
| 503 | } |
| 504 | private: |
| 505 | const A1 arg1_; |
| 506 | const A2 arg2_; |
| 507 | const A3 arg3_; |
| 508 | }; |
| 509 | |
| 510 | // Invokes a 4-ary callable argument with the given arguments. |
| 511 | template <size_t N, typename A1, typename A2, typename A3, typename A4> |
| 512 | class InvokeArgumentAction4 { |
| 513 | public: |
| 514 | InvokeArgumentAction4(A1 a1, A2 a2, A3 a3, A4 a4) : |
| 515 | arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4) {} |
| 516 | |
| 517 | template <typename Result, typename ArgumentTuple> |
| 518 | Result Perform(const ArgumentTuple& args) { |
| 519 | return CallableHelper<Result>::Call(::std::tr1::get<N>(args), arg1_, arg2_, |
| 520 | arg3_, arg4_); |
| 521 | } |
| 522 | private: |
| 523 | const A1 arg1_; |
| 524 | const A2 arg2_; |
| 525 | const A3 arg3_; |
| 526 | const A4 arg4_; |
| 527 | }; |
| 528 | |
| 529 | // Invokes a 5-ary callable argument with the given arguments. |
| 530 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 531 | typename A5> |
| 532 | class InvokeArgumentAction5 { |
| 533 | public: |
| 534 | InvokeArgumentAction5(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) : |
| 535 | arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5) {} |
| 536 | |
| 537 | template <typename Result, typename ArgumentTuple> |
| 538 | Result Perform(const ArgumentTuple& args) { |
| 539 | // We extract the callable to a variable before invoking it, in |
| 540 | // case it is a functor passed by value and its operator() is not |
| 541 | // const. |
| 542 | typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function = |
| 543 | ::std::tr1::get<N>(args); |
| 544 | return function(arg1_, arg2_, arg3_, arg4_, arg5_); |
| 545 | } |
| 546 | private: |
| 547 | const A1 arg1_; |
| 548 | const A2 arg2_; |
| 549 | const A3 arg3_; |
| 550 | const A4 arg4_; |
| 551 | const A5 arg5_; |
| 552 | }; |
| 553 | |
| 554 | // Invokes a 6-ary callable argument with the given arguments. |
| 555 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 556 | typename A5, typename A6> |
| 557 | class InvokeArgumentAction6 { |
| 558 | public: |
| 559 | InvokeArgumentAction6(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) : |
| 560 | arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6) {} |
| 561 | |
| 562 | template <typename Result, typename ArgumentTuple> |
| 563 | Result Perform(const ArgumentTuple& args) { |
| 564 | // We extract the callable to a variable before invoking it, in |
| 565 | // case it is a functor passed by value and its operator() is not |
| 566 | // const. |
| 567 | typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function = |
| 568 | ::std::tr1::get<N>(args); |
| 569 | return function(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_); |
| 570 | } |
| 571 | private: |
| 572 | const A1 arg1_; |
| 573 | const A2 arg2_; |
| 574 | const A3 arg3_; |
| 575 | const A4 arg4_; |
| 576 | const A5 arg5_; |
| 577 | const A6 arg6_; |
| 578 | }; |
| 579 | |
| 580 | // Invokes a 7-ary callable argument with the given arguments. |
| 581 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 582 | typename A5, typename A6, typename A7> |
| 583 | class InvokeArgumentAction7 { |
| 584 | public: |
| 585 | InvokeArgumentAction7(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) : |
| 586 | arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6), |
| 587 | arg7_(a7) {} |
| 588 | |
| 589 | template <typename Result, typename ArgumentTuple> |
| 590 | Result Perform(const ArgumentTuple& args) { |
| 591 | // We extract the callable to a variable before invoking it, in |
| 592 | // case it is a functor passed by value and its operator() is not |
| 593 | // const. |
| 594 | typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function = |
| 595 | ::std::tr1::get<N>(args); |
| 596 | return function(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_); |
| 597 | } |
| 598 | private: |
| 599 | const A1 arg1_; |
| 600 | const A2 arg2_; |
| 601 | const A3 arg3_; |
| 602 | const A4 arg4_; |
| 603 | const A5 arg5_; |
| 604 | const A6 arg6_; |
| 605 | const A7 arg7_; |
| 606 | }; |
| 607 | |
| 608 | // Invokes a 8-ary callable argument with the given arguments. |
| 609 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 610 | typename A5, typename A6, typename A7, typename A8> |
| 611 | class InvokeArgumentAction8 { |
| 612 | public: |
| 613 | InvokeArgumentAction8(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, |
| 614 | A8 a8) : |
| 615 | arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6), |
| 616 | arg7_(a7), arg8_(a8) {} |
| 617 | |
| 618 | template <typename Result, typename ArgumentTuple> |
| 619 | Result Perform(const ArgumentTuple& args) { |
| 620 | // We extract the callable to a variable before invoking it, in |
| 621 | // case it is a functor passed by value and its operator() is not |
| 622 | // const. |
| 623 | typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function = |
| 624 | ::std::tr1::get<N>(args); |
| 625 | return function(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_, arg8_); |
| 626 | } |
| 627 | private: |
| 628 | const A1 arg1_; |
| 629 | const A2 arg2_; |
| 630 | const A3 arg3_; |
| 631 | const A4 arg4_; |
| 632 | const A5 arg5_; |
| 633 | const A6 arg6_; |
| 634 | const A7 arg7_; |
| 635 | const A8 arg8_; |
| 636 | }; |
| 637 | |
| 638 | // Invokes a 9-ary callable argument with the given arguments. |
| 639 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 640 | typename A5, typename A6, typename A7, typename A8, typename A9> |
| 641 | class InvokeArgumentAction9 { |
| 642 | public: |
| 643 | InvokeArgumentAction9(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, |
| 644 | A9 a9) : |
| 645 | arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6), |
| 646 | arg7_(a7), arg8_(a8), arg9_(a9) {} |
| 647 | |
| 648 | template <typename Result, typename ArgumentTuple> |
| 649 | Result Perform(const ArgumentTuple& args) { |
| 650 | // We extract the callable to a variable before invoking it, in |
| 651 | // case it is a functor passed by value and its operator() is not |
| 652 | // const. |
| 653 | typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function = |
| 654 | ::std::tr1::get<N>(args); |
| 655 | return function(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_, arg8_, |
| 656 | arg9_); |
| 657 | } |
| 658 | private: |
| 659 | const A1 arg1_; |
| 660 | const A2 arg2_; |
| 661 | const A3 arg3_; |
| 662 | const A4 arg4_; |
| 663 | const A5 arg5_; |
| 664 | const A6 arg6_; |
| 665 | const A7 arg7_; |
| 666 | const A8 arg8_; |
| 667 | const A9 arg9_; |
| 668 | }; |
| 669 | |
| 670 | // Invokes a 10-ary callable argument with the given arguments. |
| 671 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 672 | typename A5, typename A6, typename A7, typename A8, typename A9, |
| 673 | typename A10> |
| 674 | class InvokeArgumentAction10 { |
| 675 | public: |
| 676 | InvokeArgumentAction10(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, |
| 677 | A8 a8, A9 a9, A10 a10) : |
| 678 | arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6), |
| 679 | arg7_(a7), arg8_(a8), arg9_(a9), arg10_(a10) {} |
| 680 | |
| 681 | template <typename Result, typename ArgumentTuple> |
| 682 | Result Perform(const ArgumentTuple& args) { |
| 683 | // We extract the callable to a variable before invoking it, in |
| 684 | // case it is a functor passed by value and its operator() is not |
| 685 | // const. |
| 686 | typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function = |
| 687 | ::std::tr1::get<N>(args); |
| 688 | return function(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_, arg8_, |
| 689 | arg9_, arg10_); |
| 690 | } |
| 691 | private: |
| 692 | const A1 arg1_; |
| 693 | const A2 arg2_; |
| 694 | const A3 arg3_; |
| 695 | const A4 arg4_; |
| 696 | const A5 arg5_; |
| 697 | const A6 arg6_; |
| 698 | const A7 arg7_; |
| 699 | const A8 arg8_; |
| 700 | const A9 arg9_; |
| 701 | const A10 arg10_; |
| 702 | }; |
| 703 | |
| 704 | // An INTERNAL macro for extracting the type of a tuple field. It's |
| 705 | // subject to change without notice - DO NOT USE IN USER CODE! |
| 706 | #define GMOCK_FIELD(Tuple, N) \ |
| 707 | typename ::std::tr1::tuple_element<N, Tuple>::type |
| 708 | |
| 709 | // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the |
| 710 | // type of an n-ary function whose i-th (1-based) argument type is the |
| 711 | // k{i}-th (0-based) field of ArgumentTuple, which must be a tuple |
| 712 | // type, and whose return type is Result. For example, |
| 713 | // SelectArgs<int, ::std::tr1::tuple<bool, char, double, long>, 0, 3>::type |
| 714 | // is int(bool, long). |
| 715 | // |
| 716 | // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args) |
| 717 | // returns the selected fields (k1, k2, ..., k_n) of args as a tuple. |
| 718 | // For example, |
| 719 | // SelectArgs<int, ::std::tr1::tuple<bool, char, double>, 2, 0>::Select( |
| 720 | // ::std::tr1::make_tuple(true, 'a', 2.5)) |
| 721 | // returns ::std::tr1::tuple (2.5, true). |
| 722 | // |
| 723 | // The numbers in list k1, k2, ..., k_n must be >= 0, where n can be |
| 724 | // in the range [0, 10]. Duplicates are allowed and they don't have |
| 725 | // to be in an ascending or descending order. |
| 726 | |
| 727 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 728 | int k4, int k5, int k6, int k7, int k8, int k9, int k10> |
| 729 | class SelectArgs { |
| 730 | public: |
| 731 | typedef Result type(GMOCK_FIELD(ArgumentTuple, k1), |
| 732 | GMOCK_FIELD(ArgumentTuple, k2), GMOCK_FIELD(ArgumentTuple, k3), |
| 733 | GMOCK_FIELD(ArgumentTuple, k4), GMOCK_FIELD(ArgumentTuple, k5), |
| 734 | GMOCK_FIELD(ArgumentTuple, k6), GMOCK_FIELD(ArgumentTuple, k7), |
| 735 | GMOCK_FIELD(ArgumentTuple, k8), GMOCK_FIELD(ArgumentTuple, k9), |
| 736 | GMOCK_FIELD(ArgumentTuple, k10)); |
| 737 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 738 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 739 | using ::std::tr1::get; |
| 740 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 741 | get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args), |
| 742 | get<k8>(args), get<k9>(args), get<k10>(args)); |
| 743 | } |
| 744 | }; |
| 745 | |
| 746 | template <typename Result, typename ArgumentTuple> |
| 747 | class SelectArgs<Result, ArgumentTuple, |
| 748 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { |
| 749 | public: |
| 750 | typedef Result type(); |
| 751 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 752 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 753 | using ::std::tr1::get; |
| 754 | return SelectedArgs(); |
| 755 | } |
| 756 | }; |
| 757 | |
| 758 | template <typename Result, typename ArgumentTuple, int k1> |
| 759 | class SelectArgs<Result, ArgumentTuple, |
| 760 | k1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { |
| 761 | public: |
| 762 | typedef Result type(GMOCK_FIELD(ArgumentTuple, k1)); |
| 763 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 764 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 765 | using ::std::tr1::get; |
| 766 | return SelectedArgs(get<k1>(args)); |
| 767 | } |
| 768 | }; |
| 769 | |
| 770 | template <typename Result, typename ArgumentTuple, int k1, int k2> |
| 771 | class SelectArgs<Result, ArgumentTuple, |
| 772 | k1, k2, -1, -1, -1, -1, -1, -1, -1, -1> { |
| 773 | public: |
| 774 | typedef Result type(GMOCK_FIELD(ArgumentTuple, k1), |
| 775 | GMOCK_FIELD(ArgumentTuple, k2)); |
| 776 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 777 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 778 | using ::std::tr1::get; |
| 779 | return SelectedArgs(get<k1>(args), get<k2>(args)); |
| 780 | } |
| 781 | }; |
| 782 | |
| 783 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3> |
| 784 | class SelectArgs<Result, ArgumentTuple, |
| 785 | k1, k2, k3, -1, -1, -1, -1, -1, -1, -1> { |
| 786 | public: |
| 787 | typedef Result type(GMOCK_FIELD(ArgumentTuple, k1), |
| 788 | GMOCK_FIELD(ArgumentTuple, k2), GMOCK_FIELD(ArgumentTuple, k3)); |
| 789 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 790 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 791 | using ::std::tr1::get; |
| 792 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args)); |
| 793 | } |
| 794 | }; |
| 795 | |
| 796 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 797 | int k4> |
| 798 | class SelectArgs<Result, ArgumentTuple, |
| 799 | k1, k2, k3, k4, -1, -1, -1, -1, -1, -1> { |
| 800 | public: |
| 801 | typedef Result type(GMOCK_FIELD(ArgumentTuple, k1), |
| 802 | GMOCK_FIELD(ArgumentTuple, k2), GMOCK_FIELD(ArgumentTuple, k3), |
| 803 | GMOCK_FIELD(ArgumentTuple, k4)); |
| 804 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 805 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 806 | using ::std::tr1::get; |
| 807 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 808 | get<k4>(args)); |
| 809 | } |
| 810 | }; |
| 811 | |
| 812 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 813 | int k4, int k5> |
| 814 | class SelectArgs<Result, ArgumentTuple, |
| 815 | k1, k2, k3, k4, k5, -1, -1, -1, -1, -1> { |
| 816 | public: |
| 817 | typedef Result type(GMOCK_FIELD(ArgumentTuple, k1), |
| 818 | GMOCK_FIELD(ArgumentTuple, k2), GMOCK_FIELD(ArgumentTuple, k3), |
| 819 | GMOCK_FIELD(ArgumentTuple, k4), GMOCK_FIELD(ArgumentTuple, k5)); |
| 820 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 821 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 822 | using ::std::tr1::get; |
| 823 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 824 | get<k4>(args), get<k5>(args)); |
| 825 | } |
| 826 | }; |
| 827 | |
| 828 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 829 | int k4, int k5, int k6> |
| 830 | class SelectArgs<Result, ArgumentTuple, |
| 831 | k1, k2, k3, k4, k5, k6, -1, -1, -1, -1> { |
| 832 | public: |
| 833 | typedef Result type(GMOCK_FIELD(ArgumentTuple, k1), |
| 834 | GMOCK_FIELD(ArgumentTuple, k2), GMOCK_FIELD(ArgumentTuple, k3), |
| 835 | GMOCK_FIELD(ArgumentTuple, k4), GMOCK_FIELD(ArgumentTuple, k5), |
| 836 | GMOCK_FIELD(ArgumentTuple, k6)); |
| 837 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 838 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 839 | using ::std::tr1::get; |
| 840 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 841 | get<k4>(args), get<k5>(args), get<k6>(args)); |
| 842 | } |
| 843 | }; |
| 844 | |
| 845 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 846 | int k4, int k5, int k6, int k7> |
| 847 | class SelectArgs<Result, ArgumentTuple, |
| 848 | k1, k2, k3, k4, k5, k6, k7, -1, -1, -1> { |
| 849 | public: |
| 850 | typedef Result type(GMOCK_FIELD(ArgumentTuple, k1), |
| 851 | GMOCK_FIELD(ArgumentTuple, k2), GMOCK_FIELD(ArgumentTuple, k3), |
| 852 | GMOCK_FIELD(ArgumentTuple, k4), GMOCK_FIELD(ArgumentTuple, k5), |
| 853 | GMOCK_FIELD(ArgumentTuple, k6), GMOCK_FIELD(ArgumentTuple, k7)); |
| 854 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 855 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 856 | using ::std::tr1::get; |
| 857 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 858 | get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args)); |
| 859 | } |
| 860 | }; |
| 861 | |
| 862 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 863 | int k4, int k5, int k6, int k7, int k8> |
| 864 | class SelectArgs<Result, ArgumentTuple, |
| 865 | k1, k2, k3, k4, k5, k6, k7, k8, -1, -1> { |
| 866 | public: |
| 867 | typedef Result type(GMOCK_FIELD(ArgumentTuple, k1), |
| 868 | GMOCK_FIELD(ArgumentTuple, k2), GMOCK_FIELD(ArgumentTuple, k3), |
| 869 | GMOCK_FIELD(ArgumentTuple, k4), GMOCK_FIELD(ArgumentTuple, k5), |
| 870 | GMOCK_FIELD(ArgumentTuple, k6), GMOCK_FIELD(ArgumentTuple, k7), |
| 871 | GMOCK_FIELD(ArgumentTuple, k8)); |
| 872 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 873 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 874 | using ::std::tr1::get; |
| 875 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 876 | get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args), |
| 877 | get<k8>(args)); |
| 878 | } |
| 879 | }; |
| 880 | |
| 881 | template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, |
| 882 | int k4, int k5, int k6, int k7, int k8, int k9> |
| 883 | class SelectArgs<Result, ArgumentTuple, |
| 884 | k1, k2, k3, k4, k5, k6, k7, k8, k9, -1> { |
| 885 | public: |
| 886 | typedef Result type(GMOCK_FIELD(ArgumentTuple, k1), |
| 887 | GMOCK_FIELD(ArgumentTuple, k2), GMOCK_FIELD(ArgumentTuple, k3), |
| 888 | GMOCK_FIELD(ArgumentTuple, k4), GMOCK_FIELD(ArgumentTuple, k5), |
| 889 | GMOCK_FIELD(ArgumentTuple, k6), GMOCK_FIELD(ArgumentTuple, k7), |
| 890 | GMOCK_FIELD(ArgumentTuple, k8), GMOCK_FIELD(ArgumentTuple, k9)); |
| 891 | typedef typename Function<type>::ArgumentTuple SelectedArgs; |
| 892 | static SelectedArgs Select(const ArgumentTuple& args) { |
| 893 | using ::std::tr1::get; |
| 894 | return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args), |
| 895 | get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args), |
| 896 | get<k8>(args), get<k9>(args)); |
| 897 | } |
| 898 | }; |
| 899 | |
| 900 | #undef GMOCK_FIELD |
| 901 | |
| 902 | // Implements the WithArgs action. |
| 903 | template <typename InnerAction, int k1 = -1, int k2 = -1, int k3 = -1, |
| 904 | int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1, |
| 905 | int k9 = -1, int k10 = -1> |
| 906 | class WithArgsAction { |
| 907 | public: |
| 908 | explicit WithArgsAction(const InnerAction& action) : action_(action) {} |
| 909 | |
| 910 | template <typename F> |
| 911 | operator Action<F>() const { |
| 912 | typedef typename Function<F>::Result Result; |
| 913 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 914 | typedef typename SelectArgs<Result, ArgumentTuple, |
| 915 | k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type |
| 916 | InnerFunctionType; |
| 917 | |
| 918 | class Impl : public ActionInterface<F> { |
| 919 | public: |
| 920 | explicit Impl(const InnerAction& action) : action_(action) {} |
| 921 | |
| 922 | virtual Result Perform(const ArgumentTuple& args) { |
| 923 | return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, |
| 924 | k4, k5, k6, k7, k8, k9, k10>::Select(args)); |
| 925 | } |
| 926 | private: |
| 927 | Action<InnerFunctionType> action_; |
| 928 | }; |
| 929 | |
| 930 | return MakeAction(new Impl(action_)); |
| 931 | } |
| 932 | private: |
| 933 | const InnerAction action_; |
| 934 | }; |
| 935 | |
| 936 | // Does two actions sequentially. Used for implementing the DoAll(a1, |
| 937 | // a2, ...) action. |
| 938 | template <typename Action1, typename Action2> |
| 939 | class DoBothAction { |
| 940 | public: |
| 941 | DoBothAction(Action1 action1, Action2 action2) |
| 942 | : action1_(action1), action2_(action2) {} |
| 943 | |
| 944 | // This template type conversion operator allows DoAll(a1, ..., a_n) |
| 945 | // to be used in ANY function of compatible type. |
| 946 | template <typename F> |
| 947 | operator Action<F>() const { |
| 948 | typedef typename Function<F>::Result Result; |
| 949 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 950 | typedef typename Function<F>::MakeResultVoid VoidResult; |
| 951 | |
| 952 | // Implements the DoAll(...) action for a particular function type F. |
| 953 | class Impl : public ActionInterface<F> { |
| 954 | public: |
| 955 | Impl(const Action<VoidResult>& action1, const Action<F>& action2) |
| 956 | : action1_(action1), action2_(action2) {} |
| 957 | |
| 958 | virtual Result Perform(const ArgumentTuple& args) { |
| 959 | action1_.Perform(args); |
| 960 | return action2_.Perform(args); |
| 961 | } |
| 962 | private: |
| 963 | const Action<VoidResult> action1_; |
| 964 | const Action<F> action2_; |
| 965 | }; |
| 966 | |
| 967 | return Action<F>(new Impl(action1_, action2_)); |
| 968 | } |
| 969 | private: |
| 970 | Action1 action1_; |
| 971 | Action2 action2_; |
| 972 | }; |
| 973 | |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 974 | // A macro from the ACTION* family (defined later in this file) |
| 975 | // defines an action that can be used in a mock function. Typically, |
| 976 | // these actions only care about a subset of the arguments of the mock |
| 977 | // function. For example, if such an action only uses the second |
| 978 | // argument, it can be used in any mock function that takes >= 2 |
| 979 | // arguments where the type of the second argument is compatible. |
| 980 | // |
| 981 | // Therefore, the action implementation must be prepared to take more |
| 982 | // arguments than it needs. The ExcessiveArg type is used to |
| 983 | // represent those excessive arguments. In order to keep the compiler |
| 984 | // error messages tractable, we define it in the testing namespace |
| 985 | // instead of testing::internal. However, this is an INTERNAL TYPE |
| 986 | // and subject to change without notice, so a user MUST NOT USE THIS |
| 987 | // TYPE DIRECTLY. |
| 988 | struct ExcessiveArg {}; |
| 989 | |
| 990 | // A helper class needed for implementing the ACTION* macros. |
| 991 | template <typename Result, class Impl> |
| 992 | class ActionHelper { |
| 993 | public: |
| 994 | static Result Perform(Impl* impl, const ::std::tr1::tuple<>& args) { |
| 995 | using ::std::tr1::get; |
| 996 | return impl->gmock_PerformImpl(args, ExcessiveArg(), ExcessiveArg(), |
| 997 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 998 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg()); |
| 999 | } |
| 1000 | |
| 1001 | template <typename A0> |
| 1002 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0>& args) { |
| 1003 | using ::std::tr1::get; |
| 1004 | return impl->gmock_PerformImpl(args, get<0>(args), ExcessiveArg(), |
| 1005 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 1006 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg()); |
| 1007 | } |
| 1008 | |
| 1009 | template <typename A0, typename A1> |
| 1010 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1>& args) { |
| 1011 | using ::std::tr1::get; |
| 1012 | return impl->gmock_PerformImpl(args, get<0>(args), get<1>(args), |
| 1013 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 1014 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg()); |
| 1015 | } |
| 1016 | |
| 1017 | template <typename A0, typename A1, typename A2> |
| 1018 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2>& args) { |
| 1019 | using ::std::tr1::get; |
| 1020 | return impl->gmock_PerformImpl(args, get<0>(args), get<1>(args), |
| 1021 | get<2>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), |
| 1022 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg()); |
| 1023 | } |
| 1024 | |
| 1025 | template <typename A0, typename A1, typename A2, typename A3> |
| 1026 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, |
| 1027 | A3>& args) { |
| 1028 | using ::std::tr1::get; |
| 1029 | return impl->gmock_PerformImpl(args, get<0>(args), get<1>(args), |
| 1030 | get<2>(args), get<3>(args), ExcessiveArg(), ExcessiveArg(), |
| 1031 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg()); |
| 1032 | } |
| 1033 | |
| 1034 | template <typename A0, typename A1, typename A2, typename A3, typename A4> |
| 1035 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, |
| 1036 | A4>& args) { |
| 1037 | using ::std::tr1::get; |
| 1038 | return impl->gmock_PerformImpl(args, get<0>(args), get<1>(args), |
| 1039 | get<2>(args), get<3>(args), get<4>(args), ExcessiveArg(), |
| 1040 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg()); |
| 1041 | } |
| 1042 | |
| 1043 | template <typename A0, typename A1, typename A2, typename A3, typename A4, |
| 1044 | typename A5> |
| 1045 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, |
| 1046 | A5>& args) { |
| 1047 | using ::std::tr1::get; |
| 1048 | return impl->gmock_PerformImpl(args, get<0>(args), get<1>(args), |
| 1049 | get<2>(args), get<3>(args), get<4>(args), get<5>(args), ExcessiveArg(), |
| 1050 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg()); |
| 1051 | } |
| 1052 | |
| 1053 | template <typename A0, typename A1, typename A2, typename A3, typename A4, |
| 1054 | typename A5, typename A6> |
| 1055 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, |
| 1056 | A5, A6>& args) { |
| 1057 | using ::std::tr1::get; |
| 1058 | return impl->gmock_PerformImpl(args, get<0>(args), get<1>(args), |
| 1059 | get<2>(args), get<3>(args), get<4>(args), get<5>(args), get<6>(args), |
| 1060 | ExcessiveArg(), ExcessiveArg(), ExcessiveArg()); |
| 1061 | } |
| 1062 | |
| 1063 | template <typename A0, typename A1, typename A2, typename A3, typename A4, |
| 1064 | typename A5, typename A6, typename A7> |
| 1065 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, |
| 1066 | A5, A6, A7>& args) { |
| 1067 | using ::std::tr1::get; |
| 1068 | return impl->gmock_PerformImpl(args, get<0>(args), get<1>(args), |
| 1069 | get<2>(args), get<3>(args), get<4>(args), get<5>(args), get<6>(args), |
| 1070 | get<7>(args), ExcessiveArg(), ExcessiveArg()); |
| 1071 | } |
| 1072 | |
| 1073 | template <typename A0, typename A1, typename A2, typename A3, typename A4, |
| 1074 | typename A5, typename A6, typename A7, typename A8> |
| 1075 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, |
| 1076 | A5, A6, A7, A8>& args) { |
| 1077 | using ::std::tr1::get; |
| 1078 | return impl->gmock_PerformImpl(args, get<0>(args), get<1>(args), |
| 1079 | get<2>(args), get<3>(args), get<4>(args), get<5>(args), get<6>(args), |
| 1080 | get<7>(args), get<8>(args), ExcessiveArg()); |
| 1081 | } |
| 1082 | |
| 1083 | template <typename A0, typename A1, typename A2, typename A3, typename A4, |
| 1084 | typename A5, typename A6, typename A7, typename A8, typename A9> |
| 1085 | static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4, |
| 1086 | A5, A6, A7, A8, A9>& args) { |
| 1087 | using ::std::tr1::get; |
| 1088 | return impl->gmock_PerformImpl(args, get<0>(args), get<1>(args), |
| 1089 | get<2>(args), get<3>(args), get<4>(args), get<5>(args), get<6>(args), |
| 1090 | get<7>(args), get<8>(args), get<9>(args)); |
| 1091 | } |
| 1092 | }; |
| 1093 | |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 1094 | } // namespace internal |
| 1095 | |
| 1096 | // Various overloads for Invoke(). |
| 1097 | |
| 1098 | // Creates an action that invokes 'function_impl' with the mock |
| 1099 | // function's arguments. |
| 1100 | template <typename FunctionImpl> |
| 1101 | PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke( |
| 1102 | FunctionImpl function_impl) { |
| 1103 | return MakePolymorphicAction( |
| 1104 | internal::InvokeAction<FunctionImpl>(function_impl)); |
| 1105 | } |
| 1106 | |
| 1107 | // Creates an action that invokes the given method on the given object |
| 1108 | // with the mock function's arguments. |
| 1109 | template <class Class, typename MethodPtr> |
| 1110 | PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke( |
| 1111 | Class* obj_ptr, MethodPtr method_ptr) { |
| 1112 | return MakePolymorphicAction( |
| 1113 | internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr)); |
| 1114 | } |
| 1115 | |
| 1116 | // Creates a reference wrapper for the given L-value. If necessary, |
| 1117 | // you can explicitly specify the type of the reference. For example, |
| 1118 | // suppose 'derived' is an object of type Derived, ByRef(derived) |
| 1119 | // would wrap a Derived&. If you want to wrap a const Base& instead, |
| 1120 | // where Base is a base class of Derived, just write: |
| 1121 | // |
| 1122 | // ByRef<const Base>(derived) |
| 1123 | template <typename T> |
| 1124 | inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT |
| 1125 | return internal::ReferenceWrapper<T>(l_value); |
| 1126 | } |
| 1127 | |
| 1128 | // Various overloads for InvokeArgument<N>(). |
| 1129 | // |
| 1130 | // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th |
| 1131 | // (0-based) argument, which must be a k-ary callable, of the mock |
| 1132 | // function, with arguments a1, a2, ..., a_k. |
| 1133 | // |
| 1134 | // Notes: |
| 1135 | // |
| 1136 | // 1. The arguments are passed by value by default. If you need to |
| 1137 | // pass an argument by reference, wrap it inside ByRef(). For |
| 1138 | // example, |
| 1139 | // |
| 1140 | // InvokeArgument<1>(5, string("Hello"), ByRef(foo)) |
| 1141 | // |
| 1142 | // passes 5 and string("Hello") by value, and passes foo by |
| 1143 | // reference. |
| 1144 | // |
| 1145 | // 2. If the callable takes an argument by reference but ByRef() is |
| 1146 | // not used, it will receive the reference to a copy of the value, |
| 1147 | // instead of the original value. For example, when the 0-th |
| 1148 | // argument of the mock function takes a const string&, the action |
| 1149 | // |
| 1150 | // InvokeArgument<0>(string("Hello")) |
| 1151 | // |
| 1152 | // makes a copy of the temporary string("Hello") object and passes a |
| 1153 | // reference of the copy, instead of the original temporary object, |
| 1154 | // to the callable. This makes it easy for a user to define an |
| 1155 | // InvokeArgument action from temporary values and have it performed |
| 1156 | // later. |
| 1157 | template <size_t N> |
| 1158 | inline PolymorphicAction<internal::InvokeArgumentAction0<N> > InvokeArgument() { |
| 1159 | return MakePolymorphicAction(internal::InvokeArgumentAction0<N>()); |
| 1160 | } |
| 1161 | |
| 1162 | // We deliberately pass a1 by value instead of const reference here in |
| 1163 | // case it is a C-string literal. If we had declared the parameter as |
| 1164 | // 'const A1& a1' and write InvokeArgument<0>("Hi"), the compiler |
| 1165 | // would've thought A1 is 'char[3]', which causes trouble as the |
| 1166 | // implementation needs to copy a value of type A1. By declaring the |
| 1167 | // parameter as 'A1 a1', the compiler will correctly infer that A1 is |
| 1168 | // 'const char*' when it sees InvokeArgument<0>("Hi"). |
| 1169 | // |
| 1170 | // Since this function is defined inline, the compiler can get rid of |
| 1171 | // the copying of the arguments. Therefore the performance won't be |
| 1172 | // hurt. |
| 1173 | template <size_t N, typename A1> |
| 1174 | inline PolymorphicAction<internal::InvokeArgumentAction1<N, A1> > |
| 1175 | InvokeArgument(A1 a1) { |
| 1176 | return MakePolymorphicAction(internal::InvokeArgumentAction1<N, A1>(a1)); |
| 1177 | } |
| 1178 | |
| 1179 | template <size_t N, typename A1, typename A2> |
| 1180 | inline PolymorphicAction<internal::InvokeArgumentAction2<N, A1, A2> > |
| 1181 | InvokeArgument(A1 a1, A2 a2) { |
| 1182 | return MakePolymorphicAction( |
| 1183 | internal::InvokeArgumentAction2<N, A1, A2>(a1, a2)); |
| 1184 | } |
| 1185 | |
| 1186 | template <size_t N, typename A1, typename A2, typename A3> |
| 1187 | inline PolymorphicAction<internal::InvokeArgumentAction3<N, A1, A2, A3> > |
| 1188 | InvokeArgument(A1 a1, A2 a2, A3 a3) { |
| 1189 | return MakePolymorphicAction( |
| 1190 | internal::InvokeArgumentAction3<N, A1, A2, A3>(a1, a2, a3)); |
| 1191 | } |
| 1192 | |
| 1193 | template <size_t N, typename A1, typename A2, typename A3, typename A4> |
| 1194 | inline PolymorphicAction<internal::InvokeArgumentAction4<N, A1, A2, A3, A4> > |
| 1195 | InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4) { |
| 1196 | return MakePolymorphicAction( |
| 1197 | internal::InvokeArgumentAction4<N, A1, A2, A3, A4>(a1, a2, a3, a4)); |
| 1198 | } |
| 1199 | |
| 1200 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 1201 | typename A5> |
| 1202 | inline PolymorphicAction<internal::InvokeArgumentAction5<N, A1, A2, A3, A4, |
| 1203 | A5> > |
| 1204 | InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { |
| 1205 | return MakePolymorphicAction( |
| 1206 | internal::InvokeArgumentAction5<N, A1, A2, A3, A4, A5>(a1, a2, a3, a4, |
| 1207 | a5)); |
| 1208 | } |
| 1209 | |
| 1210 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 1211 | typename A5, typename A6> |
| 1212 | inline PolymorphicAction<internal::InvokeArgumentAction6<N, A1, A2, A3, A4, A5, |
| 1213 | A6> > |
| 1214 | InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { |
| 1215 | return MakePolymorphicAction( |
| 1216 | internal::InvokeArgumentAction6<N, A1, A2, A3, A4, A5, A6>(a1, a2, a3, |
| 1217 | a4, a5, a6)); |
| 1218 | } |
| 1219 | |
| 1220 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 1221 | typename A5, typename A6, typename A7> |
| 1222 | inline PolymorphicAction<internal::InvokeArgumentAction7<N, A1, A2, A3, A4, A5, |
| 1223 | A6, A7> > |
| 1224 | InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { |
| 1225 | return MakePolymorphicAction( |
| 1226 | internal::InvokeArgumentAction7<N, A1, A2, A3, A4, A5, A6, A7>(a1, a2, |
| 1227 | a3, a4, a5, a6, a7)); |
| 1228 | } |
| 1229 | |
| 1230 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 1231 | typename A5, typename A6, typename A7, typename A8> |
| 1232 | inline PolymorphicAction<internal::InvokeArgumentAction8<N, A1, A2, A3, A4, A5, |
| 1233 | A6, A7, A8> > |
| 1234 | InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { |
| 1235 | return MakePolymorphicAction( |
| 1236 | internal::InvokeArgumentAction8<N, A1, A2, A3, A4, A5, A6, A7, A8>(a1, |
| 1237 | a2, a3, a4, a5, a6, a7, a8)); |
| 1238 | } |
| 1239 | |
| 1240 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 1241 | typename A5, typename A6, typename A7, typename A8, typename A9> |
| 1242 | inline PolymorphicAction<internal::InvokeArgumentAction9<N, A1, A2, A3, A4, A5, |
| 1243 | A6, A7, A8, A9> > |
| 1244 | InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { |
| 1245 | return MakePolymorphicAction( |
| 1246 | internal::InvokeArgumentAction9<N, A1, A2, A3, A4, A5, A6, A7, A8, |
| 1247 | A9>(a1, a2, a3, a4, a5, a6, a7, a8, a9)); |
| 1248 | } |
| 1249 | |
| 1250 | template <size_t N, typename A1, typename A2, typename A3, typename A4, |
| 1251 | typename A5, typename A6, typename A7, typename A8, typename A9, |
| 1252 | typename A10> |
| 1253 | inline PolymorphicAction<internal::InvokeArgumentAction10<N, A1, A2, A3, A4, |
| 1254 | A5, A6, A7, A8, A9, A10> > |
| 1255 | InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, |
| 1256 | A10 a10) { |
| 1257 | return MakePolymorphicAction( |
| 1258 | internal::InvokeArgumentAction10<N, A1, A2, A3, A4, A5, A6, A7, A8, A9, |
| 1259 | A10>(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)); |
| 1260 | } |
| 1261 | |
| 1262 | // WithoutArgs(inner_action) can be used in a mock function with a |
| 1263 | // non-empty argument list to perform inner_action, which takes no |
| 1264 | // argument. In other words, it adapts an action accepting no |
| 1265 | // argument to one that accepts (and ignores) arguments. |
| 1266 | template <typename InnerAction> |
| 1267 | inline internal::WithArgsAction<InnerAction> |
| 1268 | WithoutArgs(const InnerAction& action) { |
| 1269 | return internal::WithArgsAction<InnerAction>(action); |
| 1270 | } |
| 1271 | |
| 1272 | // WithArg<k>(an_action) creates an action that passes the k-th |
| 1273 | // (0-based) argument of the mock function to an_action and performs |
| 1274 | // it. It adapts an action accepting one argument to one that accepts |
| 1275 | // multiple arguments. For convenience, we also provide |
| 1276 | // WithArgs<k>(an_action) (defined below) as a synonym. |
| 1277 | template <int k, typename InnerAction> |
| 1278 | inline internal::WithArgsAction<InnerAction, k> |
| 1279 | WithArg(const InnerAction& action) { |
| 1280 | return internal::WithArgsAction<InnerAction, k>(action); |
| 1281 | } |
| 1282 | |
| 1283 | // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes |
| 1284 | // the selected arguments of the mock function to an_action and |
| 1285 | // performs it. It serves as an adaptor between actions with |
| 1286 | // different argument lists. C++ doesn't support default arguments for |
| 1287 | // function templates, so we have to overload it. |
| 1288 | template <int k1, typename InnerAction> |
| 1289 | inline internal::WithArgsAction<InnerAction, k1> |
| 1290 | WithArgs(const InnerAction& action) { |
| 1291 | return internal::WithArgsAction<InnerAction, k1>(action); |
| 1292 | } |
| 1293 | |
| 1294 | template <int k1, int k2, typename InnerAction> |
| 1295 | inline internal::WithArgsAction<InnerAction, k1, k2> |
| 1296 | WithArgs(const InnerAction& action) { |
| 1297 | return internal::WithArgsAction<InnerAction, k1, k2>(action); |
| 1298 | } |
| 1299 | |
| 1300 | template <int k1, int k2, int k3, typename InnerAction> |
| 1301 | inline internal::WithArgsAction<InnerAction, k1, k2, k3> |
| 1302 | WithArgs(const InnerAction& action) { |
| 1303 | return internal::WithArgsAction<InnerAction, k1, k2, k3>(action); |
| 1304 | } |
| 1305 | |
| 1306 | template <int k1, int k2, int k3, int k4, typename InnerAction> |
| 1307 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4> |
| 1308 | WithArgs(const InnerAction& action) { |
| 1309 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action); |
| 1310 | } |
| 1311 | |
| 1312 | template <int k1, int k2, int k3, int k4, int k5, typename InnerAction> |
| 1313 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5> |
| 1314 | WithArgs(const InnerAction& action) { |
| 1315 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action); |
| 1316 | } |
| 1317 | |
| 1318 | template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction> |
| 1319 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6> |
| 1320 | WithArgs(const InnerAction& action) { |
| 1321 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action); |
| 1322 | } |
| 1323 | |
| 1324 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, |
| 1325 | typename InnerAction> |
| 1326 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7> |
| 1327 | WithArgs(const InnerAction& action) { |
| 1328 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, |
| 1329 | k7>(action); |
| 1330 | } |
| 1331 | |
| 1332 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, |
| 1333 | typename InnerAction> |
| 1334 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8> |
| 1335 | WithArgs(const InnerAction& action) { |
| 1336 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, |
| 1337 | k8>(action); |
| 1338 | } |
| 1339 | |
| 1340 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, |
| 1341 | int k9, typename InnerAction> |
| 1342 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9> |
| 1343 | WithArgs(const InnerAction& action) { |
| 1344 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, |
| 1345 | k9>(action); |
| 1346 | } |
| 1347 | |
| 1348 | template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, |
| 1349 | int k9, int k10, typename InnerAction> |
| 1350 | inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, |
| 1351 | k9, k10> |
| 1352 | WithArgs(const InnerAction& action) { |
| 1353 | return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, |
| 1354 | k9, k10>(action); |
| 1355 | } |
| 1356 | |
| 1357 | // Creates an action that does actions a1, a2, ..., sequentially in |
| 1358 | // each invocation. |
| 1359 | template <typename Action1, typename Action2> |
| 1360 | inline internal::DoBothAction<Action1, Action2> |
| 1361 | DoAll(Action1 a1, Action2 a2) { |
| 1362 | return internal::DoBothAction<Action1, Action2>(a1, a2); |
| 1363 | } |
| 1364 | |
| 1365 | template <typename Action1, typename Action2, typename Action3> |
| 1366 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 1367 | Action3> > |
| 1368 | DoAll(Action1 a1, Action2 a2, Action3 a3) { |
| 1369 | return DoAll(a1, DoAll(a2, a3)); |
| 1370 | } |
| 1371 | |
| 1372 | template <typename Action1, typename Action2, typename Action3, |
| 1373 | typename Action4> |
| 1374 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 1375 | internal::DoBothAction<Action3, Action4> > > |
| 1376 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) { |
| 1377 | return DoAll(a1, DoAll(a2, a3, a4)); |
| 1378 | } |
| 1379 | |
| 1380 | template <typename Action1, typename Action2, typename Action3, |
| 1381 | typename Action4, typename Action5> |
| 1382 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 1383 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 1384 | Action5> > > > |
| 1385 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) { |
| 1386 | return DoAll(a1, DoAll(a2, a3, a4, a5)); |
| 1387 | } |
| 1388 | |
| 1389 | template <typename Action1, typename Action2, typename Action3, |
| 1390 | typename Action4, typename Action5, typename Action6> |
| 1391 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 1392 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 1393 | internal::DoBothAction<Action5, Action6> > > > > |
| 1394 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) { |
| 1395 | return DoAll(a1, DoAll(a2, a3, a4, a5, a6)); |
| 1396 | } |
| 1397 | |
| 1398 | template <typename Action1, typename Action2, typename Action3, |
| 1399 | typename Action4, typename Action5, typename Action6, typename Action7> |
| 1400 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 1401 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 1402 | internal::DoBothAction<Action5, internal::DoBothAction<Action6, |
| 1403 | Action7> > > > > > |
| 1404 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, |
| 1405 | Action7 a7) { |
| 1406 | return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7)); |
| 1407 | } |
| 1408 | |
| 1409 | template <typename Action1, typename Action2, typename Action3, |
| 1410 | typename Action4, typename Action5, typename Action6, typename Action7, |
| 1411 | typename Action8> |
| 1412 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 1413 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 1414 | internal::DoBothAction<Action5, internal::DoBothAction<Action6, |
| 1415 | internal::DoBothAction<Action7, Action8> > > > > > > |
| 1416 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, |
| 1417 | Action7 a7, Action8 a8) { |
| 1418 | return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8)); |
| 1419 | } |
| 1420 | |
| 1421 | template <typename Action1, typename Action2, typename Action3, |
| 1422 | typename Action4, typename Action5, typename Action6, typename Action7, |
| 1423 | typename Action8, typename Action9> |
| 1424 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 1425 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 1426 | internal::DoBothAction<Action5, internal::DoBothAction<Action6, |
| 1427 | internal::DoBothAction<Action7, internal::DoBothAction<Action8, |
| 1428 | Action9> > > > > > > > |
| 1429 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, |
| 1430 | Action7 a7, Action8 a8, Action9 a9) { |
| 1431 | return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9)); |
| 1432 | } |
| 1433 | |
| 1434 | template <typename Action1, typename Action2, typename Action3, |
| 1435 | typename Action4, typename Action5, typename Action6, typename Action7, |
| 1436 | typename Action8, typename Action9, typename Action10> |
| 1437 | inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, |
| 1438 | internal::DoBothAction<Action3, internal::DoBothAction<Action4, |
| 1439 | internal::DoBothAction<Action5, internal::DoBothAction<Action6, |
| 1440 | internal::DoBothAction<Action7, internal::DoBothAction<Action8, |
| 1441 | internal::DoBothAction<Action9, Action10> > > > > > > > > |
| 1442 | DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, |
| 1443 | Action7 a7, Action8 a8, Action9 a9, Action10 a10) { |
| 1444 | return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10)); |
| 1445 | } |
| 1446 | |
| 1447 | } // namespace testing |
| 1448 | |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1449 | // The ACTION* family of macros can be used in a namespace scope to |
| 1450 | // define custom actions easily. The syntax: |
| 1451 | // |
| 1452 | // ACTION(name) { statements; } |
| 1453 | // |
| 1454 | // will define an action with the given name that executes the |
| 1455 | // statements. The value returned by the statements will be used as |
| 1456 | // the return value of the action. Inside the statements, you can |
| 1457 | // refer to the K-th (0-based) argument of the mock function by |
| 1458 | // 'argK', and refer to its type by 'argK_type'. For example: |
| 1459 | // |
| 1460 | // ACTION(IncrementArg1) { |
| 1461 | // arg1_type temp = arg1; |
| 1462 | // return ++(*temp); |
| 1463 | // } |
| 1464 | // |
| 1465 | // allows you to write |
| 1466 | // |
| 1467 | // ...WillOnce(IncrementArg1()); |
| 1468 | // |
| 1469 | // You can also refer to the entire argument tuple and its type by |
| 1470 | // 'args' and 'args_type', and refer to the mock function type and its |
| 1471 | // return type by 'function_type' and 'return_type'. |
| 1472 | // |
| 1473 | // Note that you don't need to specify the types of the mock function |
| 1474 | // arguments. However rest assured that your code is still type-safe: |
| 1475 | // you'll get a compiler error if *arg1 doesn't support the ++ |
| 1476 | // operator, or if the type of ++(*arg1) isn't compatible with the |
| 1477 | // mock function's return type, for example. |
| 1478 | // |
| 1479 | // Sometimes you'll want to parameterize the action. For that you can use |
| 1480 | // another macro: |
| 1481 | // |
| 1482 | // ACTION_P(name, param_name) { statements; } |
| 1483 | // |
| 1484 | // For example: |
| 1485 | // |
| 1486 | // ACTION_P(Add, n) { return arg0 + n; } |
| 1487 | // |
| 1488 | // will allow you to write: |
| 1489 | // |
| 1490 | // ...WillOnce(Add(5)); |
| 1491 | // |
| 1492 | // Note that you don't need to provide the type of the parameter |
| 1493 | // either. If you need to reference the type of a parameter named |
| 1494 | // 'foo', you can write 'foo_type'. For example, in the body of |
| 1495 | // ACTION_P(Add, n) above, you can write 'n_type' to refer to the type |
| 1496 | // of 'n'. |
| 1497 | // |
| 1498 | // We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support |
| 1499 | // multi-parameter actions. |
| 1500 | // |
| 1501 | // For the purpose of typing, you can view |
| 1502 | // |
| 1503 | // ACTION_Pk(Foo, p1, ..., pk) { ... } |
| 1504 | // |
| 1505 | // as shorthand for |
| 1506 | // |
| 1507 | // template <typename p1_type, ..., typename pk_type> |
| 1508 | // FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... } |
| 1509 | // |
| 1510 | // In particular, you can provide the template type arguments |
| 1511 | // explicitly when invoking Foo(), as in Foo<long, bool>(5, false); |
| 1512 | // although usually you can rely on the compiler to infer the types |
| 1513 | // for you automatically. You can assign the result of expression |
| 1514 | // Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ..., |
| 1515 | // pk_type>. This can be useful when composing actions. |
| 1516 | // |
| 1517 | // You can also overload actions with different numbers of parameters: |
| 1518 | // |
| 1519 | // ACTION_P(Plus, a) { ... } |
| 1520 | // ACTION_P2(Plus, a, b) { ... } |
| 1521 | // |
| 1522 | // While it's tempting to always use the ACTION* macros when defining |
| 1523 | // a new action, you should also consider implementing ActionInterface |
| 1524 | // or using MakePolymorphicAction() instead, especially if you need to |
| 1525 | // use the action a lot. While these approaches require more work, |
| 1526 | // they give you more control on the types of the mock function |
| 1527 | // arguments and the action parameters, which in general leads to |
| 1528 | // better compiler error messages that pay off in the long run. They |
| 1529 | // also allow overloading actions based on parameter types (as opposed |
| 1530 | // to just based on the number of parameters). |
| 1531 | // |
| 1532 | // CAVEAT: |
| 1533 | // |
| 1534 | // ACTION*() can only be used in a namespace scope. The reason is |
| 1535 | // that C++ doesn't yet allow function-local types to be used to |
| 1536 | // instantiate templates. The up-coming C++0x standard will fix this. |
| 1537 | // Once that's done, we'll consider supporting using ACTION*() inside |
| 1538 | // a function. |
| 1539 | // |
| 1540 | // MORE INFORMATION: |
| 1541 | // |
| 1542 | // To learn more about using these macros, please search for 'ACTION' |
| 1543 | // on http://code.google.com/p/googlemock/wiki/CookBook. |
| 1544 | |
| 1545 | #define ACTION(name)\ |
| 1546 | class name##Action {\ |
| 1547 | public:\ |
| 1548 | name##Action() {}\ |
| 1549 | template <typename F>\ |
| 1550 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 1551 | public:\ |
| 1552 | typedef F function_type;\ |
| 1553 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 1554 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 1555 | args_type;\ |
| 1556 | gmock_Impl() {}\ |
| 1557 | virtual return_type Perform(const args_type& args) {\ |
| 1558 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 1559 | Perform(this, args);\ |
| 1560 | }\ |
| 1561 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1562 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1563 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1564 | typename arg9_type>\ |
| 1565 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 1566 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 1567 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 1568 | arg9_type arg9) const;\ |
| 1569 | };\ |
| 1570 | template <typename F> operator ::testing::Action<F>() const {\ |
| 1571 | return ::testing::Action<F>(new gmock_Impl<F>());\ |
| 1572 | }\ |
| 1573 | };\ |
| 1574 | inline name##Action name() {\ |
| 1575 | return name##Action();\ |
| 1576 | }\ |
| 1577 | template <typename F>\ |
| 1578 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1579 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1580 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1581 | typename arg9_type>\ |
| 1582 | typename ::testing::internal::Function<F>::Result\ |
| 1583 | name##Action::\ |
| 1584 | gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \ |
| 1585 | arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \ |
| 1586 | arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \ |
| 1587 | arg8_type arg8, arg9_type arg9) const |
| 1588 | |
| 1589 | #define ACTION_P(name, p0)\ |
| 1590 | template <typename p0##_type>\ |
| 1591 | class name##ActionP {\ |
| 1592 | public:\ |
| 1593 | name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\ |
| 1594 | template <typename F>\ |
| 1595 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 1596 | public:\ |
| 1597 | typedef F function_type;\ |
| 1598 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 1599 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 1600 | args_type;\ |
| 1601 | explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\ |
| 1602 | virtual return_type Perform(const args_type& args) {\ |
| 1603 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 1604 | Perform(this, args);\ |
| 1605 | }\ |
| 1606 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1607 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1608 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1609 | typename arg9_type>\ |
| 1610 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 1611 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 1612 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 1613 | arg9_type arg9) const;\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1614 | p0##_type p0;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1615 | };\ |
| 1616 | template <typename F> operator ::testing::Action<F>() const {\ |
| 1617 | return ::testing::Action<F>(new gmock_Impl<F>(p0));\ |
| 1618 | }\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1619 | p0##_type p0;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1620 | };\ |
| 1621 | template <typename p0##_type>\ |
| 1622 | inline name##ActionP<p0##_type> name(p0##_type p0) {\ |
| 1623 | return name##ActionP<p0##_type>(p0);\ |
| 1624 | }\ |
| 1625 | template <typename p0##_type>\ |
| 1626 | template <typename F>\ |
| 1627 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1628 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1629 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1630 | typename arg9_type>\ |
| 1631 | typename ::testing::internal::Function<F>::Result\ |
| 1632 | name##ActionP<p0##_type>::\ |
| 1633 | gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \ |
| 1634 | arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \ |
| 1635 | arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \ |
| 1636 | arg8_type arg8, arg9_type arg9) const |
| 1637 | |
| 1638 | #define ACTION_P2(name, p0, p1)\ |
| 1639 | template <typename p0##_type, typename p1##_type>\ |
| 1640 | class name##ActionP2 {\ |
| 1641 | public:\ |
| 1642 | name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ |
| 1643 | p1(gmock_p1) {}\ |
| 1644 | template <typename F>\ |
| 1645 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 1646 | public:\ |
| 1647 | typedef F function_type;\ |
| 1648 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 1649 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 1650 | args_type;\ |
| 1651 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ |
| 1652 | p1(gmock_p1) {}\ |
| 1653 | virtual return_type Perform(const args_type& args) {\ |
| 1654 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 1655 | Perform(this, args);\ |
| 1656 | }\ |
| 1657 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1658 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1659 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1660 | typename arg9_type>\ |
| 1661 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 1662 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 1663 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 1664 | arg9_type arg9) const;\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1665 | p0##_type p0;\ |
| 1666 | p1##_type p1;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1667 | };\ |
| 1668 | template <typename F> operator ::testing::Action<F>() const {\ |
| 1669 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\ |
| 1670 | }\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1671 | p0##_type p0;\ |
| 1672 | p1##_type p1;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1673 | };\ |
| 1674 | template <typename p0##_type, typename p1##_type>\ |
| 1675 | inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \ |
| 1676 | p1##_type p1) {\ |
| 1677 | return name##ActionP2<p0##_type, p1##_type>(p0, p1);\ |
| 1678 | }\ |
| 1679 | template <typename p0##_type, typename p1##_type>\ |
| 1680 | template <typename F>\ |
| 1681 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1682 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1683 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1684 | typename arg9_type>\ |
| 1685 | typename ::testing::internal::Function<F>::Result\ |
| 1686 | name##ActionP2<p0##_type, p1##_type>::\ |
| 1687 | gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \ |
| 1688 | arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \ |
| 1689 | arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \ |
| 1690 | arg8_type arg8, arg9_type arg9) const |
| 1691 | |
| 1692 | #define ACTION_P3(name, p0, p1, p2)\ |
| 1693 | template <typename p0##_type, typename p1##_type, typename p2##_type>\ |
| 1694 | class name##ActionP3 {\ |
| 1695 | public:\ |
| 1696 | name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 1697 | p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ |
| 1698 | template <typename F>\ |
| 1699 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 1700 | public:\ |
| 1701 | typedef F function_type;\ |
| 1702 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 1703 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 1704 | args_type;\ |
| 1705 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 1706 | p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ |
| 1707 | virtual return_type Perform(const args_type& args) {\ |
| 1708 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 1709 | Perform(this, args);\ |
| 1710 | }\ |
| 1711 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1712 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1713 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1714 | typename arg9_type>\ |
| 1715 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 1716 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 1717 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 1718 | arg9_type arg9) const;\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1719 | p0##_type p0;\ |
| 1720 | p1##_type p1;\ |
| 1721 | p2##_type p2;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1722 | };\ |
| 1723 | template <typename F> operator ::testing::Action<F>() const {\ |
| 1724 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\ |
| 1725 | }\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1726 | p0##_type p0;\ |
| 1727 | p1##_type p1;\ |
| 1728 | p2##_type p2;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1729 | };\ |
| 1730 | template <typename p0##_type, typename p1##_type, typename p2##_type>\ |
| 1731 | inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \ |
| 1732 | p1##_type p1, p2##_type p2) {\ |
| 1733 | return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\ |
| 1734 | }\ |
| 1735 | template <typename p0##_type, typename p1##_type, typename p2##_type>\ |
| 1736 | template <typename F>\ |
| 1737 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1738 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1739 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1740 | typename arg9_type>\ |
| 1741 | typename ::testing::internal::Function<F>::Result\ |
| 1742 | name##ActionP3<p0##_type, p1##_type, p2##_type>::\ |
| 1743 | gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \ |
| 1744 | arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \ |
| 1745 | arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \ |
| 1746 | arg8_type arg8, arg9_type arg9) const |
| 1747 | |
| 1748 | #define ACTION_P4(name, p0, p1, p2, p3)\ |
| 1749 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 1750 | typename p3##_type>\ |
| 1751 | class name##ActionP4 {\ |
| 1752 | public:\ |
| 1753 | name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 1754 | p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ |
| 1755 | p2(gmock_p2), p3(gmock_p3) {}\ |
| 1756 | template <typename F>\ |
| 1757 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 1758 | public:\ |
| 1759 | typedef F function_type;\ |
| 1760 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 1761 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 1762 | args_type;\ |
| 1763 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 1764 | p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 1765 | p3(gmock_p3) {}\ |
| 1766 | virtual return_type Perform(const args_type& args) {\ |
| 1767 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 1768 | Perform(this, args);\ |
| 1769 | }\ |
| 1770 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1771 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1772 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1773 | typename arg9_type>\ |
| 1774 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 1775 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 1776 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 1777 | arg9_type arg9) const;\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1778 | p0##_type p0;\ |
| 1779 | p1##_type p1;\ |
| 1780 | p2##_type p2;\ |
| 1781 | p3##_type p3;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1782 | };\ |
| 1783 | template <typename F> operator ::testing::Action<F>() const {\ |
| 1784 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\ |
| 1785 | }\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1786 | p0##_type p0;\ |
| 1787 | p1##_type p1;\ |
| 1788 | p2##_type p2;\ |
| 1789 | p3##_type p3;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1790 | };\ |
| 1791 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 1792 | typename p3##_type>\ |
| 1793 | inline name##ActionP4<p0##_type, p1##_type, p2##_type, \ |
| 1794 | p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ |
| 1795 | p3##_type p3) {\ |
| 1796 | return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \ |
| 1797 | p2, p3);\ |
| 1798 | }\ |
| 1799 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 1800 | typename p3##_type>\ |
| 1801 | template <typename F>\ |
| 1802 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1803 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1804 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1805 | typename arg9_type>\ |
| 1806 | typename ::testing::internal::Function<F>::Result\ |
| 1807 | name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>::\ |
| 1808 | gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \ |
| 1809 | arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \ |
| 1810 | arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \ |
| 1811 | arg8_type arg8, arg9_type arg9) const |
| 1812 | |
| 1813 | #define ACTION_P5(name, p0, p1, p2, p3, p4)\ |
| 1814 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 1815 | typename p3##_type, typename p4##_type>\ |
| 1816 | class name##ActionP5 {\ |
| 1817 | public:\ |
| 1818 | name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 1819 | p2##_type gmock_p2, p3##_type gmock_p3, \ |
| 1820 | p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 1821 | p3(gmock_p3), p4(gmock_p4) {}\ |
| 1822 | template <typename F>\ |
| 1823 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 1824 | public:\ |
| 1825 | typedef F function_type;\ |
| 1826 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 1827 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 1828 | args_type;\ |
| 1829 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 1830 | p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \ |
| 1831 | p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\ |
| 1832 | virtual return_type Perform(const args_type& args) {\ |
| 1833 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 1834 | Perform(this, args);\ |
| 1835 | }\ |
| 1836 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1837 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1838 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1839 | typename arg9_type>\ |
| 1840 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 1841 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 1842 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 1843 | arg9_type arg9) const;\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1844 | p0##_type p0;\ |
| 1845 | p1##_type p1;\ |
| 1846 | p2##_type p2;\ |
| 1847 | p3##_type p3;\ |
| 1848 | p4##_type p4;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1849 | };\ |
| 1850 | template <typename F> operator ::testing::Action<F>() const {\ |
| 1851 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\ |
| 1852 | }\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1853 | p0##_type p0;\ |
| 1854 | p1##_type p1;\ |
| 1855 | p2##_type p2;\ |
| 1856 | p3##_type p3;\ |
| 1857 | p4##_type p4;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1858 | };\ |
| 1859 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 1860 | typename p3##_type, typename p4##_type>\ |
| 1861 | inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 1862 | p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
| 1863 | p4##_type p4) {\ |
| 1864 | return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 1865 | p4##_type>(p0, p1, p2, p3, p4);\ |
| 1866 | }\ |
| 1867 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 1868 | typename p3##_type, typename p4##_type>\ |
| 1869 | template <typename F>\ |
| 1870 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1871 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1872 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1873 | typename arg9_type>\ |
| 1874 | typename ::testing::internal::Function<F>::Result\ |
| 1875 | name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type>::\ |
| 1876 | gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \ |
| 1877 | arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \ |
| 1878 | arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \ |
| 1879 | arg8_type arg8, arg9_type arg9) const |
| 1880 | |
| 1881 | #define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\ |
| 1882 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 1883 | typename p3##_type, typename p4##_type, typename p5##_type>\ |
| 1884 | class name##ActionP6 {\ |
| 1885 | public:\ |
| 1886 | name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 1887 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 1888 | p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 1889 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ |
| 1890 | template <typename F>\ |
| 1891 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 1892 | public:\ |
| 1893 | typedef F function_type;\ |
| 1894 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 1895 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 1896 | args_type;\ |
| 1897 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 1898 | p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 1899 | p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 1900 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ |
| 1901 | virtual return_type Perform(const args_type& args) {\ |
| 1902 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 1903 | Perform(this, args);\ |
| 1904 | }\ |
| 1905 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1906 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1907 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1908 | typename arg9_type>\ |
| 1909 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 1910 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 1911 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 1912 | arg9_type arg9) const;\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1913 | p0##_type p0;\ |
| 1914 | p1##_type p1;\ |
| 1915 | p2##_type p2;\ |
| 1916 | p3##_type p3;\ |
| 1917 | p4##_type p4;\ |
| 1918 | p5##_type p5;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1919 | };\ |
| 1920 | template <typename F> operator ::testing::Action<F>() const {\ |
| 1921 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\ |
| 1922 | }\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1923 | p0##_type p0;\ |
| 1924 | p1##_type p1;\ |
| 1925 | p2##_type p2;\ |
| 1926 | p3##_type p3;\ |
| 1927 | p4##_type p4;\ |
| 1928 | p5##_type p5;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1929 | };\ |
| 1930 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 1931 | typename p3##_type, typename p4##_type, typename p5##_type>\ |
| 1932 | inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 1933 | p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ |
| 1934 | p3##_type p3, p4##_type p4, p5##_type p5) {\ |
| 1935 | return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 1936 | p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\ |
| 1937 | }\ |
| 1938 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 1939 | typename p3##_type, typename p4##_type, typename p5##_type>\ |
| 1940 | template <typename F>\ |
| 1941 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1942 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1943 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1944 | typename arg9_type>\ |
| 1945 | typename ::testing::internal::Function<F>::Result\ |
| 1946 | name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 1947 | p5##_type>::\ |
| 1948 | gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \ |
| 1949 | arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \ |
| 1950 | arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \ |
| 1951 | arg8_type arg8, arg9_type arg9) const |
| 1952 | |
| 1953 | #define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\ |
| 1954 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 1955 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 1956 | typename p6##_type>\ |
| 1957 | class name##ActionP7 {\ |
| 1958 | public:\ |
| 1959 | name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 1960 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 1961 | p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \ |
| 1962 | p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ |
| 1963 | p6(gmock_p6) {}\ |
| 1964 | template <typename F>\ |
| 1965 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 1966 | public:\ |
| 1967 | typedef F function_type;\ |
| 1968 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 1969 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 1970 | args_type;\ |
| 1971 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 1972 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 1973 | p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 1974 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ |
| 1975 | virtual return_type Perform(const args_type& args) {\ |
| 1976 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 1977 | Perform(this, args);\ |
| 1978 | }\ |
| 1979 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 1980 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 1981 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 1982 | typename arg9_type>\ |
| 1983 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 1984 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 1985 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 1986 | arg9_type arg9) const;\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1987 | p0##_type p0;\ |
| 1988 | p1##_type p1;\ |
| 1989 | p2##_type p2;\ |
| 1990 | p3##_type p3;\ |
| 1991 | p4##_type p4;\ |
| 1992 | p5##_type p5;\ |
| 1993 | p6##_type p6;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 1994 | };\ |
| 1995 | template <typename F> operator ::testing::Action<F>() const {\ |
| 1996 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ |
| 1997 | p6));\ |
| 1998 | }\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 1999 | p0##_type p0;\ |
| 2000 | p1##_type p1;\ |
| 2001 | p2##_type p2;\ |
| 2002 | p3##_type p3;\ |
| 2003 | p4##_type p4;\ |
| 2004 | p5##_type p5;\ |
| 2005 | p6##_type p6;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 2006 | };\ |
| 2007 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 2008 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 2009 | typename p6##_type>\ |
| 2010 | inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 2011 | p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \ |
| 2012 | p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ |
| 2013 | p6##_type p6) {\ |
| 2014 | return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 2015 | p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\ |
| 2016 | }\ |
| 2017 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 2018 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 2019 | typename p6##_type>\ |
| 2020 | template <typename F>\ |
| 2021 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 2022 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 2023 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 2024 | typename arg9_type>\ |
| 2025 | typename ::testing::internal::Function<F>::Result\ |
| 2026 | name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 2027 | p5##_type, p6##_type>::\ |
| 2028 | gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \ |
| 2029 | arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \ |
| 2030 | arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \ |
| 2031 | arg8_type arg8, arg9_type arg9) const |
| 2032 | |
| 2033 | #define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\ |
| 2034 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 2035 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 2036 | typename p6##_type, typename p7##_type>\ |
| 2037 | class name##ActionP8 {\ |
| 2038 | public:\ |
| 2039 | name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 2040 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 2041 | p5##_type gmock_p5, p6##_type gmock_p6, \ |
| 2042 | p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 2043 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ |
| 2044 | p7(gmock_p7) {}\ |
| 2045 | template <typename F>\ |
| 2046 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 2047 | public:\ |
| 2048 | typedef F function_type;\ |
| 2049 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 2050 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 2051 | args_type;\ |
| 2052 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 2053 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 2054 | p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \ |
| 2055 | p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \ |
| 2056 | p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\ |
| 2057 | virtual return_type Perform(const args_type& args) {\ |
| 2058 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 2059 | Perform(this, args);\ |
| 2060 | }\ |
| 2061 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 2062 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 2063 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 2064 | typename arg9_type>\ |
| 2065 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 2066 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 2067 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 2068 | arg9_type arg9) const;\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 2069 | p0##_type p0;\ |
| 2070 | p1##_type p1;\ |
| 2071 | p2##_type p2;\ |
| 2072 | p3##_type p3;\ |
| 2073 | p4##_type p4;\ |
| 2074 | p5##_type p5;\ |
| 2075 | p6##_type p6;\ |
| 2076 | p7##_type p7;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 2077 | };\ |
| 2078 | template <typename F> operator ::testing::Action<F>() const {\ |
| 2079 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ |
| 2080 | p6, p7));\ |
| 2081 | }\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 2082 | p0##_type p0;\ |
| 2083 | p1##_type p1;\ |
| 2084 | p2##_type p2;\ |
| 2085 | p3##_type p3;\ |
| 2086 | p4##_type p4;\ |
| 2087 | p5##_type p5;\ |
| 2088 | p6##_type p6;\ |
| 2089 | p7##_type p7;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 2090 | };\ |
| 2091 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 2092 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 2093 | typename p6##_type, typename p7##_type>\ |
| 2094 | inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 2095 | p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \ |
| 2096 | p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ |
| 2097 | p6##_type p6, p7##_type p7) {\ |
| 2098 | return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 2099 | p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \ |
| 2100 | p6, p7);\ |
| 2101 | }\ |
| 2102 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 2103 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 2104 | typename p6##_type, typename p7##_type>\ |
| 2105 | template <typename F>\ |
| 2106 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 2107 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 2108 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 2109 | typename arg9_type>\ |
| 2110 | typename ::testing::internal::Function<F>::Result\ |
| 2111 | name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 2112 | p5##_type, p6##_type, p7##_type>::\ |
| 2113 | gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \ |
| 2114 | arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \ |
| 2115 | arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \ |
| 2116 | arg8_type arg8, arg9_type arg9) const |
| 2117 | |
| 2118 | #define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\ |
| 2119 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 2120 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 2121 | typename p6##_type, typename p7##_type, typename p8##_type>\ |
| 2122 | class name##ActionP9 {\ |
| 2123 | public:\ |
| 2124 | name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 2125 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 2126 | p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ |
| 2127 | p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 2128 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ |
| 2129 | p8(gmock_p8) {}\ |
| 2130 | template <typename F>\ |
| 2131 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 2132 | public:\ |
| 2133 | typedef F function_type;\ |
| 2134 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 2135 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 2136 | args_type;\ |
| 2137 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 2138 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 2139 | p6##_type gmock_p6, p7##_type gmock_p7, \ |
| 2140 | p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 2141 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ |
| 2142 | p7(gmock_p7), p8(gmock_p8) {}\ |
| 2143 | virtual return_type Perform(const args_type& args) {\ |
| 2144 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 2145 | Perform(this, args);\ |
| 2146 | }\ |
| 2147 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 2148 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 2149 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 2150 | typename arg9_type>\ |
| 2151 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 2152 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 2153 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 2154 | arg9_type arg9) const;\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 2155 | p0##_type p0;\ |
| 2156 | p1##_type p1;\ |
| 2157 | p2##_type p2;\ |
| 2158 | p3##_type p3;\ |
| 2159 | p4##_type p4;\ |
| 2160 | p5##_type p5;\ |
| 2161 | p6##_type p6;\ |
| 2162 | p7##_type p7;\ |
| 2163 | p8##_type p8;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 2164 | };\ |
| 2165 | template <typename F> operator ::testing::Action<F>() const {\ |
| 2166 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ |
| 2167 | p6, p7, p8));\ |
| 2168 | }\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 2169 | p0##_type p0;\ |
| 2170 | p1##_type p1;\ |
| 2171 | p2##_type p2;\ |
| 2172 | p3##_type p3;\ |
| 2173 | p4##_type p4;\ |
| 2174 | p5##_type p5;\ |
| 2175 | p6##_type p6;\ |
| 2176 | p7##_type p7;\ |
| 2177 | p8##_type p8;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 2178 | };\ |
| 2179 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 2180 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 2181 | typename p6##_type, typename p7##_type, typename p8##_type>\ |
| 2182 | inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 2183 | p4##_type, p5##_type, p6##_type, p7##_type, \ |
| 2184 | p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
| 2185 | p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ |
| 2186 | p8##_type p8) {\ |
| 2187 | return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 2188 | p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \ |
| 2189 | p3, p4, p5, p6, p7, p8);\ |
| 2190 | }\ |
| 2191 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 2192 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 2193 | typename p6##_type, typename p7##_type, typename p8##_type>\ |
| 2194 | template <typename F>\ |
| 2195 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 2196 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 2197 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 2198 | typename arg9_type>\ |
| 2199 | typename ::testing::internal::Function<F>::Result\ |
| 2200 | name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 2201 | p5##_type, p6##_type, p7##_type, p8##_type>::\ |
| 2202 | gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \ |
| 2203 | arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \ |
| 2204 | arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \ |
| 2205 | arg8_type arg8, arg9_type arg9) const |
| 2206 | |
| 2207 | #define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\ |
| 2208 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 2209 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 2210 | typename p6##_type, typename p7##_type, typename p8##_type, \ |
| 2211 | typename p9##_type>\ |
| 2212 | class name##ActionP10 {\ |
| 2213 | public:\ |
| 2214 | name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \ |
| 2215 | p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ |
| 2216 | p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ |
| 2217 | p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \ |
| 2218 | p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ |
| 2219 | p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ |
| 2220 | template <typename F>\ |
| 2221 | class gmock_Impl : public ::testing::ActionInterface<F> {\ |
| 2222 | public:\ |
| 2223 | typedef F function_type;\ |
| 2224 | typedef typename ::testing::internal::Function<F>::Result return_type;\ |
| 2225 | typedef typename ::testing::internal::Function<F>::ArgumentTuple\ |
| 2226 | args_type;\ |
| 2227 | gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 2228 | p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 2229 | p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ |
| 2230 | p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ |
| 2231 | p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ |
| 2232 | p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ |
| 2233 | virtual return_type Perform(const args_type& args) {\ |
| 2234 | return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ |
| 2235 | Perform(this, args);\ |
| 2236 | }\ |
| 2237 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 2238 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 2239 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 2240 | typename arg9_type>\ |
| 2241 | return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ |
| 2242 | arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ |
| 2243 | arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ |
| 2244 | arg9_type arg9) const;\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 2245 | p0##_type p0;\ |
| 2246 | p1##_type p1;\ |
| 2247 | p2##_type p2;\ |
| 2248 | p3##_type p3;\ |
| 2249 | p4##_type p4;\ |
| 2250 | p5##_type p5;\ |
| 2251 | p6##_type p6;\ |
| 2252 | p7##_type p7;\ |
| 2253 | p8##_type p8;\ |
| 2254 | p9##_type p9;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 2255 | };\ |
| 2256 | template <typename F> operator ::testing::Action<F>() const {\ |
| 2257 | return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ |
| 2258 | p6, p7, p8, p9));\ |
| 2259 | }\ |
zhanyong.wan | c069d7f | 2009-02-02 20:51:53 +0000 | [diff] [blame] | 2260 | p0##_type p0;\ |
| 2261 | p1##_type p1;\ |
| 2262 | p2##_type p2;\ |
| 2263 | p3##_type p3;\ |
| 2264 | p4##_type p4;\ |
| 2265 | p5##_type p5;\ |
| 2266 | p6##_type p6;\ |
| 2267 | p7##_type p7;\ |
| 2268 | p8##_type p8;\ |
| 2269 | p9##_type p9;\ |
shiqian | 326aa56 | 2009-01-09 21:43:57 +0000 | [diff] [blame] | 2270 | };\ |
| 2271 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 2272 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 2273 | typename p6##_type, typename p7##_type, typename p8##_type, \ |
| 2274 | typename p9##_type>\ |
| 2275 | inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 2276 | p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ |
| 2277 | p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
| 2278 | p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ |
| 2279 | p9##_type p9) {\ |
| 2280 | return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 2281 | p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \ |
| 2282 | p1, p2, p3, p4, p5, p6, p7, p8, p9);\ |
| 2283 | }\ |
| 2284 | template <typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 2285 | typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 2286 | typename p6##_type, typename p7##_type, typename p8##_type, \ |
| 2287 | typename p9##_type>\ |
| 2288 | template <typename F>\ |
| 2289 | template <typename arg0_type, typename arg1_type, typename arg2_type, \ |
| 2290 | typename arg3_type, typename arg4_type, typename arg5_type, \ |
| 2291 | typename arg6_type, typename arg7_type, typename arg8_type, \ |
| 2292 | typename arg9_type>\ |
| 2293 | typename ::testing::internal::Function<F>::Result\ |
| 2294 | name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
| 2295 | p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>::\ |
| 2296 | gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \ |
| 2297 | arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \ |
| 2298 | arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \ |
| 2299 | arg8_type arg8, arg9_type arg9) const |
| 2300 | |
zhanyong.wan | e1cdce5 | 2009-02-06 01:09:43 +0000 | [diff] [blame^] | 2301 | namespace testing { |
| 2302 | |
| 2303 | // Action Throw(exception) can be used in a mock function of any type |
| 2304 | // to throw the given exception. Any copyable value can be thrown. |
| 2305 | #if GTEST_HAS_EXCEPTIONS |
| 2306 | ACTION_P(Throw, exception) { throw exception; } |
| 2307 | #endif // GTEST_HAS_EXCEPTIONS |
| 2308 | |
| 2309 | } // namespace testing |
| 2310 | |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 2311 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ |