| 1 | // Copyright 2007, Google Inc.cxx . . $ `<file>/googlemock/include/gmock/gmock-actions.h`/ |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | // Google Mock - a framework for writing C++ mock classes. |
| 31 | // |
| 32 | // The ACTION* family of macros can be used in a namespace scope to |
| 33 | // define custom actions easily. The syntax: |
| 34 | // |
| 35 | // ACTION(name) { statements; } |
| 36 | // |
| 37 | // will define an action with the given name that executes the |
| 38 | // statements. The value returned by the statements will be used as |
| 39 | // the return value of the action. Inside the statements, you can |
| 40 | // refer to the K-th (0-based) argument of the mock function by |
| 41 | // 'argK', and refer to its type by 'argK_type'. For example: |
| 42 | // |
| 43 | // ACTION(IncrementArg1) { |
| 44 | // arg1_type temp = arg1; |
| 45 | // return ++(*temp); |
| 46 | // } |
| 47 | // |
| 48 | // allows you to write |
| 49 | // |
| 50 | // ...WillOnce(IncrementArg1()); |
| 51 | // |
| 52 | // You can also refer to the entire argument tuple and its type by |
| 53 | // 'args' and 'args_type', and refer to the mock function type and its |
| 54 | // return type by 'function_type' and 'return_type'. |
| 55 | // |
| 56 | // Note that you don't need to specify the types of the mock function |
| 57 | // arguments. However rest assured that your code is still type-safe: |
| 58 | // you'll get a compiler error if *arg1 doesn't support the ++ |
| 59 | // operator, or if the type of ++(*arg1) isn't compatible with the |
| 60 | // mock function's return type, for example. |
| 61 | // |
| 62 | // Sometimes you'll want to parameterize the action. For that you can use |
| 63 | // another macro: |
| 64 | // |
| 65 | // ACTION_P(name, param_name) { statements; } |
| 66 | // |
| 67 | // For example: |
| 68 | // |
| 69 | // ACTION_P(Add, n) { return arg0 + n; } |
| 70 | // |
| 71 | // will allow you to write: |
| 72 | // |
| 73 | // ...WillOnce(Add(5)); |
| 74 | // |
| 75 | // Note that you don't need to provide the type of the parameter |
| 76 | // either. If you need to reference the type of a parameter named |
| 77 | // 'foo', you can write 'foo_type'. For example, in the body of |
| 78 | // ACTION_P(Add, n) above, you can write 'n_type' to refer to the type |
| 79 | // of 'n'. |
| 80 | // |
| 81 | // We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support |
| 82 | // multi-parameter actions. |
| 83 | // |
| 84 | // For the purpose of typing, you can view |
| 85 | // |
| 86 | // ACTION_Pk(Foo, p1, ..., pk) { ... } |
| 87 | // |
| 88 | // as shorthand for |
| 89 | // |
| 90 | // template <typename p1_type, ..., typename pk_type> |
| 91 | // FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... } |
| 92 | // |
| 93 | // In particular, you can provide the template type arguments |
| 94 | // explicitly when invoking Foo(), as in Foo<long, bool>(5, false); |
| 95 | // although usually you can rely on the compiler to infer the types |
| 96 | // for you automatically. You can assign the result of expression |
| 97 | // Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ..., |
| 98 | // pk_type>. This can be useful when composing actions. |
| 99 | // |
| 100 | // You can also overload actions with different numbers of parameters: |
| 101 | // |
| 102 | // ACTION_P(Plus, a) { ... } |
| 103 | // ACTION_P2(Plus, a, b) { ... } |
| 104 | // |
| 105 | // While it's tempting to always use the ACTION* macros when defining |
| 106 | // a new action, you should also consider implementing ActionInterface |
| 107 | // or using MakePolymorphicAction() instead, especially if you need to |
| 108 | // use the action a lot. While these approaches require more work, |
| 109 | // they give you more control on the types of the mock function |
| 110 | // arguments and the action parameters, which in general leads to |
| 111 | // better compiler error messages that pay off in the long run. They |
| 112 | // also allow overloading actions based on parameter types (as opposed |
| 113 | // to just based on the number of parameters). |
| 114 | // |
| 115 | // CAVEAT: |
| 116 | // |
| 117 | // ACTION*() can only be used in a namespace scope as templates cannot be |
| 118 | // declared inside of a local class. |
| 119 | // Users can, however, define any local functors (e.g. a lambda) that |
| 120 | // can be used as actions. |
| 121 | // |
| 122 | // MORE INFORMATION: |
| 123 | // |
| 124 | // To learn more about using these macros, please search for 'ACTION' on |
| 125 | // https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md |
| 126 | |
| 127 | // IWYU pragma: private, include "gmock/gmock.h" |
| 128 | // IWYU pragma: friend gmock/.* |
| 129 | |
| 130 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ |
| 131 | #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_cxx . . $ `googlemock/include/gmock/gmock-actions.h:131:9`! |
| 132 | |
| 133 | #ifndef _WIN32_WCE |
| 134 | #include <errno.h> |
| 135 | #endif |
| 136 | |
| 137 | #include <algorithm> |
| 138 | #include <exception> |
| 139 | #include <functional> |
| 140 | #include <memory> |
| 141 | #include <string> |
| 142 | #include <tuple> |
| 143 | #include <type_traits> |
| 144 | #include <utility> |
| 145 | |
| 146 | #include "gmock/internal/gmock-internal-utils.h"cxx . . $ `<file>/googlemock/include/gmock/internal/gmock-internal-utils.h`/ |
| 147 | #include "gmock/internal/gmock-port.h"cxx . . $ `<file>/googlemock/include/gmock/internal/gmock-port.h`/ |
| 148 | #include "gmock/internal/gmock-pp.h"cxx . . $ `<file>/googlemock/include/gmock/internal/gmock-pp.h`/ |
| 149 | |
| 150 | GTEST_DISABLE_MSC_WARNINGS_PUSH_cxx . . $ `googletest/include/gtest/internal/gtest-port.h:375:9`!(4100) |
| 151 | |
| 152 | namespace testingcxx . . $ testing/ { |
| 153 | |
| 154 | // To implement an action Foo, define: |
| 155 | // 1. a class FooAction that implements the ActionInterface interface, and |
| 156 | // 2. a factory function that creates an Action object from a |
| 157 | // const FooAction*. |
| 158 | // |
| 159 | // The two-level delegation design follows that of Matcher, providing |
| 160 | // consistency for extension developers. It also eases ownership |
| 161 | // management as Action objects can now be copied like plain values. |
| 162 | |
| 163 | namespace internalcxx . . $ testing/internal/ { |
| 164 | |
| 165 | // BuiltInDefaultValueGetter<T, true>::Get() returns a |
| 166 | // default-constructed T value. BuiltInDefaultValueGetter<T, |
| 167 | // false>::Get() crashes with an error. |
| 168 | // |
| 169 | // This primary template is used when kDefaultConstructible is true. |
| 170 | template <typename T, bool kDefaultConstructible> |
| 171 | struct BuiltInDefaultValueGettercxx . . $ testing/internal/BuiltInDefaultValueGetter# { |
| 172 | static T Getcxx . . $ testing/internal/BuiltInDefaultValueGetter#Get(5f357b03ed472e5e).() { return T(); } |
| 173 | }; |
| 174 | template <typename T> |
| 175 | struct BuiltInDefaultValueGettercxx . . $ testing/internal/BuiltInDefaultValueGetter#<T, false> { |
| 176 | static T Getcxx . . $ testing/internal/BuiltInDefaultValueGetter#Get(5f357b03ed472e5e).() { |
| 177 | Assertcxx . . $ testing/internal/Assert(f72e0045939ddf2e).(false, __FILE__, __LINE__, |
| 178 | "Default action undefined for the function return type."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 179 | #if defined(__GNUC__cxx . . $ `<built-in>:8:9`!) || defined(__clang__cxx . . $ `<built-in>:3:9`!) |
| 180 | __builtin_unreachable(); |
| 181 | #elif defined(_MSC_VER) |
| 182 | __assume(0); |
| 183 | #else |
| 184 | return Invalid<T>(); |
| 185 | // The above statement will never be reached, but is required in |
| 186 | // order for this function to compile. |
| 187 | #endif |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | // BuiltInDefaultValue<T>::Get() returns the "built-in" default value |
| 192 | // for type T, which is NULL when T is a raw pointer type, 0 when T is |
| 193 | // a numeric type, false when T is bool, or "" when T is string or |
| 194 | // std::string. In addition, in C++11 and above, it turns a |
| 195 | // default-constructed T value if T is default constructible. For any |
| 196 | // other type T, the built-in default T value is undefined, and the |
| 197 | // function will abort the process. |
| 198 | template <typename T> |
| 199 | class BuiltInDefaultValuecxx . . $ testing/internal/BuiltInDefaultValue# { |
| 200 | public: |
| 201 | // This function returns true if and only if type T has a built-in default |
| 202 | // value. |
| 203 | static bool Existscxx . . $ testing/internal/BuiltInDefaultValue#Exists(c9857a73d68e59ba).() { return ::stdcxx . . $ std/::is_default_constructible<T>::value; } |
| 204 | |
| 205 | static T Getcxx . . $ testing/internal/BuiltInDefaultValue#Get(5f357b03ed472e5e).() { |
| 206 | return BuiltInDefaultValueGettercxx . . $ testing/internal/BuiltInDefaultValueGetter#< |
| 207 | T, ::std::is_default_constructible<T>::value>::Get(); |
| 208 | } |
| 209 | }; |
| 210 | |
| 211 | // This partial specialization says that we use the same built-in |
| 212 | // default value for T and const T. |
| 213 | template <typename T> |
| 214 | class BuiltInDefaultValuecxx . . $ testing/internal/BuiltInDefaultValue#<const T> { |
| 215 | public: |
| 216 | static bool Existscxx . . $ testing/internal/BuiltInDefaultValue#Exists(c9857a73d68e59ba).() { return BuiltInDefaultValuecxx . . $ testing/internal/BuiltInDefaultValue#<T>::Exists(); } |
| 217 | static T Getcxx . . $ testing/internal/BuiltInDefaultValue#Get(5f357b03ed472e5e).() { return BuiltInDefaultValuecxx . . $ testing/internal/BuiltInDefaultValue#<T>::Get(); } |
| 218 | }; |
| 219 | |
| 220 | // This partial specialization defines the default values for pointer |
| 221 | // types. |
| 222 | template <typename T> |
| 223 | class BuiltInDefaultValuecxx . . $ testing/internal/BuiltInDefaultValue#<T*> { |
| 224 | public: |
| 225 | static bool Existscxx . . $ testing/internal/BuiltInDefaultValue#Exists(c9857a73d68e59ba).() { return true; } |
| 226 | static T* Getcxx . . $ testing/internal/BuiltInDefaultValue#Get(155dc7f103cdb9db).() { return nullptr; } |
| 227 | }; |
| 228 | |
| 229 | // The following specializations define the default values for |
| 230 | // specific types we care about. |
| 231 | #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ `googlemock/include/gmock/gmock-actions.h:231:9`!(type, value) \ |
| 232 | template <> \ |
| 233 | class BuiltInDefaultValue<type> { \ |
| 234 | public: \ |
| 235 | static bool Exists() { return true; } \ |
| 236 | static type Get() { return value; } \ |
| 237 | } |
| 238 | |
| 239 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#(void, ); // NOLINT |
| 240 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ `googlemock/include/gmock/gmock-actions.h:231:9`!(::std::string, ""); |
| 241 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ `googlemock/include/gmock/gmock-actions.h:231:9`!(bool, false); |
| 242 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ `googlemock/include/gmock/gmock-actions.h:231:9`!(unsigned char, '\0'); |
| 243 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#Get(f1c002f0206d8350).(signed char, '\0'); |
| 244 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#(char, '\0'); |
| 245 | |
| 246 | // There's no need for a default action for signed wchar_t, as that |
| 247 | // type is the same as wchar_t for gcc, and invalid for MSVC. |
| 248 | // |
| 249 | // There's also no need for a default action for unsigned wchar_t, as |
| 250 | // that type is the same as unsigned int for gcc, and invalid for |
| 251 | // MSVC. |
| 252 | #if GMOCK_WCHAR_T_IS_NATIVE_cxx . . $ `googlemock/include/gmock/internal/gmock-internal-utils.h:120:9`! |
| 253 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#(wchar_t, 0U); // NOLINT |
| 254 | #endif |
| 255 | |
| 256 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#Get(32a7769d58713265).(unsigned short, 0U); // NOLINT |
| 257 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#Get(4c3706f7850cf040).(signed short, 0); // NOLINT |
| 258 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#Get(db52760e79bf9054).(unsigned int, 0U); |
| 259 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ `googlemock/include/gmock/gmock-actions.h:231:9`!(signed int, 0); |
| 260 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#(unsigned long, 0UL); // NOLINT |
| 261 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#Exists(c9857a73d68e59ba).(signed long, 0L); // NOLINT |
| 262 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#(unsigned long long, 0); // NOLINT |
| 263 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ `googlemock/include/gmock/gmock-actions.h:231:9`!(signed long long, 0); // NOLINT |
| 264 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#(float, 0); |
| 265 | GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ testing/internal/BuiltInDefaultValue#Get(31fa7155c10fdd13).(double, 0); |
| 266 | |
| 267 | #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_cxx . . $ `googlemock/include/gmock/gmock-actions.h:231:9`! |
| 268 | |
| 269 | // Partial implementations of metaprogramming types from the standard library |
| 270 | // not available in C++11. |
| 271 | |
| 272 | template <typename P> |
| 273 | struct negationcxx . . $ testing/internal/negation# |
| 274 | // NOLINTNEXTLINE |
| 275 | : stdcxx . . $ std/::integral_constant<bool, bool(!P::value)> {}; |
| 276 | |
| 277 | // Base case: with zero predicates the answer is always true. |
| 278 | template <typename...> |
| 279 | struct conjunctioncxx . . $ testing/internal/conjunction# : stdcxx . . $ std/::true_type {}; |
| 280 | |
| 281 | // With a single predicate, the answer is that predicate. |
| 282 | template <typename P1> |
| 283 | struct conjunctioncxx . . $ testing/internal/conjunction#<P1> : P1 {}; |
| 284 | |
| 285 | // With multiple predicates the answer is the first predicate if that is false, |
| 286 | // and we recurse otherwise. |
| 287 | template <typename P1, typename... Ps> |
| 288 | struct conjunctioncxx . . $ testing/internal/conjunction#<P1, Ps...> |
| 289 | : stdcxx . . $ std/::conditional<bool(P1::value), conjunction<Ps...>, P1>::type {}; |
| 290 | |
| 291 | template <typename...> |
| 292 | struct disjunctioncxx . . $ testing/internal/disjunction# : stdcxx . . $ std/::false_type {}; |
| 293 | |
| 294 | template <typename P1> |
| 295 | struct disjunctioncxx . . $ testing/internal/disjunction#<P1> : P1 {}; |
| 296 | |
| 297 | template <typename P1, typename... Ps> |
| 298 | struct disjunctioncxx . . $ testing/internal/disjunction#<P1, Ps...> |
| 299 | // NOLINTNEXTLINE |
| 300 | : stdcxx . . $ std/::conditional<!bool(P1::value), disjunction<Ps...>, P1>::type {}; |
| 301 | |
| 302 | template <typename...> |
| 303 | using void_tcxx . . $ testing/internal/void_t# = void; |
| 304 | |
| 305 | // Detects whether an expression of type `From` can be implicitly converted to |
| 306 | // `To` according to [conv]. In C++17, [conv]/3 defines this as follows: |
| 307 | // |
| 308 | // An expression e can be implicitly converted to a type T if and only if |
| 309 | // the declaration T t=e; is well-formed, for some invented temporary |
| 310 | // variable t ([dcl.init]). |
| 311 | // |
| 312 | // [conv]/2 implies we can use function argument passing to detect whether this |
| 313 | // initialization is valid. |
| 314 | // |
| 315 | // Note that this is distinct from is_convertible, which requires this be valid: |
| 316 | // |
| 317 | // To test() { |
| 318 | // return declval<From>(); |
| 319 | // } |
| 320 | // |
| 321 | // In particular, is_convertible doesn't give the correct answer when `To` and |
| 322 | // `From` are the same non-moveable type since `declval<From>` will be an rvalue |
| 323 | // reference, defeating the guaranteed copy elision that would otherwise make |
| 324 | // this function work. |
| 325 | // |
| 326 | // REQUIRES: `From` is not cv void. |
| 327 | template <typename From, typename To> |
| 328 | struct is_implicitly_convertiblecxx . . $ testing/internal/is_implicitly_convertible# { |
| 329 | private: |
| 330 | // A function that accepts a parameter of type T. This can be called with type |
| 331 | // U successfully only if U is implicitly convertible to T. |
| 332 | template <typename T> |
| 333 | static void Acceptcxx . . $ testing/internal/is_implicitly_convertible#Accept(b07662a27bd562f9).(T); |
| 334 | |
| 335 | // A function that creates a value of type T. |
| 336 | template <typename T> |
| 337 | static T Makecxx . . $ testing/internal/is_implicitly_convertible#Make(8a625274aa32efa9).(); |
| 338 | |
| 339 | // An overload be selected when implicit conversion from T to To is possible. |
| 340 | template <typename T, typename = decltype(Acceptcxx . . $ testing/internal/is_implicitly_convertible#Accept(b07662a27bd562f9).<To>(Makecxx . . $ testing/internal/is_implicitly_convertible#Make(8a625274aa32efa9).<T>()))> |
| 341 | static stdcxx . . $ std/::true_type TestImplicitConversioncxx . . $ testing/internal/is_implicitly_convertible#TestImplicitConversion(a9db045d7987ac97).(int); |
| 342 | |
| 343 | // A fallback overload selected in all other cases. |
| 344 | template <typename T> |
| 345 | static stdcxx . . $ std/::false_type TestImplicitConversioncxx . . $ testing/internal/is_implicitly_convertible#TestImplicitConversion(8dc8d43ad6747387).(...); |
| 346 | |
| 347 | public: |
| 348 | using typecxx . . $ testing/internal/is_implicitly_convertible#type# = decltype(TestImplicitConversioncxx . . $ testing/internal/is_implicitly_convertible#TestImplicitConversion(8dc8d43ad6747387).<From>(0)); |
| 349 | static constexpr bool valuecxx . . $ testing/internal/is_implicitly_convertible#value. = typecxx . . $ testing/internal/is_implicitly_convertible#type#::value; |
| 350 | }; |
| 351 | |
| 352 | // Like std::invoke_result_t from C++17, but works only for objects with call |
| 353 | // operators (not e.g. member function pointers, which we don't need specific |
| 354 | // support for in OnceAction because std::function deals with them). |
| 355 | template <typename F, typename... Args> |
| 356 | using call_result_tcxx . . $ testing/internal/call_result_t# = decltype(stdcxx . . $ std/::declval<F>()(stdcxx . . $ std/::declval<Args>()...)); |
| 357 | |
| 358 | template <typename Void, typename R, typename F, typename... Args> |
| 359 | struct is_callable_r_implcxx . . $ testing/internal/is_callable_r_impl# : stdcxx . . $ std/::false_type {}; |
| 360 | |
| 361 | // Specialize the struct for those template arguments where call_result_t is |
| 362 | // well-formed. When it's not, the generic template above is chosen, resulting |
| 363 | // in std::false_type. |
| 364 | template <typename R, typename F, typename... Args> |
| 365 | struct is_callable_r_implcxx . . $ testing/internal/is_callable_r_impl#<void_tcxx . . $ testing/internal/void_t#<call_result_tcxx . . $ testing/internal/call_result_t#<F, Args...>>, R, F, Args...> |
| 366 | : stdcxx . . $ std/::conditional< |
| 367 | std::is_void<R>::value, // |
| 368 | std::true_type, // |
| 369 | is_implicitly_convertible<call_result_t<F, Args...>, R>>::type {}; |
| 370 | |
| 371 | // Like std::is_invocable_r from C++17, but works only for objects with call |
| 372 | // operators. See the note on call_result_t. |
| 373 | template <typename R, typename F, typename... Args> |
| 374 | using is_callable_rcxx . . $ testing/internal/is_callable_r# = is_callable_r_implcxx . . $ testing/internal/is_callable_r_impl#<void, R, F, Args...>; |
| 375 | |
| 376 | // Like std::as_const from C++17. |
| 377 | template <typename T> |
| 378 | typename stdcxx . . $ std/::add_const<T>::type& as_constcxx . . $ testing/internal/as_const(a9df1f66f9aef2b2).(T& t) { |
| 379 | return t; |
| 380 | } |
| 381 | |
| 382 | } // namespace internal |
| 383 | |
| 384 | // Specialized for function types below. |
| 385 | template <typename F> |
| 386 | class OnceActioncxx . . $ testing/OnceAction#; |
| 387 | |
| 388 | // An action that can only be used once. |
| 389 | // |
| 390 | // This is accepted by WillOnce, which doesn't require the underlying action to |
| 391 | // be copy-constructible (only move-constructible), and promises to invoke it as |
| 392 | // an rvalue reference. This allows the action to work with move-only types like |
| 393 | // std::move_only_function in a type-safe manner. |
| 394 | // |
| 395 | // For example: |
| 396 | // |
| 397 | // // Assume we have some API that needs to accept a unique pointer to some |
| 398 | // // non-copyable object Foo. |
| 399 | // void AcceptUniquePointer(std::unique_ptr<Foo> foo); |
| 400 | // |
| 401 | // // We can define an action that provides a Foo to that API. Because It |
| 402 | // // has to give away its unique pointer, it must not be called more than |
| 403 | // // once, so its call operator is &&-qualified. |
| 404 | // struct ProvideFoo { |
| 405 | // std::unique_ptr<Foo> foo; |
| 406 | // |
| 407 | // void operator()() && { |
| 408 | // AcceptUniquePointer(std::move(Foo)); |
| 409 | // } |
| 410 | // }; |
| 411 | // |
| 412 | // // This action can be used with WillOnce. |
| 413 | // EXPECT_CALL(mock, Call) |
| 414 | // .WillOnce(ProvideFoo{std::make_unique<Foo>(...)}); |
| 415 | // |
| 416 | // // But a call to WillRepeatedly will fail to compile. This is correct, |
| 417 | // // since the action cannot correctly be used repeatedly. |
| 418 | // EXPECT_CALL(mock, Call) |
| 419 | // .WillRepeatedly(ProvideFoo{std::make_unique<Foo>(...)}); |
| 420 | // |
| 421 | // A less-contrived example would be an action that returns an arbitrary type, |
| 422 | // whose &&-qualified call operator is capable of dealing with move-only types. |
| 423 | template <typename Result, typename... Args> |
| 424 | class OnceActioncxx . . $ testing/OnceAction#<Result(Args...)> final { |
| 425 | private: |
| 426 | // True iff we can use the given callable type (or lvalue reference) directly |
| 427 | // via StdFunctionAdaptor. |
| 428 | template <typename Callable> |
| 429 | using IsDirectlyCompatiblecxx . . $ testing/OnceAction#IsDirectlyCompatible# = internalcxx . . $ testing/internal/::conjunctioncxx . . $ testing/internal/conjunction#< |
| 430 | // It must be possible to capture the callable in StdFunctionAdaptor. |
| 431 | stdcxx . . $ std/::is_constructible<typename stdcxx . . $ std/::decay<Callable>::type, Callable>, |
| 432 | // The callable must be compatible with our signature. |
| 433 | internalcxx . . $ testing/internal/::is_callable_rcxx . . $ testing/internal/is_callable_r#<Result, typename stdcxx . . $ std/::decay<Callable>::type, |
| 434 | Args...>>; |
| 435 | |
| 436 | // True iff we can use the given callable type via StdFunctionAdaptor once we |
| 437 | // ignore incoming arguments. |
| 438 | template <typename Callable> |
| 439 | using IsCompatibleAfterIgnoringArgumentscxx . . $ testing/OnceAction#IsCompatibleAfterIgnoringArguments# = internalcxx . . $ testing/internal/::conjunctioncxx . . $ testing/internal/conjunction#< |
| 440 | // It must be possible to capture the callable in a lambda. |
| 441 | stdcxx . . $ std/::is_constructible<typename stdcxx . . $ std/::decay<Callable>::type, Callable>, |
| 442 | // The callable must be invocable with zero arguments, returning something |
| 443 | // convertible to Result. |
| 444 | internalcxx . . $ testing/internal/::is_callable_rcxx . . $ testing/internal/is_callable_r#<Result, typename stdcxx . . $ std/::decay<Callable>::type>>; |
| 445 | |
| 446 | public: |
| 447 | // Construct from a callable that is directly compatible with our mocked |
| 448 | // signature: it accepts our function type's arguments and returns something |
| 449 | // convertible to our result type. |
| 450 | template <typename Callable, |
| 451 | typename stdcxx . . $ std/::enable_if< |
| 452 | internal::conjunction< |
| 453 | // Teach clang on macOS that we're not talking about a |
| 454 | // copy/move constructor here. Otherwise it gets confused |
| 455 | // when checking the is_constructible requirement of our |
| 456 | // traits above. |
| 457 | internal::negation<std::is_same< |
| 458 | OnceAction, typename std::decay<Callable>::type>>, |
| 459 | IsDirectlyCompatible<Callable>> // |
| 460 | ::value, |
| 461 | int>::type = 0> |
| 462 | OnceActioncxx . . $ testing/OnceAction#`OnceAction<Result (Args...)>`(4f6c0277e8680150).(Callable&& callable) // NOLINT |
| 463 | : function_cxx . . $ testing/OnceAction#function_.(StdFunctionAdaptorcxx . . $ testing/OnceAction#StdFunctionAdaptor#<typename stdcxx . . $ std/::decay<Callable>::type>( |
| 464 | {}, stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Callable>(callable))) {} |
| 465 | |
| 466 | // As above, but for a callable that ignores the mocked function's arguments. |
| 467 | template <typename Callable, |
| 468 | typename stdcxx . . $ std/::enable_if< |
| 469 | internal::conjunction< |
| 470 | // Teach clang on macOS that we're not talking about a |
| 471 | // copy/move constructor here. Otherwise it gets confused |
| 472 | // when checking the is_constructible requirement of our |
| 473 | // traits above. |
| 474 | internal::negation<std::is_same< |
| 475 | OnceAction, typename std::decay<Callable>::type>>, |
| 476 | // Exclude callables for which the overload above works. |
| 477 | // We'd rather provide the arguments if possible. |
| 478 | internal::negation<IsDirectlyCompatible<Callable>>, |
| 479 | IsCompatibleAfterIgnoringArguments<Callable>>::value, |
| 480 | int>::type = 0> |
| 481 | OnceActioncxx . . $ testing/OnceAction#`OnceAction<Result (Args...)>`(4f6c0277e8680150).(Callable&& callable) // NOLINT |
| 482 | // Call the constructor above with a callable |
| 483 | // that ignores the input arguments. |
| 484 | : OnceAction(IgnoreIncomingArgumentscxx . . $ testing/OnceAction#IgnoreIncomingArguments#<typename stdcxx . . $ std/::decay<Callable>::type>{ |
| 485 | stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Callable>(callable)}) {} |
| 486 | |
| 487 | // We are naturally copyable because we store only an std::function, but |
| 488 | // semantically we should not be copyable. |
| 489 | OnceActioncxx . . $ testing/OnceAction#`OnceAction<Result (Args...)>`(9d2b74cfe75751a9).(const OnceAction&) = delete; |
| 490 | OnceAction& operatorcxx . . $ testing/OnceAction#`operator=`(4302db10bd9f5eb0).=(const OnceAction&) = delete; |
| 491 | OnceActioncxx . . $ testing/OnceAction#`OnceAction<Result (Args...)>`(8e46f2b5c93943f).(OnceAction&&) = default; |
| 492 | |
| 493 | // Invoke the underlying action callable with which we were constructed, |
| 494 | // handing it the supplied arguments. |
| 495 | Result Callcxx . . $ testing/OnceAction#Call(f01b9517887e9157).(Args... args) && { |
| 496 | return function_cxx . . $ testing/OnceAction#function_.(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Args>(args)...); |
| 497 | } |
| 498 | |
| 499 | private: |
| 500 | // An adaptor that wraps a callable that is compatible with our signature and |
| 501 | // being invoked as an rvalue reference so that it can be used as an |
| 502 | // StdFunctionAdaptor. This throws away type safety, but that's fine because |
| 503 | // this is only used by WillOnce, which we know calls at most once. |
| 504 | // |
| 505 | // Once we have something like std::move_only_function from C++23, we can do |
| 506 | // away with this. |
| 507 | template <typename Callable> |
| 508 | class StdFunctionAdaptorcxx . . $ testing/OnceAction#StdFunctionAdaptor# final { |
| 509 | public: |
| 510 | // A tag indicating that the (otherwise universal) constructor is accepting |
| 511 | // the callable itself, instead of e.g. stealing calls for the move |
| 512 | // constructor. |
| 513 | struct CallableTagcxx . . $ testing/OnceAction#StdFunctionAdaptor#CallableTag# final {}; |
| 514 | |
| 515 | template <typename F> |
| 516 | explicit StdFunctionAdaptorcxx . . $ testing/OnceAction#StdFunctionAdaptor#`StdFunctionAdaptor<Callable>`(215e8955baf14bd5).(CallableTagcxx . . $ testing/OnceAction#StdFunctionAdaptor#CallableTag#, F&& callable) |
| 517 | : callable_cxx . . $ testing/OnceAction#StdFunctionAdaptor#callable_.(stdcxx . . $ std/::make_sharedcxx . . $ std/make_shared(ffca0f3977536948).<Callable>(stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<F>(callable))) {} |
| 518 | |
| 519 | // Rather than explicitly returning Result, we return whatever the wrapped |
| 520 | // callable returns. This allows for compatibility with existing uses like |
| 521 | // the following, when the mocked function returns void: |
| 522 | // |
| 523 | // EXPECT_CALL(mock_fn_, Call) |
| 524 | // .WillOnce([&] { |
| 525 | // [...] |
| 526 | // return 0; |
| 527 | // }); |
| 528 | // |
| 529 | // Such a callable can be turned into std::function<void()>. If we use an |
| 530 | // explicit return type of Result here then it *doesn't* work with |
| 531 | // std::function, because we'll get a "void function should not return a |
| 532 | // value" error. |
| 533 | // |
| 534 | // We need not worry about incompatible result types because the SFINAE on |
| 535 | // OnceAction already checks this for us. std::is_invocable_r_v itself makes |
| 536 | // the same allowance for void result types. |
| 537 | template <typename... ArgRefs> |
| 538 | internalcxx . . $ testing/internal/::call_result_tcxx . . $ testing/internal/call_result_t#<Callable, ArgRefs...> operatorcxx . . $ testing/OnceAction#StdFunctionAdaptor#`operator()`(32f326e716442511).()( |
| 539 | ArgRefs&&... args) const { |
| 540 | return stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(*callable_cxx . . $ testing/OnceAction#StdFunctionAdaptor#callable_.)(stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<ArgRefs>(args)...); |
| 541 | } |
| 542 | |
| 543 | private: |
| 544 | // We must put the callable on the heap so that we are copyable, which |
| 545 | // std::function needs. |
| 546 | stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<Callable> callable_cxx . . $ testing/OnceAction#StdFunctionAdaptor#callable_.; |
| 547 | }; |
| 548 | |
| 549 | // An adaptor that makes a callable that accepts zero arguments callable with |
| 550 | // our mocked arguments. |
| 551 | template <typename Callable> |
| 552 | struct IgnoreIncomingArgumentscxx . . $ testing/OnceAction#IgnoreIncomingArguments# { |
| 553 | internalcxx . . $ testing/internal/::call_result_tcxx . . $ testing/internal/call_result_t#<Callable> operatorcxx . . $ testing/OnceAction#IgnoreIncomingArguments#`operator()`(b8b19cd2ba84fc5e).()(Args&&...) { |
| 554 | return stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(callablecxx . . $ testing/OnceAction#IgnoreIncomingArguments#callable.)(); |
| 555 | } |
| 556 | |
| 557 | Callable callablecxx . . $ testing/OnceAction#IgnoreIncomingArguments#callable.; |
| 558 | }; |
| 559 | |
| 560 | stdcxx . . $ std/::functioncxx . . $ std/function#<Result(Args...)> function_cxx . . $ testing/OnceAction#function_.; |
| 561 | }; |
| 562 | |
| 563 | // When an unexpected function call is encountered, Google Mock will |
| 564 | // let it return a default value if the user has specified one for its |
| 565 | // return type, or if the return type has a built-in default value; |
| 566 | // otherwise Google Mock won't know what value to return and will have |
| 567 | // to abort the process. |
| 568 | // |
| 569 | // The DefaultValue<T> class allows a user to specify the |
| 570 | // default value for a type T that is both copyable and publicly |
| 571 | // destructible (i.e. anything that can be used as a function return |
| 572 | // type). The usage is: |
| 573 | // |
| 574 | // // Sets the default value for type T to be foo. |
| 575 | // DefaultValue<T>::Set(foo); |
| 576 | template <typename T> |
| 577 | class DefaultValuecxx . . $ testing/DefaultValue# { |
| 578 | public: |
| 579 | // Sets the default value for type T; requires T to be |
| 580 | // copy-constructable and have a public destructor. |
| 581 | static void Setcxx . . $ testing/DefaultValue#Set(9b289cee16747614).(T x) { |
| 582 | delete producer_cxx . . $ testing/DefaultValue#producer_.; |
| 583 | producer_cxx . . $ testing/DefaultValue#producer_. = new FixedValueProducercxx . . $ testing/DefaultValue#FixedValueProducer#(x); |
| 584 | } |
| 585 | |
| 586 | // Provides a factory function to be called to generate the default value. |
| 587 | // This method can be used even if T is only move-constructible, but it is not |
| 588 | // limited to that case. |
| 589 | typedef T (*FactoryFunctioncxx . . $ testing/DefaultValue#FactoryFunction#)(); |
| 590 | static void SetFactorycxx . . $ testing/DefaultValue#SetFactory(5483fd664521b54d).(FactoryFunctioncxx . . $ testing/DefaultValue#FactoryFunction# factory) { |
| 591 | delete producer_cxx . . $ testing/DefaultValue#producer_.; |
| 592 | producer_cxx . . $ testing/DefaultValue#producer_. = new FactoryValueProducercxx . . $ testing/DefaultValue#FactoryValueProducer#(factory); |
| 593 | } |
| 594 | |
| 595 | // Unsets the default value for type T. |
| 596 | static void Clearcxx . . $ testing/DefaultValue#Clear(49f6e7a06ebc5aa8).() { |
| 597 | delete producer_cxx . . $ testing/DefaultValue#producer_.; |
| 598 | producer_cxx . . $ testing/DefaultValue#producer_. = nullptr; |
| 599 | } |
| 600 | |
| 601 | // Returns true if and only if the user has set the default value for type T. |
| 602 | static bool IsSetcxx . . $ testing/DefaultValue#IsSet(c9857a73d68e59ba).() { return producer_cxx . . $ testing/DefaultValue#producer_. != nullptr; } |
| 603 | |
| 604 | // Returns true if T has a default return value set by the user or there |
| 605 | // exists a built-in default value. |
| 606 | static bool Existscxx . . $ testing/DefaultValue#Exists(c9857a73d68e59ba).() { |
| 607 | return IsSetcxx . . $ testing/DefaultValue#IsSet(c9857a73d68e59ba).() || internalcxx . . $ testing/internal/::BuiltInDefaultValuecxx . . $ testing/internal/BuiltInDefaultValue#<T>::Exists(); |
| 608 | } |
| 609 | |
| 610 | // Returns the default value for type T if the user has set one; |
| 611 | // otherwise returns the built-in default value. Requires that Exists() |
| 612 | // is true, which ensures that the return value is well-defined. |
| 613 | static T Getcxx . . $ testing/DefaultValue#Get(5f357b03ed472e5e).() { |
| 614 | return producer_cxx . . $ testing/DefaultValue#producer_. == nullptr ? internalcxx . . $ testing/internal/::BuiltInDefaultValuecxx . . $ testing/internal/BuiltInDefaultValue#<T>::Get() |
| 615 | : producer_cxx . . $ testing/DefaultValue#producer_.->Producecxx . . $ testing/DefaultValue#ValueProducer#Produce(5f357b03ed472e5e).(); |
| 616 | } |
| 617 | |
| 618 | private: |
| 619 | class ValueProducercxx . . $ testing/DefaultValue#ValueProducer# { |
| 620 | public: |
| 621 | virtual ~cxx . . $ testing/DefaultValue#ValueProducer#`~ValueProducer`(49f6e7a06ebc5aa8).ValueProducercxx . . $ testing/DefaultValue#ValueProducer#() = default; |
| 622 | virtual T Producecxx . . $ testing/DefaultValue#ValueProducer#Produce(5f357b03ed472e5e).() = 0; |
| 623 | }; |
| 624 | |
| 625 | class FixedValueProducercxx . . $ testing/DefaultValue#FixedValueProducer# : public ValueProducercxx . . $ testing/DefaultValue#ValueProducer# { |
| 626 | public: |
| 627 | explicit FixedValueProducercxx . . $ testing/DefaultValue#FixedValueProducer#FixedValueProducer(9b289cee16747614).(T value) : value_cxx . . $ testing/DefaultValue#FixedValueProducer#value_.(value) {} |
| 628 | T Producecxx . . $ testing/DefaultValue#FixedValueProducer#Produce(5f357b03ed472e5e).() override { return value_cxx . . $ testing/DefaultValue#FixedValueProducer#value_.; } |
| 629 | |
| 630 | private: |
| 631 | const T value_cxx . . $ testing/DefaultValue#FixedValueProducer#value_.; |
| 632 | FixedValueProducercxx . . $ testing/DefaultValue#FixedValueProducer#FixedValueProducer(3cd95023622bb2a9).(const FixedValueProducercxx . . $ testing/DefaultValue#FixedValueProducer#&) = delete; |
| 633 | FixedValueProducercxx . . $ testing/DefaultValue#FixedValueProducer#& operatorcxx . . $ testing/DefaultValue#FixedValueProducer#`operator=`(d265e56fc45bd2f).=(const FixedValueProducercxx . . $ testing/DefaultValue#FixedValueProducer#&) = delete; |
| 634 | }; |
| 635 | |
| 636 | class FactoryValueProducercxx . . $ testing/DefaultValue#FactoryValueProducer# : public ValueProducercxx . . $ testing/DefaultValue#ValueProducer# { |
| 637 | public: |
| 638 | explicit FactoryValueProducercxx . . $ testing/DefaultValue#FactoryValueProducer#FactoryValueProducer(5483fd664521b54d).(FactoryFunctioncxx . . $ testing/DefaultValue#FactoryFunction# factory) |
| 639 | : factory_cxx . . $ testing/DefaultValue#FactoryValueProducer#factory_.(factory) {} |
| 640 | T Producecxx . . $ testing/DefaultValue#FactoryValueProducer#Produce(5f357b03ed472e5e).() override { return factory_cxx . . $ testing/DefaultValue#FactoryValueProducer#factory_.(); } |
| 641 | |
| 642 | private: |
| 643 | const FactoryFunctioncxx . . $ testing/DefaultValue#FactoryFunction# factory_cxx . . $ testing/DefaultValue#FactoryValueProducer#factory_.; |
| 644 | FactoryValueProducercxx . . $ testing/DefaultValue#FactoryValueProducer#FactoryValueProducer(2cecc0a2fd2278c4).(const FactoryValueProducercxx . . $ testing/DefaultValue#FactoryValueProducer#&) = delete; |
| 645 | FactoryValueProducercxx . . $ testing/DefaultValue#FactoryValueProducer#& operatorcxx . . $ testing/DefaultValue#FactoryValueProducer#`operator=`(f1996b4dfb32532c).=(const FactoryValueProducercxx . . $ testing/DefaultValue#FactoryValueProducer#&) = delete; |
| 646 | }; |
| 647 | |
| 648 | static ValueProducercxx . . $ testing/DefaultValue#ValueProducer#* producer_cxx . . $ testing/DefaultValue#producer_.; |
| 649 | }; |
| 650 | |
| 651 | // This partial specialization allows a user to set default values for |
| 652 | // reference types. |
| 653 | template <typename T> |
| 654 | class DefaultValuecxx . . $ testing/DefaultValue#<T&> { |
| 655 | public: |
| 656 | // Sets the default value for type T&. |
| 657 | static void Setcxx . . $ testing/DefaultValue#Set(8e935d9c2e576e3a).(T& x) { // NOLINT |
| 658 | address_cxx . . $ testing/DefaultValue#address_. = &x; |
| 659 | } |
| 660 | |
| 661 | // Unsets the default value for type T&. |
| 662 | static void Clearcxx . . $ testing/DefaultValue#Clear(49f6e7a06ebc5aa8).() { address_cxx . . $ testing/DefaultValue#address_. = nullptr; } |
| 663 | |
| 664 | // Returns true if and only if the user has set the default value for type T&. |
| 665 | static bool IsSetcxx . . $ testing/DefaultValue#IsSet(c9857a73d68e59ba).() { return address_cxx . . $ testing/DefaultValue#address_. != nullptr; } |
| 666 | |
| 667 | // Returns true if T has a default return value set by the user or there |
| 668 | // exists a built-in default value. |
| 669 | static bool Existscxx . . $ testing/DefaultValue#Exists(c9857a73d68e59ba).() { |
| 670 | return IsSetcxx . . $ testing/DefaultValue#IsSet(c9857a73d68e59ba).() || internalcxx . . $ testing/internal/::BuiltInDefaultValuecxx . . $ testing/internal/BuiltInDefaultValue#<T&>::Exists(); |
| 671 | } |
| 672 | |
| 673 | // Returns the default value for type T& if the user has set one; |
| 674 | // otherwise returns the built-in default value if there is one; |
| 675 | // otherwise aborts the process. |
| 676 | static T& Getcxx . . $ testing/DefaultValue#Get(19b2b6f17af048b).() { |
| 677 | return address_cxx . . $ testing/DefaultValue#address_. == nullptr ? internalcxx . . $ testing/internal/::BuiltInDefaultValuecxx . . $ testing/internal/BuiltInDefaultValue#<T&>::Get() |
| 678 | : *address_cxx . . $ testing/DefaultValue#address_.; |
| 679 | } |
| 680 | |
| 681 | private: |
| 682 | static T* address_cxx . . $ testing/DefaultValue#address_.; |
| 683 | }; |
| 684 | |
| 685 | // This specialization allows DefaultValue<void>::Get() to |
| 686 | // compile. |
| 687 | template <> |
| 688 | class DefaultValuecxx . . $ testing/DefaultValue#<void> { |
| 689 | public: |
| 690 | static bool Existscxx . . $ testing/DefaultValue#Exists(c9857a73d68e59ba).() { return true; } |
| 691 | static void Getcxx . . $ testing/DefaultValue#Get(49f6e7a06ebc5aa8).() {} |
| 692 | }; |
| 693 | |
| 694 | // Points to the user-set default value for type T. |
| 695 | template <typename T> |
| 696 | typename DefaultValuecxx . . $ testing/DefaultValue#<T>::ValueProducercxx . . $ testing/DefaultValue#ValueProducer#* DefaultValuecxx . . $ testing/DefaultValue#<T>::producer_cxx . . $ testing/DefaultValue#producer_. = nullptr; |
| 697 | |
| 698 | // Points to the user-set default value for type T&. |
| 699 | template <typename T> |
| 700 | T* DefaultValuecxx . . $ testing/DefaultValue#<T&>::address_cxx . . $ testing/DefaultValue#address_. = nullptr; |
| 701 | |
| 702 | // Implement this interface to define an action for function type F. |
| 703 | template <typename F> |
| 704 | class ActionInterfacecxx . . $ testing/ActionInterface# { |
| 705 | public: |
| 706 | typedef typename internalcxx . . $ testing/internal/::Functioncxx . . $ testing/internal/Function#<F>::Result Resultcxx . . $ testing/ActionInterface#Result#; |
| 707 | typedef typename internalcxx . . $ testing/internal/::Functioncxx . . $ testing/internal/Function#<F>::ArgumentTuple ArgumentTuplecxx . . $ testing/ActionInterface#ArgumentTuple#; |
| 708 | |
| 709 | ActionInterfacecxx . . $ testing/ActionInterface#`ActionInterface<F>`(49f6e7a06ebc5aa8).() = default; |
| 710 | virtual ~cxx . . $ testing/ActionInterface#`~ActionInterface<F>`(49f6e7a06ebc5aa8).ActionInterface() = default; |
| 711 | |
| 712 | // Performs the action. This method is not const, as in general an |
| 713 | // action can have side effects and be stateful. For example, a |
| 714 | // get-the-next-element-from-the-collection action will need to |
| 715 | // remember the current element. |
| 716 | virtual Resultcxx . . $ testing/ActionInterface#Result# Performcxx . . $ testing/ActionInterface#Perform(a8c712f5c80d1d88).(const ArgumentTuplecxx . . $ testing/ActionInterface#ArgumentTuple#& args) = 0; |
| 717 | |
| 718 | private: |
| 719 | ActionInterfacecxx . . $ testing/ActionInterface#`ActionInterface<F>`(3a2a2d39e10735b1).(const ActionInterface&) = delete; |
| 720 | ActionInterface& operatorcxx . . $ testing/ActionInterface#`operator=`(94b92c082da7aabb).=(const ActionInterface&) = delete; |
| 721 | }; |
| 722 | |
| 723 | template <typename F> |
| 724 | class Actioncxx . . $ testing/Action#; |
| 725 | |
| 726 | // An Action<R(Args...)> is a copyable and IMMUTABLE (except by assignment) |
| 727 | // object that represents an action to be taken when a mock function of type |
| 728 | // R(Args...) is called. The implementation of Action<T> is just a |
| 729 | // std::shared_ptr to const ActionInterface<T>. Don't inherit from Action! You |
| 730 | // can view an object implementing ActionInterface<F> as a concrete action |
| 731 | // (including its current state), and an Action<F> object as a handle to it. |
| 732 | template <typename R, typename... Args> |
| 733 | class Actioncxx . . $ testing/Action#<R(Args...)> { |
| 734 | private: |
| 735 | using Fcxx . . $ testing/Action#F# = R(Args...); |
| 736 | |
| 737 | // Adapter class to allow constructing Action from a legacy ActionInterface. |
| 738 | // New code should create Actions from functors instead. |
| 739 | struct ActionAdaptercxx . . $ testing/Action#ActionAdapter# { |
| 740 | // Adapter must be copyable to satisfy std::function requirements. |
| 741 | ::stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<ActionInterfacecxx . . $ testing/ActionInterface#<Fcxx . . $ testing/Action#F#>> impl_cxx . . $ testing/Action#ActionAdapter#impl_.; |
| 742 | |
| 743 | template <typename... InArgs> |
| 744 | typename internalcxx . . $ testing/internal/::Functioncxx . . $ testing/internal/Function#<F>::Result operatorcxx . . $ testing/Action#ActionAdapter#`operator()`(d749f0aafe592a0a).()(InArgs&&... args) { |
| 745 | return impl_cxx . . $ testing/Action#ActionAdapter#impl_.->Perform( |
| 746 | ::stdcxx . . $ std/::forward_as_tuplecxx . . $ std/forward_as_tuple(cd19fb0d9524ec73).(::stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<InArgs>(args)...)); |
| 747 | } |
| 748 | }; |
| 749 | |
| 750 | template <typename G> |
| 751 | using IsCompatibleFunctorcxx . . $ testing/Action#IsCompatibleFunctor# = stdcxx . . $ std/::is_constructible<stdcxx . . $ std/::functioncxx . . $ std/function#<Fcxx . . $ testing/Action#F#>, G>; |
| 752 | |
| 753 | public: |
| 754 | typedef typename internalcxx . . $ testing/internal/::Functioncxx . . $ testing/internal/Function#<F>::Result Resultcxx . . $ testing/Action#Result#; |
| 755 | typedef typename internalcxx . . $ testing/internal/::Functioncxx . . $ testing/internal/Function#<F>::ArgumentTuple ArgumentTuplecxx . . $ testing/Action#ArgumentTuple#; |
| 756 | |
| 757 | // Constructs a null Action. Needed for storing Action objects in |
| 758 | // STL containers. |
| 759 | Actioncxx . . $ testing/Action#`Action<R (Args...)>`(49f6e7a06ebc5aa8).() = default; |
| 760 | |
| 761 | // Construct an Action from a specified callable. |
| 762 | // This cannot take std::function directly, because then Action would not be |
| 763 | // directly constructible from lambda (it would require two conversions). |
| 764 | template < |
| 765 | typename G, |
| 766 | typename = typename stdcxx . . $ std/::enable_if<internal::disjunction< |
| 767 | IsCompatibleFunctor<G>, std::is_constructible<std::function<Result()>, |
| 768 | G>>::value>::type> |
| 769 | Actioncxx . . $ testing/Action#`Action<R (Args...)>`(4f6c0277e8680150).(G&& fun) { // NOLINT |
| 770 | Init(::stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<G>(fun), IsCompatibleFunctorcxx . . $ testing/Action#IsCompatibleFunctor#<G>()); |
| 771 | } |
| 772 | |
| 773 | // Constructs an Action from its implementation. |
| 774 | explicit Actioncxx . . $ testing/Action#`Action<R (Args...)>`(c9aad281ed9b4444).(ActionInterfacecxx . . $ testing/ActionInterface#<Fcxx . . $ testing/Action#F#>* impl) |
| 775 | : fun_cxx . . $ testing/Action#fun_.(ActionAdaptercxx . . $ testing/Action#ActionAdapter#{::stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<ActionInterfacecxx . . $ testing/ActionInterface#<Fcxx . . $ testing/Action#F#>>(impl)}) {} |
| 776 | |
| 777 | // This constructor allows us to turn an Action<Func> object into an |
| 778 | // Action<F>, as long as F's arguments can be implicitly converted |
| 779 | // to Func's and Func's return type can be implicitly converted to F's. |
| 780 | template <typename Func> |
| 781 | Actioncxx . . $ testing/Action#`Action<R (Args...)>`(c1869ffb8e3f70ea).(const Actioncxx . . $ testing/Action#<Func>& action) // NOLINT |
| 782 | : fun_cxx . . $ testing/Action#fun_.(action.fun_) {} |
| 783 | |
| 784 | // Returns true if and only if this is the DoDefault() action. |
| 785 | bool IsDoDefaultcxx . . $ testing/Action#IsDoDefault(50ce9a9e25b4a850).() const { return fun_cxx . . $ testing/Action#fun_. == nullptr; } |
| 786 | |
| 787 | // Performs the action. Note that this method is const even though |
| 788 | // the corresponding method in ActionInterface is not. The reason |
| 789 | // is that a const Action<F> means that it cannot be re-bound to |
| 790 | // another concrete action, not that the concrete action it binds to |
| 791 | // cannot change state. (Think of the difference between a const |
| 792 | // pointer and a pointer to const.) |
| 793 | Resultcxx . . $ testing/Action#Result# Performcxx . . $ testing/Action#Perform(5e31c7adb76eea1c).(ArgumentTuplecxx . . $ testing/Action#ArgumentTuple# args) const { |
| 794 | if (IsDoDefaultcxx . . $ testing/Action#IsDoDefault(50ce9a9e25b4a850).()) { |
| 795 | internalcxx . . $ testing/internal/::IllegalDoDefaultcxx . . $ testing/internal/IllegalDoDefault(34d26762b42c433a).(__FILE__, __LINE__); |
| 796 | } |
| 797 | return internalcxx . . $ testing/internal/::Applycxx . . $ testing/internal/Apply(6593b434a6c264f).(fun_cxx . . $ testing/Action#fun_., ::stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(args)); |
| 798 | } |
| 799 | |
| 800 | // An action can be used as a OnceAction, since it's obviously safe to call it |
| 801 | // once. |
| 802 | operatorcxx . . $ testing/Action#`operator OnceAction<type-parameter-0-0 (type-parameter-0-1...)>`(b502b3b9843bb8af). OnceActioncxx . . $ testing/OnceAction#<Fcxx . . $ testing/Action#F#>() const { // NOLINT |
| 803 | // Return a OnceAction-compatible callable that calls Perform with the |
| 804 | // arguments it is provided. We could instead just return fun_, but then |
| 805 | // we'd need to handle the IsDoDefault() case separately. |
| 806 | struct OAcxx . . $ testing/Action#`operator OnceAction<type-parameter-0-0 (type-parameter-0-1...)>`(b502b3b9843bb8af).OA# { |
| 807 | Actioncxx . . $ testing/Action#<Fcxx . . $ testing/Action#F#> actioncxx . . $ testing/Action#`operator OnceAction<type-parameter-0-0 (type-parameter-0-1...)>`(b502b3b9843bb8af).OA#action.; |
| 808 | |
| 809 | R operatorcxx . . $ testing/Action#`operator OnceAction<type-parameter-0-0 (type-parameter-0-1...)>`(b502b3b9843bb8af).OA#`operator()`(f01b9517887e9157).()(Args... args) && { |
| 810 | return actioncxx . . $ testing/Action#`operator OnceAction<type-parameter-0-0 (type-parameter-0-1...)>`(b502b3b9843bb8af).OA#action..Performcxx . . $ testing/Action#Perform(5e31c7adb76eea1c).( |
| 811 | stdcxx . . $ std/::forward_as_tuplecxx . . $ std/forward_as_tuple(cd19fb0d9524ec73).(stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<Args>(args)...)); |
| 812 | } |
| 813 | }; |
| 814 | |
| 815 | return OAcxx . . $ testing/Action#`operator OnceAction<type-parameter-0-0 (type-parameter-0-1...)>`(b502b3b9843bb8af).OA#{*this}; |
| 816 | } |
| 817 | |
| 818 | private: |
| 819 | template <typename G> |
| 820 | friend class Actioncxx . . $ testing/Action#; |
| 821 | |
| 822 | template <typename G> |
| 823 | void Initcxx . . $ testing/Action#Init(6a0e08ed75b905c9).(G&& g, ::stdcxx . . $ std/::true_type) { |
| 824 | fun_cxx . . $ testing/Action#fun_. = ::stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<G>(g); |
| 825 | } |
| 826 | |
| 827 | template <typename G> |
| 828 | void Initcxx . . $ testing/Action#Init(ac05d58f2dee64da).(G&& g, ::stdcxx . . $ std/::false_type) { |
| 829 | fun_cxx . . $ testing/Action#fun_. = IgnoreArgscxx . . $ testing/Action#IgnoreArgs#<typename ::stdcxx . . $ std/::decay<G>::type>{::stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<G>(g)}; |
| 830 | } |
| 831 | |
| 832 | template <typename FunctionImpl> |
| 833 | struct IgnoreArgscxx . . $ testing/Action#IgnoreArgs# { |
| 834 | template <typename... InArgs> |
| 835 | Resultcxx . . $ testing/Action#Result# operatorcxx . . $ testing/Action#IgnoreArgs#`operator()`(963974b3ca5b1393).()(const InArgs&...) const { |
| 836 | return function_implcxx . . $ testing/Action#IgnoreArgs#function_impl.(); |
| 837 | } |
| 838 | template <typename... InArgs> |
| 839 | Resultcxx . . $ testing/Action#Result# operatorcxx . . $ testing/Action#IgnoreArgs#`operator()`(931985f772781c6b).()(const InArgs&...) { |
| 840 | return function_implcxx . . $ testing/Action#IgnoreArgs#function_impl.(); |
| 841 | } |
| 842 | |
| 843 | FunctionImpl function_implcxx . . $ testing/Action#IgnoreArgs#function_impl.; |
| 844 | }; |
| 845 | |
| 846 | // fun_ is an empty function if and only if this is the DoDefault() action. |
| 847 | ::stdcxx . . $ std/::functioncxx . . $ std/function#<Fcxx . . $ testing/Action#F#> fun_cxx . . $ testing/Action#fun_.; |
| 848 | }; |
| 849 | |
| 850 | // The PolymorphicAction class template makes it easy to implement a |
| 851 | // polymorphic action (i.e. an action that can be used in mock |
| 852 | // functions of than one type, e.g. Return()). |
| 853 | // |
| 854 | // To define a polymorphic action, a user first provides a COPYABLE |
| 855 | // implementation class that has a Perform() method template: |
| 856 | // |
| 857 | // class FooAction { |
| 858 | // public: |
| 859 | // template <typename Result, typename ArgumentTuple> |
| 860 | // Result Perform(const ArgumentTuple& args) const { |
| 861 | // // Processes the arguments and returns a result, using |
| 862 | // // std::get<N>(args) to get the N-th (0-based) argument in the tuple. |
| 863 | // } |
| 864 | // ... |
| 865 | // }; |
| 866 | // |
| 867 | // Then the user creates the polymorphic action using |
| 868 | // MakePolymorphicAction(object) where object has type FooAction. See |
| 869 | // the definition of Return(void) and SetArgumentPointee<N>(value) for |
| 870 | // complete examples. |
| 871 | template <typename Impl> |
| 872 | class PolymorphicActioncxx . . $ testing/PolymorphicAction# { |
| 873 | public: |
| 874 | explicit PolymorphicActioncxx . . $ testing/PolymorphicAction#`PolymorphicAction<Impl>`(77d9f17553126ecb).(const Impl& impl) : impl_cxx . . $ testing/PolymorphicAction#impl_.(impl) {} |
| 875 | |
| 876 | template <typename F> |
| 877 | operatorcxx . . $ testing/PolymorphicAction#`operator Action<type-parameter-1-0>`(d222aac85de04b2e). Actioncxx . . $ testing/Action#<F>() const { |
| 878 | return Actioncxx . . $ testing/Action#<F>(new MonomorphicImplcxx . . $ testing/PolymorphicAction#MonomorphicImpl#<F>(impl_cxx . . $ testing/PolymorphicAction#impl_.)); |
| 879 | } |
| 880 | |
| 881 | private: |
| 882 | template <typename F> |
| 883 | class MonomorphicImplcxx . . $ testing/PolymorphicAction#MonomorphicImpl# : public ActionInterfacecxx . . $ testing/ActionInterface#<F> { |
| 884 | public: |
| 885 | typedef typename internalcxx . . $ testing/internal/::Functioncxx . . $ testing/internal/Function#<F>::Result Resultcxx . . $ testing/PolymorphicAction#MonomorphicImpl#Result#; |
| 886 | typedef typename internalcxx . . $ testing/internal/::Functioncxx . . $ testing/internal/Function#<F>::ArgumentTuple ArgumentTuplecxx . . $ testing/PolymorphicAction#MonomorphicImpl#ArgumentTuple#; |
| 887 | |
| 888 | explicit MonomorphicImplcxx . . $ testing/PolymorphicAction#MonomorphicImpl#`MonomorphicImpl<F>`(77d9f17553126ecb).(const Impl& impl) : impl_cxx . . $ testing/PolymorphicAction#MonomorphicImpl#impl_.(impl) {} |
| 889 | |
| 890 | Resultcxx . . $ testing/PolymorphicAction#MonomorphicImpl#Result# Performcxx . . $ testing/PolymorphicAction#MonomorphicImpl#Perform(645bc447c39635c6).(const ArgumentTuplecxx . . $ testing/PolymorphicAction#MonomorphicImpl#ArgumentTuple#& args) override { |
| 891 | return impl_cxx . . $ testing/PolymorphicAction#MonomorphicImpl#impl_..template Perform<Resultcxx . . $ testing/PolymorphicAction#MonomorphicImpl#Result#>(args); |
| 892 | } |
| 893 | |
| 894 | private: |
| 895 | Impl impl_cxx . . $ testing/PolymorphicAction#MonomorphicImpl#impl_.; |
| 896 | }; |
| 897 | |
| 898 | Impl impl_cxx . . $ testing/PolymorphicAction#impl_.; |
| 899 | }; |
| 900 | |
| 901 | // Creates an Action from its implementation and returns it. The |
| 902 | // created Action object owns the implementation. |
| 903 | template <typename F> |
| 904 | Actioncxx . . $ testing/Action#<F> MakeActioncxx . . $ testing/MakeAction(ef54eec51843cab4).(ActionInterfacecxx . . $ testing/ActionInterface#<F>* impl) { |
| 905 | return Actioncxx . . $ testing/Action#<F>(impl); |
| 906 | } |
| 907 | |
| 908 | // Creates a polymorphic action from its implementation. This is |
| 909 | // easier to use than the PolymorphicAction<Impl> constructor as it |
| 910 | // doesn't require you to explicitly write the template argument, e.g. |
| 911 | // |
| 912 | // MakePolymorphicAction(foo); |
| 913 | // vs |
| 914 | // PolymorphicAction<TypeOfFoo>(foo); |
| 915 | template <typename Impl> |
| 916 | inline PolymorphicActioncxx . . $ testing/PolymorphicAction#<Impl> MakePolymorphicActioncxx . . $ testing/MakePolymorphicAction(712d411a1ea0c3b).(const Impl& impl) { |
| 917 | return PolymorphicActioncxx . . $ testing/PolymorphicAction#<Impl>(impl); |
| 918 | } |
| 919 | |
| 920 | namespace internalcxx . . $ testing/internal/ { |
| 921 | |
| 922 | // Helper struct to specialize ReturnAction to execute a move instead of a copy |
| 923 | // on return. Useful for move-only types, but could be used on any type. |
| 924 | template <typename T> |
| 925 | struct ByMoveWrappercxx . . $ testing/internal/ByMoveWrapper# { |
| 926 | explicit ByMoveWrappercxx . . $ testing/internal/ByMoveWrapper#`ByMoveWrapper<T>`(9b289cee16747614).(T value) : payloadcxx . . $ testing/internal/ByMoveWrapper#payload.(stdcxx . . $ std/::movecxx . . $ std/move(88304b602929f6f4).(value)) {} |
| 927 | T payloadcxx . . $ testing/internal/ByMoveWrapper#payload.; |
| 928 | }; |
| 929 | |
| 930 | // The general implementation of Return(R). Specializations follow below. |
| 931 | template <typename R> |
| 932 | class ReturnActioncxx . . $ testing/internal/ReturnAction# final { |
| 933 | public: |
| 934 | explicit ReturnActioncxx . . $ testing/internal/ReturnAction#`ReturnAction<R>`(9b289cee16747614).(R value) : value_cxx . . $ testing/internal/ReturnAction#value_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(value)) {} |
| 935 | |
| 936 | template <typename U, typename... Args, |
| 937 | typename = typename stdcxx . . $ std/::enable_if<conjunction< |
| 938 | // See the requirements documented on Return. |
| 939 | negation<std::is_same<void, U>>, // |
| 940 | negation<std::is_reference<U>>, // |
| 941 | std::is_convertible<R, U>, // |
| 942 | std::is_move_constructible<U>>::value>::type> |
| 943 | operatorcxx . . $ testing/internal/ReturnAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9). OnceActioncxx . . $ testing/OnceAction#<U(Args...)>() && { // NOLINT |
| 944 | return Implcxx . . $ testing/internal/ReturnAction#Impl#<U>(stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(value_cxx . . $ testing/internal/ReturnAction#value_.)); |
| 945 | } |
| 946 | |
| 947 | template <typename U, typename... Args, |
| 948 | typename = typename stdcxx . . $ std/::enable_if<conjunction< |
| 949 | // See the requirements documented on Return. |
| 950 | negation<std::is_same<void, U>>, // |
| 951 | negation<std::is_reference<U>>, // |
| 952 | std::is_convertible<const R&, U>, // |
| 953 | std::is_copy_constructible<U>>::value>::type> |
| 954 | operatorcxx . . $ testing/internal/ReturnAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41). Actioncxx . . $ testing/Action#<U(Args...)>() const { // NOLINT |
| 955 | return Implcxx . . $ testing/internal/ReturnAction#Impl#<U>(value_cxx . . $ testing/internal/ReturnAction#value_.); |
| 956 | } |
| 957 | |
| 958 | private: |
| 959 | // Implements the Return(x) action for a mock function that returns type U. |
| 960 | template <typename U> |
| 961 | class Implcxx . . $ testing/internal/ReturnAction#Impl# final { |
| 962 | public: |
| 963 | // The constructor used when the return value is allowed to move from the |
| 964 | // input value (i.e. we are converting to OnceAction). |
| 965 | explicit Implcxx . . $ testing/internal/ReturnAction#Impl#`Impl<U>`(fe7a8a4d1eddb70).(R&& input_value) |
| 966 | : state_cxx . . $ testing/internal/ReturnAction#Impl#state_.(new Statecxx . . $ testing/internal/ReturnAction#Impl#State#(stdcxx . . $ std/::movecxx . . $ std/move(88304b602929f6f4).(input_value))) {} |
| 967 | |
| 968 | // The constructor used when the return value is not allowed to move from |
| 969 | // the input value (i.e. we are converting to Action). |
| 970 | explicit Implcxx . . $ testing/internal/ReturnAction#Impl#`Impl<U>`(77d9f17553126ecb).(const R& input_value) : state_cxx . . $ testing/internal/ReturnAction#Impl#state_.(new Statecxx . . $ testing/internal/ReturnAction#Impl#State#(input_value)) {} |
| 971 | |
| 972 | U operatorcxx . . $ testing/internal/ReturnAction#Impl#`operator()`(22b1d6cf8429c12b).()() && { return stdcxx . . $ std/::movecxx . . $ std/move(88304b602929f6f4).(state_cxx . . $ testing/internal/ReturnAction#Impl#state_.->value); } |
| 973 | U operatorcxx . . $ testing/internal/ReturnAction#Impl#`operator()`(1af80543910dcd63).()() const& { return state_cxx . . $ testing/internal/ReturnAction#Impl#state_.->value; } |
| 974 | |
| 975 | private: |
| 976 | // We put our state on the heap so that the compiler-generated copy/move |
| 977 | // constructors work correctly even when U is a reference-like type. This is |
| 978 | // necessary only because we eagerly create State::value (see the note on |
| 979 | // that symbol for details). If we instead had only the input value as a |
| 980 | // member then the default constructors would work fine. |
| 981 | // |
| 982 | // For example, when R is std::string and U is std::string_view, value is a |
| 983 | // reference to the string backed by input_value. The copy constructor would |
| 984 | // copy both, so that we wind up with a new input_value object (with the |
| 985 | // same contents) and a reference to the *old* input_value object rather |
| 986 | // than the new one. |
| 987 | struct Statecxx . . $ testing/internal/ReturnAction#Impl#State# { |
| 988 | explicit Statecxx . . $ testing/internal/ReturnAction#Impl#State#State(77d9f17553126ecb).(const R& input_value_in) |
| 989 | : input_valuecxx . . $ testing/internal/ReturnAction#Impl#State#input_value.(input_value_in), |
| 990 | // Make an implicit conversion to Result before initializing the U |
| 991 | // object we store, avoiding calling any explicit constructor of U |
| 992 | // from R. |
| 993 | // |
| 994 | // This simulates the language rules: a function with return type U |
| 995 | // that does `return R()` requires R to be implicitly convertible to |
| 996 | // U, and uses that path for the conversion, even U Result has an |
| 997 | // explicit constructor from R. |
| 998 | valuecxx . . $ testing/internal/ReturnAction#Impl#State#value.(ImplicitCast_cxx . . $ testing/internal/ImplicitCast_(ada6a8422704cf8a).<U>(internalcxx . . $ testing/internal/::as_constcxx . . $ testing/internal/as_const(a9df1f66f9aef2b2).(input_valuecxx . . $ testing/internal/ReturnAction#Impl#State#input_value.))) {} |
| 999 | |
| 1000 | // As above, but for the case where we're moving from the ReturnAction |
| 1001 | // object because it's being used as a OnceAction. |
| 1002 | explicit Statecxx . . $ testing/internal/ReturnAction#Impl#State#State(fe7a8a4d1eddb70).(R&& input_value_in) |
| 1003 | : input_valuecxx . . $ testing/internal/ReturnAction#Impl#State#input_value.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(input_value_in)), |
| 1004 | // For the same reason as above we make an implicit conversion to U |
| 1005 | // before initializing the value. |
| 1006 | // |
| 1007 | // Unlike above we provide the input value as an rvalue to the |
| 1008 | // implicit conversion because this is a OnceAction: it's fine if it |
| 1009 | // wants to consume the input value. |
| 1010 | valuecxx . . $ testing/internal/ReturnAction#Impl#State#value.(ImplicitCast_cxx . . $ testing/internal/ImplicitCast_(ada6a8422704cf8a).<U>(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(input_valuecxx . . $ testing/internal/ReturnAction#Impl#State#input_value.))) {} |
| 1011 | |
| 1012 | // A copy of the value originally provided by the user. We retain this in |
| 1013 | // addition to the value of the mock function's result type below in case |
| 1014 | // the latter is a reference-like type. See the std::string_view example |
| 1015 | // in the documentation on Return. |
| 1016 | R input_valuecxx . . $ testing/internal/ReturnAction#Impl#State#input_value.; |
| 1017 | |
| 1018 | // The value we actually return, as the type returned by the mock function |
| 1019 | // itself. |
| 1020 | // |
| 1021 | // We eagerly initialize this here, rather than lazily doing the implicit |
| 1022 | // conversion automatically each time Perform is called, for historical |
| 1023 | // reasons: in 2009-11, commit a070cbd91c (Google changelist 13540126) |
| 1024 | // made the Action<U()> conversion operator eagerly convert the R value to |
| 1025 | // U, but without keeping the R alive. This broke the use case discussed |
| 1026 | // in the documentation for Return, making reference-like types such as |
| 1027 | // std::string_view not safe to use as U where the input type R is a |
| 1028 | // value-like type such as std::string. |
| 1029 | // |
| 1030 | // The example the commit gave was not very clear, nor was the issue |
| 1031 | // thread (https://github.com/google/googlemock/issues/86), but it seems |
| 1032 | // the worry was about reference-like input types R that flatten to a |
| 1033 | // value-like type U when being implicitly converted. An example of this |
| 1034 | // is std::vector<bool>::reference, which is often a proxy type with an |
| 1035 | // reference to the underlying vector: |
| 1036 | // |
| 1037 | // // Helper method: have the mock function return bools according |
| 1038 | // // to the supplied script. |
| 1039 | // void SetActions(MockFunction<bool(size_t)>& mock, |
| 1040 | // const std::vector<bool>& script) { |
| 1041 | // for (size_t i = 0; i < script.size(); ++i) { |
| 1042 | // EXPECT_CALL(mock, Call(i)).WillOnce(Return(script[i])); |
| 1043 | // } |
| 1044 | // } |
| 1045 | // |
| 1046 | // TEST(Foo, Bar) { |
| 1047 | // // Set actions using a temporary vector, whose operator[] |
| 1048 | // // returns proxy objects that references that will be |
| 1049 | // // dangling once the call to SetActions finishes and the |
| 1050 | // // vector is destroyed. |
| 1051 | // MockFunction<bool(size_t)> mock; |
| 1052 | // SetActions(mock, {false, true}); |
| 1053 | // |
| 1054 | // EXPECT_FALSE(mock.AsStdFunction()(0)); |
| 1055 | // EXPECT_TRUE(mock.AsStdFunction()(1)); |
| 1056 | // } |
| 1057 | // |
| 1058 | // This eager conversion helps with a simple case like this, but doesn't |
| 1059 | // fully make these types work in general. For example the following still |
| 1060 | // uses a dangling reference: |
| 1061 | // |
| 1062 | // TEST(Foo, Baz) { |
| 1063 | // MockFunction<std::vector<std::string>()> mock; |
| 1064 | // |
| 1065 | // // Return the same vector twice, and then the empty vector |
| 1066 | // // thereafter. |
| 1067 | // auto action = Return(std::initializer_list<std::string>{ |
| 1068 | // "taco", "burrito", |
| 1069 | // }); |
| 1070 | // |
| 1071 | // EXPECT_CALL(mock, Call) |
| 1072 | // .WillOnce(action) |
| 1073 | // .WillOnce(action) |
| 1074 | // .WillRepeatedly(Return(std::vector<std::string>{})); |
| 1075 | // |
| 1076 | // EXPECT_THAT(mock.AsStdFunction()(), |
| 1077 | // ElementsAre("taco", "burrito")); |
| 1078 | // EXPECT_THAT(mock.AsStdFunction()(), |
| 1079 | // ElementsAre("taco", "burrito")); |
| 1080 | // EXPECT_THAT(mock.AsStdFunction()(), IsEmpty()); |
| 1081 | // } |
| 1082 | // |
| 1083 | U valuecxx . . $ testing/internal/ReturnAction#Impl#State#value.; |
| 1084 | }; |
| 1085 | |
| 1086 | const stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<Statecxx . . $ testing/internal/ReturnAction#Impl#State#> state_cxx . . $ testing/internal/ReturnAction#Impl#state_.; |
| 1087 | }; |
| 1088 | |
| 1089 | R value_cxx . . $ testing/internal/ReturnAction#value_.; |
| 1090 | }; |
| 1091 | |
| 1092 | // A specialization of ReturnAction<R> when R is ByMoveWrapper<T> for some T. |
| 1093 | // |
| 1094 | // This version applies the type system-defeating hack of moving from T even in |
| 1095 | // the const call operator, checking at runtime that it isn't called more than |
| 1096 | // once, since the user has declared their intent to do so by using ByMove. |
| 1097 | template <typename T> |
| 1098 | class ReturnActioncxx . . $ testing/internal/ReturnAction#<ByMoveWrappercxx . . $ testing/internal/ByMoveWrapper#<T>> final { |
| 1099 | public: |
| 1100 | explicit ReturnActioncxx . . $ testing/internal/ReturnAction#`ReturnAction<ByMoveWrapper<T>>`(6ce65cb051a69c77).(ByMoveWrappercxx . . $ testing/internal/ByMoveWrapper#<T> wrapper) |
| 1101 | : state_cxx . . $ testing/internal/ReturnAction#state_.(new Statecxx . . $ testing/internal/ReturnAction#State#(stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(wrapper.payloadcxx . . $ testing/internal/ByMoveWrapper#payload.))) {} |
| 1102 | |
| 1103 | T operatorcxx . . $ testing/internal/ReturnAction#`operator()`(8f5363d873dd4781).()() const { |
| 1104 | GTEST_CHECK_cxx . . $ std/`operator<<`(efaf8c13fc75f3c7).(!state_->called) |
| 1105 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "A ByMove() action must be performed at most once."; |
| 1106 | |
| 1107 | state_cxx . . $ testing/internal/ReturnAction#state_.->called = true; |
| 1108 | return stdcxx . . $ std/::movecxx . . $ std/move(88304b602929f6f4).(state_cxx . . $ testing/internal/ReturnAction#state_.->value); |
| 1109 | } |
| 1110 | |
| 1111 | private: |
| 1112 | // We store our state on the heap so that we are copyable as required by |
| 1113 | // Action, despite the fact that we are stateful and T may not be copyable. |
| 1114 | struct Statecxx . . $ testing/internal/ReturnAction#State# { |
| 1115 | explicit Statecxx . . $ testing/internal/ReturnAction#State#State(fe7a8a4d1eddb70).(T&& value_in) : valuecxx . . $ testing/internal/ReturnAction#State#value.(stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(value_in)) {} |
| 1116 | |
| 1117 | T valuecxx . . $ testing/internal/ReturnAction#State#value.; |
| 1118 | bool calledcxx . . $ testing/internal/ReturnAction#State#called. = false; |
| 1119 | }; |
| 1120 | |
| 1121 | const stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<Statecxx . . $ testing/internal/ReturnAction#State#> state_cxx . . $ testing/internal/ReturnAction#state_.; |
| 1122 | }; |
| 1123 | |
| 1124 | // Implements the ReturnNull() action. |
| 1125 | class ReturnNullActioncxx . . $ testing/internal/ReturnNullAction# { |
| 1126 | public: |
| 1127 | // Allows ReturnNull() to be used in any pointer-returning function. In C++11 |
| 1128 | // this is enforced by returning nullptr, and in non-C++11 by asserting a |
| 1129 | // pointer type on compile time. |
| 1130 | template <typename Result, typename ArgumentTuple> |
| 1131 | static Result Performcxx . . $ testing/internal/ReturnNullAction#Perform(5dc1535cced3b05b).(const ArgumentTuple&) { |
| 1132 | return nullptr; |
| 1133 | } |
| 1134 | }; |
| 1135 | |
| 1136 | // Implements the Return() action. |
| 1137 | class ReturnVoidActioncxx . . $ testing/internal/ReturnVoidAction# { |
| 1138 | public: |
| 1139 | // Allows Return() to be used in any void-returning function. |
| 1140 | template <typename Result, typename ArgumentTuple> |
| 1141 | static void Performcxx . . $ testing/internal/ReturnVoidAction#Perform(3496de05b827211c).(const ArgumentTuple&) { |
| 1142 | static_assert(stdcxx . . $ std/::is_void<Result>::value, "Result should be void."); |
| 1143 | } |
| 1144 | }; |
| 1145 | |
| 1146 | // Implements the polymorphic ReturnRef(x) action, which can be used |
| 1147 | // in any function that returns a reference to the type of x, |
| 1148 | // regardless of the argument types. |
| 1149 | template <typename T> |
| 1150 | class ReturnRefActioncxx . . $ testing/internal/ReturnRefAction# { |
| 1151 | public: |
| 1152 | // Constructs a ReturnRefAction object from the reference to be returned. |
| 1153 | explicit ReturnRefActioncxx . . $ testing/internal/ReturnRefAction#`ReturnRefAction<T>`(8e935d9c2e576e3a).(T& ref) : ref_cxx . . $ testing/internal/ReturnRefAction#ref_.(ref) {} // NOLINT |
| 1154 | |
| 1155 | // This template type conversion operator allows ReturnRef(x) to be |
| 1156 | // used in ANY function that returns a reference to x's type. |
| 1157 | template <typename F> |
| 1158 | operatorcxx . . $ testing/internal/ReturnRefAction#`operator Action<type-parameter-1-0>`(d222aac85de04b2e). Actioncxx . . $ testing/Action#<F>() const { |
| 1159 | typedef typename Functioncxx . . $ testing/internal/Function#<F>::Result Resultcxx . . $ testing/internal/ReturnRefAction#`operator Action<type-parameter-1-0>`(d222aac85de04b2e).Result#; |
| 1160 | // Asserts that the function return type is a reference. This |
| 1161 | // catches the user error of using ReturnRef(x) when Return(x) |
| 1162 | // should be used, and generates some helpful error message. |
| 1163 | static_assert(stdcxx . . $ std/::is_reference<Result>::value, |
| 1164 | "use Return instead of ReturnRef to return a value"); |
| 1165 | return Actioncxx . . $ testing/Action#<F>(new Implcxx . . $ testing/internal/ReturnRefAction#Impl#<F>(ref_cxx . . $ testing/internal/ReturnRefAction#ref_.)); |
| 1166 | } |
| 1167 | |
| 1168 | private: |
| 1169 | // Implements the ReturnRef(x) action for a particular function type F. |
| 1170 | template <typename F> |
| 1171 | class Implcxx . . $ testing/internal/ReturnRefAction#Impl# : public ActionInterfacecxx . . $ testing/ActionInterface#<F> { |
| 1172 | public: |
| 1173 | typedef typename Functioncxx . . $ testing/internal/Function#<F>::Result Resultcxx . . $ testing/internal/ReturnRefAction#Impl#Result#; |
| 1174 | typedef typename Functioncxx . . $ testing/internal/Function#<F>::ArgumentTuple ArgumentTuplecxx . . $ testing/internal/ReturnRefAction#Impl#ArgumentTuple#; |
| 1175 | |
| 1176 | explicit Implcxx . . $ testing/internal/ReturnRefAction#Impl#`Impl<F>`(8e935d9c2e576e3a).(T& ref) : ref_cxx . . $ testing/internal/ReturnRefAction#Impl#ref_.(ref) {} // NOLINT |
| 1177 | |
| 1178 | Resultcxx . . $ testing/internal/ReturnRefAction#Impl#Result# Performcxx . . $ testing/internal/ReturnRefAction#Impl#Perform(645bc447c39635c6).(const ArgumentTuplecxx . . $ testing/internal/ReturnRefAction#Impl#ArgumentTuple#&) override { return ref_cxx . . $ testing/internal/ReturnRefAction#Impl#ref_.; } |
| 1179 | |
| 1180 | private: |
| 1181 | T& ref_cxx . . $ testing/internal/ReturnRefAction#Impl#ref_.; |
| 1182 | }; |
| 1183 | |
| 1184 | T& ref_cxx . . $ testing/internal/ReturnRefAction#ref_.; |
| 1185 | }; |
| 1186 | |
| 1187 | // Implements the polymorphic ReturnRefOfCopy(x) action, which can be |
| 1188 | // used in any function that returns a reference to the type of x, |
| 1189 | // regardless of the argument types. |
| 1190 | template <typename T> |
| 1191 | class ReturnRefOfCopyActioncxx . . $ testing/internal/ReturnRefOfCopyAction# { |
| 1192 | public: |
| 1193 | // Constructs a ReturnRefOfCopyAction object from the reference to |
| 1194 | // be returned. |
| 1195 | explicit ReturnRefOfCopyActioncxx . . $ testing/internal/ReturnRefOfCopyAction#`ReturnRefOfCopyAction<T>`(77d9f17553126ecb).(const T& value) : value_cxx . . $ testing/internal/ReturnRefOfCopyAction#value_.(value) {} // NOLINT |
| 1196 | |
| 1197 | // This template type conversion operator allows ReturnRefOfCopy(x) to be |
| 1198 | // used in ANY function that returns a reference to x's type. |
| 1199 | template <typename F> |
| 1200 | operatorcxx . . $ testing/internal/ReturnRefOfCopyAction#`operator Action<type-parameter-1-0>`(d222aac85de04b2e). Actioncxx . . $ testing/Action#<F>() const { |
| 1201 | typedef typename Functioncxx . . $ testing/internal/Function#<F>::Result Resultcxx . . $ testing/internal/ReturnRefOfCopyAction#`operator Action<type-parameter-1-0>`(d222aac85de04b2e).Result#; |
| 1202 | // Asserts that the function return type is a reference. This |
| 1203 | // catches the user error of using ReturnRefOfCopy(x) when Return(x) |
| 1204 | // should be used, and generates some helpful error message. |
| 1205 | static_assert(stdcxx . . $ std/::is_reference<Result>::value, |
| 1206 | "use Return instead of ReturnRefOfCopy to return a value"); |
| 1207 | return Actioncxx . . $ testing/Action#<F>(new Implcxx . . $ testing/internal/ReturnRefOfCopyAction#Impl#<F>(value_cxx . . $ testing/internal/ReturnRefOfCopyAction#value_.)); |
| 1208 | } |
| 1209 | |
| 1210 | private: |
| 1211 | // Implements the ReturnRefOfCopy(x) action for a particular function type F. |
| 1212 | template <typename F> |
| 1213 | class Implcxx . . $ testing/internal/ReturnRefOfCopyAction#Impl# : public ActionInterfacecxx . . $ testing/ActionInterface#<F> { |
| 1214 | public: |
| 1215 | typedef typename Functioncxx . . $ testing/internal/Function#<F>::Result Resultcxx . . $ testing/internal/ReturnRefOfCopyAction#Impl#Result#; |
| 1216 | typedef typename Functioncxx . . $ testing/internal/Function#<F>::ArgumentTuple ArgumentTuplecxx . . $ testing/internal/ReturnRefOfCopyAction#Impl#ArgumentTuple#; |
| 1217 | |
| 1218 | explicit Implcxx . . $ testing/internal/ReturnRefOfCopyAction#Impl#`Impl<F>`(77d9f17553126ecb).(const T& value) : value_cxx . . $ testing/internal/ReturnRefOfCopyAction#Impl#value_.(value) {} // NOLINT |
| 1219 | |
| 1220 | Resultcxx . . $ testing/internal/ReturnRefOfCopyAction#Impl#Result# Performcxx . . $ testing/internal/ReturnRefOfCopyAction#Impl#Perform(645bc447c39635c6).(const ArgumentTuplecxx . . $ testing/internal/ReturnRefOfCopyAction#Impl#ArgumentTuple#&) override { return value_cxx . . $ testing/internal/ReturnRefOfCopyAction#Impl#value_.; } |
| 1221 | |
| 1222 | private: |
| 1223 | T value_cxx . . $ testing/internal/ReturnRefOfCopyAction#Impl#value_.; |
| 1224 | }; |
| 1225 | |
| 1226 | const T value_cxx . . $ testing/internal/ReturnRefOfCopyAction#value_.; |
| 1227 | }; |
| 1228 | |
| 1229 | // Implements the polymorphic ReturnRoundRobin(v) action, which can be |
| 1230 | // used in any function that returns the element_type of v. |
| 1231 | template <typename T> |
| 1232 | class ReturnRoundRobinActioncxx . . $ testing/internal/ReturnRoundRobinAction# { |
| 1233 | public: |
| 1234 | explicit ReturnRoundRobinActioncxx . . $ testing/internal/ReturnRoundRobinAction#`ReturnRoundRobinAction<T>`(d25536abaa7b6125).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<T> values) { |
| 1235 | GTEST_CHECK_cxx . . $ testing/internal/GTestLog#GTestLog(7512214fac1ed22).(!values.empty()) |
| 1236 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "ReturnRoundRobin requires at least one element."; |
| 1237 | state_cxx . . $ testing/internal/ReturnRoundRobinAction#state_.->values = stdcxx . . $ std/::movecxx . . $ std/move(88304b602929f6f4).(values); |
| 1238 | } |
| 1239 | |
| 1240 | template <typename... Args> |
| 1241 | T operatorcxx . . $ testing/internal/ReturnRoundRobinAction#`operator()`(f7b740c72afd1ae5).()(Args&&...) const { |
| 1242 | return state_cxx . . $ testing/internal/ReturnRoundRobinAction#state_.->Next(); |
| 1243 | } |
| 1244 | |
| 1245 | private: |
| 1246 | struct Statecxx . . $ testing/internal/ReturnRoundRobinAction#State# { |
| 1247 | T Nextcxx . . $ testing/internal/ReturnRoundRobinAction#State#Next(5f357b03ed472e5e).() { |
| 1248 | T ret_val = valuescxx . . $ testing/internal/ReturnRoundRobinAction#State#values.[icxx . . $ testing/internal/ReturnRoundRobinAction#State#i.++]; |
| 1249 | if (icxx . . $ testing/internal/ReturnRoundRobinAction#State#i. ==cxx . . $ testing/internal/`operator==`(67d151cd10fc7f68). valuescxx . . $ testing/internal/ReturnRoundRobinAction#State#values..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()) icxx . . $ testing/internal/ReturnRoundRobinAction#State#i. = 0; |
| 1250 | return ret_val; |
| 1251 | } |
| 1252 | |
| 1253 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<T> valuescxx . . $ testing/internal/ReturnRoundRobinAction#State#values.; |
| 1254 | size_t icxx . . $ testing/internal/ReturnRoundRobinAction#State#i. = 0; |
| 1255 | }; |
| 1256 | stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<Statecxx . . $ testing/internal/ReturnRoundRobinAction#State#> state_cxx . . $ testing/internal/ReturnRoundRobinAction#state_. = stdcxx . . $ std/::make_sharedcxx . . $ std/make_shared(ffca0f3977536948).<Statecxx . . $ testing/internal/ReturnRoundRobinAction#State#>(); |
| 1257 | }; |
| 1258 | |
| 1259 | // Implements the polymorphic DoDefault() action. |
| 1260 | class DoDefaultActioncxx . . $ testing/internal/DoDefaultAction# { |
| 1261 | public: |
| 1262 | // This template type conversion operator allows DoDefault() to be |
| 1263 | // used in any function. |
| 1264 | template <typename F> |
| 1265 | operatorcxx . . $ testing/internal/DoDefaultAction#`operator Action<type-parameter-0-0>`(25050c95e1e59d4). Actioncxx . . $ testing/Action#<F>() const { |
| 1266 | return Actioncxx . . $ testing/Action#<F>(); |
| 1267 | } // NOLINT |
| 1268 | }; |
| 1269 | |
| 1270 | // Implements the Assign action to set a given pointer referent to a |
| 1271 | // particular value. |
| 1272 | template <typename T1, typename T2> |
| 1273 | class AssignActioncxx . . $ testing/internal/AssignAction# { |
| 1274 | public: |
| 1275 | AssignActioncxx . . $ testing/internal/AssignAction#`AssignAction<T1, T2>`(c3afbfd628237275).(T1* ptr, T2 value) : ptr_cxx . . $ testing/internal/AssignAction#ptr_.(ptr), value_cxx . . $ testing/internal/AssignAction#value_.(value) {} |
| 1276 | |
| 1277 | template <typename Result, typename ArgumentTuple> |
| 1278 | void Performcxx . . $ testing/internal/AssignAction#Perform(ccc2a12414fb9418).(const ArgumentTuple& /* args */) const { |
| 1279 | *ptr_cxx . . $ testing/internal/AssignAction#ptr_. = value_cxx . . $ testing/internal/AssignAction#value_.; |
| 1280 | } |
| 1281 | |
| 1282 | private: |
| 1283 | T1* const ptr_cxx . . $ testing/internal/AssignAction#ptr_.; |
| 1284 | const T2 value_cxx . . $ testing/internal/AssignAction#value_.; |
| 1285 | }; |
| 1286 | |
| 1287 | #ifndef GTEST_OS_WINDOWS_MOBILE |
| 1288 | |
| 1289 | // Implements the SetErrnoAndReturn action to simulate return from |
| 1290 | // various system calls and libc functions. |
| 1291 | template <typename T> |
| 1292 | class SetErrnoAndReturnActioncxx . . $ testing/internal/SetErrnoAndReturnAction# { |
| 1293 | public: |
| 1294 | SetErrnoAndReturnActioncxx . . $ testing/internal/SetErrnoAndReturnAction#`SetErrnoAndReturnAction<T>`(cd440ec2f3ed967f).(int errno_value, T result) |
| 1295 | : errno_cxx . . $ testing/internal/SetErrnoAndReturnAction#errno_.(errno_value), result_cxx . . $ testing/internal/SetErrnoAndReturnAction#result_.(result) {} |
| 1296 | template <typename Result, typename ArgumentTuple> |
| 1297 | Result Performcxx . . $ testing/internal/SetErrnoAndReturnAction#Perform(746720068a1bc30f).(const ArgumentTuple& /* args */) const { |
| 1298 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = errno_cxx . . $ testing/internal/SetErrnoAndReturnAction#errno_.; |
| 1299 | return result_cxx . . $ testing/internal/SetErrnoAndReturnAction#result_.; |
| 1300 | } |
| 1301 | |
| 1302 | private: |
| 1303 | const int errno_cxx . . $ testing/internal/SetErrnoAndReturnAction#errno_.; |
| 1304 | const T result_cxx . . $ testing/internal/SetErrnoAndReturnAction#result_.; |
| 1305 | }; |
| 1306 | |
| 1307 | #endif // !GTEST_OS_WINDOWS_MOBILE |
| 1308 | |
| 1309 | // Implements the SetArgumentPointee<N>(x) action for any function |
| 1310 | // whose N-th argument (0-based) is a pointer to x's type. |
| 1311 | template <size_t N, typename A, typename = void> |
| 1312 | struct SetArgumentPointeeActioncxx . . $ testing/internal/SetArgumentPointeeAction# { |
| 1313 | A valuecxx . . $ testing/internal/SetArgumentPointeeAction#value.; |
| 1314 | |
| 1315 | template <typename... Args> |
| 1316 | void operatorcxx . . $ testing/internal/SetArgumentPointeeAction#`operator()`(93a3122f6acb4b7c).()(const Args&... args) const { |
| 1317 | *::stdcxx . . $ std/::getcxx . . $ std/get(6c68b51b79f97de2).<N>(stdcxx . . $ std/::tiecxx . . $ std/tie(988772b69a7ca893).(args...)) = valuecxx . . $ testing/internal/SetArgumentPointeeAction#value.; |
| 1318 | } |
| 1319 | }; |
| 1320 | |
| 1321 | // Implements the Invoke(object_ptr, &Class::Method) action. |
| 1322 | template <class Class, typename MethodPtr> |
| 1323 | struct InvokeMethodActioncxx . . $ testing/internal/InvokeMethodAction# { |
| 1324 | Class* const obj_ptrcxx . . $ testing/internal/InvokeMethodAction#obj_ptr.; |
| 1325 | const MethodPtr method_ptrcxx . . $ testing/internal/InvokeMethodAction#method_ptr.; |
| 1326 | |
| 1327 | template <typename... Args> |
| 1328 | auto operatorcxx . . $ testing/internal/InvokeMethodAction#`operator()`(1a923fb450632fd0).()(Args&&... args) const |
| 1329 | -> decltype((obj_ptrcxx . . $ testing/internal/InvokeMethodAction#obj_ptr.->*method_ptrcxx . . $ testing/internal/InvokeMethodAction#method_ptr.)(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Args>(args)...)) { |
| 1330 | return (obj_ptrcxx . . $ testing/internal/InvokeMethodAction#obj_ptr.->*method_ptrcxx . . $ testing/internal/InvokeMethodAction#method_ptr.)(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Args>(args)...); |
| 1331 | } |
| 1332 | }; |
| 1333 | |
| 1334 | // Implements the InvokeWithoutArgs(f) action. The template argument |
| 1335 | // FunctionImpl is the implementation type of f, which can be either a |
| 1336 | // function pointer or a functor. InvokeWithoutArgs(f) can be used as an |
| 1337 | // Action<F> as long as f's type is compatible with F. |
| 1338 | template <typename FunctionImpl> |
| 1339 | struct InvokeWithoutArgsActioncxx . . $ testing/internal/InvokeWithoutArgsAction# { |
| 1340 | FunctionImpl function_implcxx . . $ testing/internal/InvokeWithoutArgsAction#function_impl.; |
| 1341 | |
| 1342 | // Allows InvokeWithoutArgs(f) to be used as any action whose type is |
| 1343 | // compatible with f. |
| 1344 | template <typename... Args> |
| 1345 | auto operatorcxx . . $ testing/internal/InvokeWithoutArgsAction#`operator()`(a4190d2a7c4fc042).()(const Args&...) -> decltype(function_implcxx . . $ testing/internal/InvokeWithoutArgsAction#function_impl.()) { |
| 1346 | return function_implcxx . . $ testing/internal/InvokeWithoutArgsAction#function_impl.(); |
| 1347 | } |
| 1348 | }; |
| 1349 | |
| 1350 | // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action. |
| 1351 | template <class Class, typename MethodPtr> |
| 1352 | struct InvokeMethodWithoutArgsActioncxx . . $ testing/internal/InvokeMethodWithoutArgsAction# { |
| 1353 | Class* const obj_ptrcxx . . $ testing/internal/InvokeMethodWithoutArgsAction#obj_ptr.; |
| 1354 | const MethodPtr method_ptrcxx . . $ testing/internal/InvokeMethodWithoutArgsAction#method_ptr.; |
| 1355 | |
| 1356 | using ReturnTypecxx . . $ testing/internal/InvokeMethodWithoutArgsAction#ReturnType# = |
| 1357 | decltype((stdcxx . . $ std/::declval<Class*>()->*stdcxx . . $ std/::declval<MethodPtr>())()); |
| 1358 | |
| 1359 | template <typename... Args> |
| 1360 | ReturnTypecxx . . $ testing/internal/InvokeMethodWithoutArgsAction#ReturnType# operatorcxx . . $ testing/internal/InvokeMethodWithoutArgsAction#`operator()`(d0dbdbe77752ff23).()(const Args&...) const { |
| 1361 | return (obj_ptrcxx . . $ testing/internal/InvokeMethodWithoutArgsAction#obj_ptr.->*method_ptrcxx . . $ testing/internal/InvokeMethodWithoutArgsAction#method_ptr.)(); |
| 1362 | } |
| 1363 | }; |
| 1364 | |
| 1365 | // Implements the IgnoreResult(action) action. |
| 1366 | template <typename A> |
| 1367 | class IgnoreResultActioncxx . . $ testing/internal/IgnoreResultAction# { |
| 1368 | public: |
| 1369 | explicit IgnoreResultActioncxx . . $ testing/internal/IgnoreResultAction#`IgnoreResultAction<A>`(77d9f17553126ecb).(const A& action) : action_cxx . . $ testing/internal/IgnoreResultAction#action_.(action) {} |
| 1370 | |
| 1371 | template <typename F> |
| 1372 | operatorcxx . . $ testing/internal/IgnoreResultAction#`operator Action<type-parameter-1-0>`(d222aac85de04b2e). Actioncxx . . $ testing/Action#<F>() const { |
| 1373 | // Assert statement belongs here because this is the best place to verify |
| 1374 | // conditions on F. It produces the clearest error messages |
| 1375 | // in most compilers. |
| 1376 | // Impl really belongs in this scope as a local class but can't |
| 1377 | // because MSVC produces duplicate symbols in different translation units |
| 1378 | // in this case. Until MS fixes that bug we put Impl into the class scope |
| 1379 | // and put the typedef both here (for use in assert statement) and |
| 1380 | // in the Impl class. But both definitions must be the same. |
| 1381 | typedef typename internalcxx . . $ testing/internal/::Functioncxx . . $ testing/internal/Function#<F>::Result Resultcxx . . $ testing/internal/IgnoreResultAction#`operator Action<type-parameter-1-0>`(d222aac85de04b2e).Result#; |
| 1382 | |
| 1383 | // Asserts at compile time that F returns void. |
| 1384 | static_assert(stdcxx . . $ std/::is_void<Result>::value, "Result type should be void."); |
| 1385 | |
| 1386 | return Actioncxx . . $ testing/Action#<F>(new Implcxx . . $ testing/internal/IgnoreResultAction#Impl#<F>(action_cxx . . $ testing/internal/IgnoreResultAction#action_.)); |
| 1387 | } |
| 1388 | |
| 1389 | private: |
| 1390 | template <typename F> |
| 1391 | class Implcxx . . $ testing/internal/IgnoreResultAction#Impl# : public ActionInterfacecxx . . $ testing/ActionInterface#<F> { |
| 1392 | public: |
| 1393 | typedef typename internalcxx . . $ testing/internal/::Functioncxx . . $ testing/internal/Function#<F>::Result Resultcxx . . $ testing/internal/IgnoreResultAction#Impl#Result#; |
| 1394 | typedef typename internalcxx . . $ testing/internal/::Functioncxx . . $ testing/internal/Function#<F>::ArgumentTuple ArgumentTuplecxx . . $ testing/internal/IgnoreResultAction#Impl#ArgumentTuple#; |
| 1395 | |
| 1396 | explicit Implcxx . . $ testing/internal/IgnoreResultAction#Impl#`Impl<F>`(77d9f17553126ecb).(const A& action) : action_cxx . . $ testing/internal/IgnoreResultAction#Impl#action_.(action) {} |
| 1397 | |
| 1398 | void Performcxx . . $ testing/internal/IgnoreResultAction#Impl#Perform(3fdaf3cad9bbd462).(const ArgumentTuplecxx . . $ testing/internal/IgnoreResultAction#Impl#ArgumentTuple#& args) override { |
| 1399 | // Performs the action and ignores its result. |
| 1400 | action_cxx . . $ testing/internal/IgnoreResultAction#Impl#action_..Perform(args); |
| 1401 | } |
| 1402 | |
| 1403 | private: |
| 1404 | // Type OriginalFunction is the same as F except that its return |
| 1405 | // type is IgnoredValue. |
| 1406 | typedef |
| 1407 | typename internalcxx . . $ testing/internal/::Functioncxx . . $ testing/internal/Function#<F>::MakeResultIgnoredValue OriginalFunctioncxx . . $ testing/internal/IgnoreResultAction#Impl#OriginalFunction#; |
| 1408 | |
| 1409 | const Actioncxx . . $ testing/Action#<OriginalFunctioncxx . . $ testing/internal/IgnoreResultAction#Impl#OriginalFunction#> action_cxx . . $ testing/internal/IgnoreResultAction#Impl#action_.; |
| 1410 | }; |
| 1411 | |
| 1412 | const A action_cxx . . $ testing/internal/IgnoreResultAction#action_.; |
| 1413 | }; |
| 1414 | |
| 1415 | template <typename InnerAction, size_t... I> |
| 1416 | struct WithArgsActioncxx . . $ testing/internal/WithArgsAction# { |
| 1417 | InnerAction inner_actioncxx . . $ testing/internal/WithArgsAction#inner_action.; |
| 1418 | |
| 1419 | // The signature of the function as seen by the inner action, given an out |
| 1420 | // action with the given result and argument types. |
| 1421 | template <typename R, typename... Args> |
| 1422 | using InnerSignaturecxx . . $ testing/internal/WithArgsAction#InnerSignature# = |
| 1423 | R(typename stdcxx . . $ std/::tuple_elementcxx . . $ std/tuple_element#<I, std::tuple<Args...>>::type...); |
| 1424 | |
| 1425 | // Rather than a call operator, we must define conversion operators to |
| 1426 | // particular action types. This is necessary for embedded actions like |
| 1427 | // DoDefault(), which rely on an action conversion operators rather than |
| 1428 | // providing a call operator because even with a particular set of arguments |
| 1429 | // they don't have a fixed return type. |
| 1430 | |
| 1431 | template < |
| 1432 | typename R, typename... Args, |
| 1433 | typename stdcxx . . $ std/::enable_if< |
| 1434 | std::is_convertible<InnerAction, |
| 1435 | // Unfortunately we can't use the InnerSignature |
| 1436 | // alias here; MSVC complains about the I |
| 1437 | // parameter pack not being expanded (error C3520) |
| 1438 | // despite it being expanded in the type alias. |
| 1439 | // TupleElement is also an MSVC workaround. |
| 1440 | // See its definition for details. |
| 1441 | OnceAction<R(internal::TupleElement< |
| 1442 | I, std::tuple<Args...>>...)>>::value, |
| 1443 | int>::type = 0> |
| 1444 | operatorcxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9). OnceActioncxx . . $ testing/OnceAction#<R(Args...)>() && { // NOLINT |
| 1445 | struct OAcxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA# { |
| 1446 | OnceActioncxx . . $ testing/OnceAction#<InnerSignaturecxx . . $ testing/internal/WithArgsAction#InnerSignature#<R, Args...>> inner_actioncxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA#inner_action.; |
| 1447 | |
| 1448 | R operatorcxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA#`operator()`(9b07b8cbbd49eab4).()(Args&&... args) && { |
| 1449 | return stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(inner_actioncxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA#inner_action.) |
| 1450 | .Call(stdcxx . . $ std/::getcxx . . $ std/get(3745fbf9a4df67d6).<I>( |
| 1451 | stdcxx . . $ std/::forward_as_tuplecxx . . $ std/forward_as_tuple(cd19fb0d9524ec73).(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Args>(args)...))...); |
| 1452 | } |
| 1453 | }; |
| 1454 | |
| 1455 | return OAcxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA#{stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(inner_actioncxx . . $ testing/internal/WithArgsAction#inner_action.)}; |
| 1456 | } |
| 1457 | |
| 1458 | // As above, but in the case where we want to create a OnceAction from a const |
| 1459 | // WithArgsAction. This is fine as long as the inner action doesn't need to |
| 1460 | // move any of its state to create a OnceAction. |
| 1461 | template < |
| 1462 | typename R, typename... Args, |
| 1463 | typename stdcxx . . $ std/::enable_if< |
| 1464 | std::is_convertible<const InnerAction&, |
| 1465 | OnceAction<R(internal::TupleElement< |
| 1466 | I, std::tuple<Args...>>...)>>::value, |
| 1467 | int>::type = 0> |
| 1468 | operatorcxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(7d1fedb987dd4f6d). OnceActioncxx . . $ testing/OnceAction#<R(Args...)>() const& { // NOLINT |
| 1469 | struct OAcxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(7d1fedb987dd4f6d).OA# { |
| 1470 | OnceActioncxx . . $ testing/OnceAction#<InnerSignaturecxx . . $ testing/internal/WithArgsAction#InnerSignature#<R, Args...>> inner_actioncxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(7d1fedb987dd4f6d).OA#inner_action.; |
| 1471 | |
| 1472 | R operatorcxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(7d1fedb987dd4f6d).OA#`operator()`(9b07b8cbbd49eab4).()(Args&&... args) && { |
| 1473 | return stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(inner_actioncxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(7d1fedb987dd4f6d).OA#inner_action.) |
| 1474 | .Call(stdcxx . . $ std/::getcxx . . $ std/get(9a1b01079da03411).<I>( |
| 1475 | stdcxx . . $ std/::forward_as_tuplecxx . . $ std/forward_as_tuple(cd19fb0d9524ec73).(stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<Args>(args)...))...); |
| 1476 | } |
| 1477 | }; |
| 1478 | |
| 1479 | return OAcxx . . $ testing/internal/WithArgsAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(7d1fedb987dd4f6d).OA#{inner_actioncxx . . $ testing/internal/WithArgsAction#inner_action.}; |
| 1480 | } |
| 1481 | |
| 1482 | template < |
| 1483 | typename R, typename... Args, |
| 1484 | typename stdcxx . . $ std/::enable_if< |
| 1485 | std::is_convertible<const InnerAction&, |
| 1486 | // Unfortunately we can't use the InnerSignature |
| 1487 | // alias here; MSVC complains about the I |
| 1488 | // parameter pack not being expanded (error C3520) |
| 1489 | // despite it being expanded in the type alias. |
| 1490 | // TupleElement is also an MSVC workaround. |
| 1491 | // See its definition for details. |
| 1492 | Action<R(internal::TupleElement< |
| 1493 | I, std::tuple<Args...>>...)>>::value, |
| 1494 | int>::type = 0> |
| 1495 | operatorcxx . . $ testing/internal/WithArgsAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41). Actioncxx . . $ testing/Action#<R(Args...)>() const { // NOLINT |
| 1496 | Actioncxx . . $ testing/Action#<InnerSignaturecxx . . $ testing/internal/WithArgsAction#InnerSignature#<R, Args...>> converted(inner_actioncxx . . $ testing/internal/WithArgsAction#inner_action.); |
| 1497 | |
| 1498 | return [converted](Args&&... args) -> R { |
| 1499 | return converted.Perform(stdcxx . . $ std/::forward_as_tuplecxx . . $ std/forward_as_tuple(cd19fb0d9524ec73).( |
| 1500 | stdcxx . . $ std/::getcxx . . $ std/get(3745fbf9a4df67d6).<I>(stdcxx . . $ std/::forward_as_tuplecxx . . $ std/forward_as_tuple(cd19fb0d9524ec73).(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Args>(args)...))...)); |
| 1501 | }; |
| 1502 | } |
| 1503 | }; |
| 1504 | |
| 1505 | template <typename... Actions> |
| 1506 | class DoAllActioncxx . . $ testing/internal/DoAllAction#; |
| 1507 | |
| 1508 | // Base case: only a single action. |
| 1509 | template <typename FinalAction> |
| 1510 | class DoAllActioncxx . . $ testing/internal/DoAllAction#<FinalAction> { |
| 1511 | public: |
| 1512 | struct UserConstructorTagcxx . . $ testing/internal/DoAllAction#UserConstructorTag# {}; |
| 1513 | |
| 1514 | template <typename T> |
| 1515 | explicit DoAllActioncxx . . $ testing/internal/DoAllAction#`DoAllAction<FinalAction>`(499e6987613223a).(UserConstructorTagcxx . . $ testing/internal/DoAllAction#UserConstructorTag#, T&& action) |
| 1516 | : final_action_cxx . . $ testing/internal/DoAllAction#final_action_.(stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<T>(action)) {} |
| 1517 | |
| 1518 | // Rather than a call operator, we must define conversion operators to |
| 1519 | // particular action types. This is necessary for embedded actions like |
| 1520 | // DoDefault(), which rely on an action conversion operators rather than |
| 1521 | // providing a call operator because even with a particular set of arguments |
| 1522 | // they don't have a fixed return type. |
| 1523 | |
| 1524 | // We support conversion to OnceAction whenever the sub-action does. |
| 1525 | template <typename R, typename... Args, |
| 1526 | typename stdcxx . . $ std/::enable_if< |
| 1527 | std::is_convertible<FinalAction, OnceAction<R(Args...)>>::value, |
| 1528 | int>::type = 0> |
| 1529 | operatorcxx . . $ testing/internal/DoAllAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9). OnceActioncxx . . $ testing/OnceAction#<R(Args...)>() && { // NOLINT |
| 1530 | return stdcxx . . $ std/::movecxx . . $ std/move(88304b602929f6f4).(final_action_cxx . . $ testing/internal/DoAllAction#final_action_.); |
| 1531 | } |
| 1532 | |
| 1533 | // We also support conversion to OnceAction whenever the sub-action supports |
| 1534 | // conversion to Action (since any Action can also be a OnceAction). |
| 1535 | template < |
| 1536 | typename R, typename... Args, |
| 1537 | typename stdcxx . . $ std/::enable_if< |
| 1538 | conjunction< |
| 1539 | negation< |
| 1540 | std::is_convertible<FinalAction, OnceAction<R(Args...)>>>, |
| 1541 | std::is_convertible<FinalAction, Action<R(Args...)>>>::value, |
| 1542 | int>::type = 0> |
| 1543 | operatorcxx . . $ testing/internal/DoAllAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9). OnceActioncxx . . $ testing/OnceAction#<R(Args...)>() && { // NOLINT |
| 1544 | return Actioncxx . . $ testing/Action#<R(Args...)>(stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(final_action_cxx . . $ testing/internal/DoAllAction#final_action_.)); |
| 1545 | } |
| 1546 | |
| 1547 | // We support conversion to Action whenever the sub-action does. |
| 1548 | template < |
| 1549 | typename R, typename... Args, |
| 1550 | typename stdcxx . . $ std/::enable_if< |
| 1551 | std::is_convertible<const FinalAction&, Action<R(Args...)>>::value, |
| 1552 | int>::type = 0> |
| 1553 | operatorcxx . . $ testing/internal/DoAllAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41). Actioncxx . . $ testing/Action#<R(Args...)>() const { // NOLINT |
| 1554 | return final_action_cxx . . $ testing/internal/DoAllAction#final_action_.; |
| 1555 | } |
| 1556 | |
| 1557 | private: |
| 1558 | FinalAction final_action_cxx . . $ testing/internal/DoAllAction#final_action_.; |
| 1559 | }; |
| 1560 | |
| 1561 | // Recursive case: support N actions by calling the initial action and then |
| 1562 | // calling through to the base class containing N-1 actions. |
| 1563 | template <typename InitialAction, typename... OtherActions> |
| 1564 | class DoAllActioncxx . . $ testing/internal/DoAllAction#<InitialAction, OtherActions...> |
| 1565 | : private DoAllActioncxx . . $ testing/internal/DoAllAction#<OtherActions...> { |
| 1566 | private: |
| 1567 | using Basecxx . . $ testing/internal/DoAllAction#Base# = DoAllActioncxx . . $ testing/internal/DoAllAction#<OtherActions...>; |
| 1568 | |
| 1569 | // The type of reference that should be provided to an initial action for a |
| 1570 | // mocked function parameter of type T. |
| 1571 | // |
| 1572 | // There are two quirks here: |
| 1573 | // |
| 1574 | // * Unlike most forwarding functions, we pass scalars through by value. |
| 1575 | // This isn't strictly necessary because an lvalue reference would work |
| 1576 | // fine too and be consistent with other non-reference types, but it's |
| 1577 | // perhaps less surprising. |
| 1578 | // |
| 1579 | // For example if the mocked function has signature void(int), then it |
| 1580 | // might seem surprising for the user's initial action to need to be |
| 1581 | // convertible to Action<void(const int&)>. This is perhaps less |
| 1582 | // surprising for a non-scalar type where there may be a performance |
| 1583 | // impact, or it might even be impossible, to pass by value. |
| 1584 | // |
| 1585 | // * More surprisingly, `const T&` is often not a const reference type. |
| 1586 | // By the reference collapsing rules in C++17 [dcl.ref]/6, if T refers to |
| 1587 | // U& or U&& for some non-scalar type U, then InitialActionArgType<T> is |
| 1588 | // U&. In other words, we may hand over a non-const reference. |
| 1589 | // |
| 1590 | // So for example, given some non-scalar type Obj we have the following |
| 1591 | // mappings: |
| 1592 | // |
| 1593 | // T InitialActionArgType<T> |
| 1594 | // ------- ----------------------- |
| 1595 | // Obj const Obj& |
| 1596 | // Obj& Obj& |
| 1597 | // Obj&& Obj& |
| 1598 | // const Obj const Obj& |
| 1599 | // const Obj& const Obj& |
| 1600 | // const Obj&& const Obj& |
| 1601 | // |
| 1602 | // In other words, the initial actions get a mutable view of an non-scalar |
| 1603 | // argument if and only if the mock function itself accepts a non-const |
| 1604 | // reference type. They are never given an rvalue reference to an |
| 1605 | // non-scalar type. |
| 1606 | // |
| 1607 | // This situation makes sense if you imagine use with a matcher that is |
| 1608 | // designed to write through a reference. For example, if the caller wants |
| 1609 | // to fill in a reference argument and then return a canned value: |
| 1610 | // |
| 1611 | // EXPECT_CALL(mock, Call) |
| 1612 | // .WillOnce(DoAll(SetArgReferee<0>(17), Return(19))); |
| 1613 | // |
| 1614 | template <typename T> |
| 1615 | using InitialActionArgTypecxx . . $ testing/internal/DoAllAction#InitialActionArgType# = |
| 1616 | typename stdcxx . . $ std/::conditional<std::is_scalar<T>::value, T, const T&>::type; |
| 1617 | |
| 1618 | public: |
| 1619 | struct UserConstructorTagcxx . . $ testing/internal/DoAllAction#UserConstructorTag# {}; |
| 1620 | |
| 1621 | template <typename T, typename... U> |
| 1622 | explicit DoAllActioncxx . . $ testing/internal/DoAllAction#`DoAllAction<InitialAction, OtherActions...>`(5dc40d1f6469e4a8).(UserConstructorTagcxx . . $ testing/internal/DoAllAction#UserConstructorTag#, T&& initial_action, |
| 1623 | U&&... other_actions) |
| 1624 | : Basecxx . . $ testing/internal/DoAllAction#Base#({}, stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<U>(other_actions)...), |
| 1625 | initial_action_cxx . . $ testing/internal/DoAllAction#initial_action_.(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<T>(initial_action)) {} |
| 1626 | |
| 1627 | // We support conversion to OnceAction whenever both the initial action and |
| 1628 | // the rest support conversion to OnceAction. |
| 1629 | template < |
| 1630 | typename R, typename... Args, |
| 1631 | typename stdcxx . . $ std/::enable_if< |
| 1632 | conjunction<std::is_convertible< |
| 1633 | InitialAction, |
| 1634 | OnceAction<void(InitialActionArgType<Args>...)>>, |
| 1635 | std::is_convertible<Base, OnceAction<R(Args...)>>>::value, |
| 1636 | int>::type = 0> |
| 1637 | operatorcxx . . $ testing/internal/DoAllAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9). OnceActioncxx . . $ testing/OnceAction#<R(Args...)>() && { // NOLINT |
| 1638 | // Return an action that first calls the initial action with arguments |
| 1639 | // filtered through InitialActionArgType, then forwards arguments directly |
| 1640 | // to the base class to deal with the remaining actions. |
| 1641 | struct OAcxx . . $ testing/internal/DoAllAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA# { |
| 1642 | OnceActioncxx . . $ testing/OnceAction#<void(InitialActionArgTypecxx . . $ testing/internal/DoAllAction#InitialActionArgType#<Args>...)> initial_actioncxx . . $ testing/internal/DoAllAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA#initial_action.; |
| 1643 | OnceActioncxx . . $ testing/OnceAction#<R(Args...)> remaining_actionscxx . . $ testing/internal/DoAllAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA#remaining_actions.; |
| 1644 | |
| 1645 | R operatorcxx . . $ testing/internal/DoAllAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA#`operator()`(18444bf2b7dd2261).()(Args... args) && { |
| 1646 | stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(initial_actioncxx . . $ testing/internal/DoAllAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA#initial_action.) |
| 1647 | .Call(static_cast<InitialActionArgTypecxx . . $ testing/internal/DoAllAction#InitialActionArgType#<Args>>(args)...); |
| 1648 | |
| 1649 | return stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(remaining_actionscxx . . $ testing/internal/DoAllAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA#remaining_actions.).Call(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Args>(args)...); |
| 1650 | } |
| 1651 | }; |
| 1652 | |
| 1653 | return OAcxx . . $ testing/internal/DoAllAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9).OA#{ |
| 1654 | stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(initial_action_cxx . . $ testing/internal/DoAllAction#initial_action_.), |
| 1655 | stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(static_cast<Basecxx . . $ testing/internal/DoAllAction#Base#&>(*this)), |
| 1656 | }; |
| 1657 | } |
| 1658 | |
| 1659 | // We also support conversion to OnceAction whenever the initial action |
| 1660 | // supports conversion to Action (since any Action can also be a OnceAction). |
| 1661 | // |
| 1662 | // The remaining sub-actions must also be compatible, but we don't need to |
| 1663 | // special case them because the base class deals with them. |
| 1664 | template < |
| 1665 | typename R, typename... Args, |
| 1666 | typename stdcxx . . $ std/::enable_if< |
| 1667 | conjunction< |
| 1668 | negation<std::is_convertible< |
| 1669 | InitialAction, |
| 1670 | OnceAction<void(InitialActionArgType<Args>...)>>>, |
| 1671 | std::is_convertible<InitialAction, |
| 1672 | Action<void(InitialActionArgType<Args>...)>>, |
| 1673 | std::is_convertible<Base, OnceAction<R(Args...)>>>::value, |
| 1674 | int>::type = 0> |
| 1675 | operatorcxx . . $ testing/internal/DoAllAction#`operator OnceAction<type-parameter-1-0 (type-parameter-1-1...)>`(be8b9c5f5bb6e9). OnceActioncxx . . $ testing/OnceAction#<R(Args...)>() && { // NOLINT |
| 1676 | return DoAll( |
| 1677 | Actioncxx . . $ testing/Action#<void(InitialActionArgTypecxx . . $ testing/internal/DoAllAction#InitialActionArgType#<Args>...)>(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(initial_action_cxx . . $ testing/internal/DoAllAction#initial_action_.)), |
| 1678 | stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(static_cast<Basecxx . . $ testing/internal/DoAllAction#Base#&>(*this))); |
| 1679 | } |
| 1680 | |
| 1681 | // We support conversion to Action whenever both the initial action and the |
| 1682 | // rest support conversion to Action. |
| 1683 | template < |
| 1684 | typename R, typename... Args, |
| 1685 | typename stdcxx . . $ std/::enable_if< |
| 1686 | conjunction< |
| 1687 | std::is_convertible<const InitialAction&, |
| 1688 | Action<void(InitialActionArgType<Args>...)>>, |
| 1689 | std::is_convertible<const Base&, Action<R(Args...)>>>::value, |
| 1690 | int>::type = 0> |
| 1691 | operatorcxx . . $ testing/internal/DoAllAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41). Actioncxx . . $ testing/Action#<R(Args...)>() const { // NOLINT |
| 1692 | // Return an action that first calls the initial action with arguments |
| 1693 | // filtered through InitialActionArgType, then forwards arguments directly |
| 1694 | // to the base class to deal with the remaining actions. |
| 1695 | struct OAcxx . . $ testing/internal/DoAllAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41).OA# { |
| 1696 | Actioncxx . . $ testing/Action#<void(InitialActionArgTypecxx . . $ testing/internal/DoAllAction#InitialActionArgType#<Args>...)> initial_actioncxx . . $ testing/internal/DoAllAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41).OA#initial_action.; |
| 1697 | Actioncxx . . $ testing/Action#<R(Args...)> remaining_actionscxx . . $ testing/internal/DoAllAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41).OA#remaining_actions.; |
| 1698 | |
| 1699 | R operatorcxx . . $ testing/internal/DoAllAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41).OA#`operator()`(230a9f7307c6e9a0).()(Args... args) const { |
| 1700 | initial_actioncxx . . $ testing/internal/DoAllAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41).OA#initial_action..Perform(stdcxx . . $ std/::forward_as_tuplecxx . . $ std/forward_as_tuple(cd19fb0d9524ec73).( |
| 1701 | static_cast<InitialActionArgTypecxx . . $ testing/internal/DoAllAction#InitialActionArgType#<Args>>(args)...)); |
| 1702 | |
| 1703 | return remaining_actionscxx . . $ testing/internal/DoAllAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41).OA#remaining_actions..Perform( |
| 1704 | stdcxx . . $ std/::forward_as_tuplecxx . . $ std/forward_as_tuple(cd19fb0d9524ec73).(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Args>(args)...)); |
| 1705 | } |
| 1706 | }; |
| 1707 | |
| 1708 | return OAcxx . . $ testing/internal/DoAllAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41).OA#{ |
| 1709 | initial_action_cxx . . $ testing/internal/DoAllAction#initial_action_., |
| 1710 | static_cast<const Basecxx . . $ testing/internal/DoAllAction#Base#&>(*this), |
| 1711 | }; |
| 1712 | } |
| 1713 | |
| 1714 | private: |
| 1715 | InitialAction initial_action_cxx . . $ testing/internal/DoAllAction#initial_action_.; |
| 1716 | }; |
| 1717 | |
| 1718 | template <typename T, typename... Params> |
| 1719 | struct ReturnNewActioncxx . . $ testing/internal/ReturnNewAction# { |
| 1720 | T* operatorcxx . . $ testing/internal/ReturnNewAction#`operator()`(5a2a78a048fb49a8).()() const { |
| 1721 | return internalcxx . . $ testing/internal/::Applycxx . . $ testing/internal/Apply(6593b434a6c264f).( |
| 1722 | [](const Params&... unpacked_params) { |
| 1723 | return new T(unpacked_params...); |
| 1724 | }, |
| 1725 | paramscxx . . $ testing/internal/ReturnNewAction#params.); |
| 1726 | } |
| 1727 | stdcxx . . $ std/::tuplecxx . . $ std/tuple#<Params...> paramscxx . . $ testing/internal/ReturnNewAction#params.; |
| 1728 | }; |
| 1729 | |
| 1730 | template <size_t k> |
| 1731 | struct ReturnArgActioncxx . . $ testing/internal/ReturnArgAction# { |
| 1732 | template <typename... Args, |
| 1733 | typename = typename stdcxx . . $ std/::enable_if<(k < sizeof...(Args))>::type> |
| 1734 | auto operatorcxx . . $ testing/internal/ReturnArgAction#`operator()`(83f12ac124ce84b).()(Args&&... args) const -> decltype(stdcxx . . $ std/::getcxx . . $ std/get(5aabc72a970aa7ce).<k>( |
| 1735 | stdcxx . . $ std/::forward_as_tuplecxx . . $ std/forward_as_tuple(cd19fb0d9524ec73).(stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<Args>(args)...))) { |
| 1736 | return stdcxx . . $ std/::getcxx . . $ std/get(317e1dd7c6ae599).<k>(stdcxx . . $ std/::forward_as_tuplecxx . . $ std/forward_as_tuple(cd19fb0d9524ec73).(stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<Args>(args)...)); |
| 1737 | } |
| 1738 | }; |
| 1739 | |
| 1740 | template <size_t k, typename Ptr> |
| 1741 | struct SaveArgActioncxx . . $ testing/internal/SaveArgAction# { |
| 1742 | Ptr pointercxx . . $ testing/internal/SaveArgAction#pointer.; |
| 1743 | |
| 1744 | template <typename... Args> |
| 1745 | void operatorcxx . . $ testing/internal/SaveArgAction#`operator()`(93a3122f6acb4b7c).()(const Args&... args) const { |
| 1746 | *pointercxx . . $ testing/internal/SaveArgAction#pointer. = stdcxx . . $ std/::getcxx . . $ std/get(9a1b01079da03411).<k>(stdcxx . . $ std/::tiecxx . . $ std/tie(988772b69a7ca893).(args...)); |
| 1747 | } |
| 1748 | }; |
| 1749 | |
| 1750 | template <size_t k, typename Ptr> |
| 1751 | struct SaveArgByMoveActioncxx . . $ testing/internal/SaveArgByMoveAction# { |
| 1752 | Ptr pointercxx . . $ testing/internal/SaveArgByMoveAction#pointer.; |
| 1753 | |
| 1754 | template <typename... Args> |
| 1755 | void operatorcxx . . $ testing/internal/SaveArgByMoveAction#`operator()`(26675d48c7f57970).()(Args&&... args) const { |
| 1756 | *pointercxx . . $ testing/internal/SaveArgByMoveAction#pointer. = stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(stdcxx . . $ std/::getcxx . . $ std/get(607352554f49d4b5).<k>(stdcxx . . $ std/::tiecxx . . $ std/tie(988772b69a7ca893).(args...))); |
| 1757 | } |
| 1758 | }; |
| 1759 | |
| 1760 | template <size_t k, typename Ptr> |
| 1761 | struct SaveArgPointeeActioncxx . . $ testing/internal/SaveArgPointeeAction# { |
| 1762 | Ptr pointercxx . . $ testing/internal/SaveArgPointeeAction#pointer.; |
| 1763 | |
| 1764 | template <typename... Args> |
| 1765 | void operatorcxx . . $ testing/internal/SaveArgPointeeAction#`operator()`(93a3122f6acb4b7c).()(const Args&... args) const { |
| 1766 | *pointercxx . . $ testing/internal/SaveArgPointeeAction#pointer. = *stdcxx . . $ std/::getcxx . . $ std/get(5aabc72a970aa7ce).<k>(stdcxx . . $ std/::tiecxx . . $ std/tie(988772b69a7ca893).(args...)); |
| 1767 | } |
| 1768 | }; |
| 1769 | |
| 1770 | template <size_t k, typename T> |
| 1771 | struct SetArgRefereeActioncxx . . $ testing/internal/SetArgRefereeAction# { |
| 1772 | T valuecxx . . $ testing/internal/SetArgRefereeAction#value.; |
| 1773 | |
| 1774 | template <typename... Args> |
| 1775 | void operatorcxx . . $ testing/internal/SetArgRefereeAction#`operator()`(26675d48c7f57970).()(Args&&... args) const { |
| 1776 | using argk_typecxx . . $ testing/internal/SetArgRefereeAction#`operator()`(26675d48c7f57970).argk_type# = |
| 1777 | typename ::stdcxx . . $ std/::tuple_elementcxx . . $ std/tuple_element#<k, std::tuple<Args...>>::type; |
| 1778 | static_assert(stdcxx . . $ std/::is_lvalue_reference<argk_type>::value, |
| 1779 | "Argument must be a reference type."); |
| 1780 | stdcxx . . $ std/::getcxx . . $ std/get(9a1b01079da03411).<k>(stdcxx . . $ std/::tiecxx . . $ std/tie(988772b69a7ca893).(args...)) = valuecxx . . $ testing/internal/SetArgRefereeAction#value.; |
| 1781 | } |
| 1782 | }; |
| 1783 | |
| 1784 | template <size_t k, typename I1, typename I2> |
| 1785 | struct SetArrayArgumentActioncxx . . $ testing/internal/SetArrayArgumentAction# { |
| 1786 | I1 firstcxx . . $ testing/internal/SetArrayArgumentAction#first.; |
| 1787 | I2 lastcxx . . $ testing/internal/SetArrayArgumentAction#last.; |
| 1788 | |
| 1789 | template <typename... Args> |
| 1790 | void operatorcxx . . $ testing/internal/SetArrayArgumentAction#`operator()`(93a3122f6acb4b7c).()(const Args&... args) const { |
| 1791 | auto value = stdcxx . . $ std/::getcxx . . $ std/get(85b7410325da9aa2).<k>(stdcxx . . $ std/::tiecxx . . $ std/tie(988772b69a7ca893).(args...)); |
| 1792 | for (auto it = firstcxx . . $ testing/internal/SetArrayArgumentAction#first.; it !=cxx . . $ testing/internal/`operator!=`(67d151cd10fc7f68). lastcxx . . $ testing/internal/SetArrayArgumentAction#last.; ++it, (void)++value) { |
| 1793 | *value = *it; |
| 1794 | } |
| 1795 | } |
| 1796 | }; |
| 1797 | |
| 1798 | template <size_t k> |
| 1799 | struct DeleteArgActioncxx . . $ testing/internal/DeleteArgAction# { |
| 1800 | template <typename... Args> |
| 1801 | void operatorcxx . . $ testing/internal/DeleteArgAction#`operator()`(93a3122f6acb4b7c).()(const Args&... args) const { |
| 1802 | delete stdcxx . . $ std/::getcxx . . $ std/get(5aabc72a970aa7ce).<k>(stdcxx . . $ std/::tiecxx . . $ std/tie(988772b69a7ca893).(args...)); |
| 1803 | } |
| 1804 | }; |
| 1805 | |
| 1806 | template <typename Ptr> |
| 1807 | struct ReturnPointeeActioncxx . . $ testing/internal/ReturnPointeeAction# { |
| 1808 | Ptr pointercxx . . $ testing/internal/ReturnPointeeAction#pointer.; |
| 1809 | template <typename... Args> |
| 1810 | auto operatorcxx . . $ testing/internal/ReturnPointeeAction#`operator()`(cfac763b69a148bc).()(const Args&...) const -> decltype(*pointercxx . . $ testing/internal/ReturnPointeeAction#pointer.) { |
| 1811 | return *pointercxx . . $ testing/internal/ReturnPointeeAction#pointer.; |
| 1812 | } |
| 1813 | }; |
| 1814 | |
| 1815 | #if GTEST_HAS_EXCEPTIONScxx . . $ `googletest/include/gtest/internal/gtest-port.h:483:9`! |
| 1816 | template <typename T> |
| 1817 | struct ThrowActioncxx . . $ testing/internal/ThrowAction# { |
| 1818 | T exceptioncxx . . $ testing/internal/ThrowAction#exception.; |
| 1819 | // We use a conversion operator to adapt to any return type. |
| 1820 | template <typename R, typename... Args> |
| 1821 | operatorcxx . . $ testing/internal/ThrowAction#`operator Action<type-parameter-1-0 (type-parameter-1-1...)>`(17d5a4fe4ac41c41). Actioncxx . . $ testing/Action#<R(Args...)>() const { // NOLINT |
| 1822 | T copy = exceptioncxx . . $ testing/internal/ThrowAction#exception.; |
| 1823 | return [copy](Args...) -> R { throw copy; }; |
| 1824 | } |
| 1825 | }; |
| 1826 | struct RethrowActioncxx . . $ testing/internal/RethrowAction# { |
| 1827 | stdcxx . . $ std/::exception_ptr exceptioncxx . . $ testing/internal/RethrowAction#exception.; |
| 1828 | template <typename R, typename... Args> |
| 1829 | operatorcxx . . $ testing/internal/RethrowAction#`operator Action<type-parameter-0-0 (type-parameter-0-1...)>`(61da1680e658f93f). Actioncxx . . $ testing/Action#<R(Args...)>() const { // NOLINT |
| 1830 | return [ex = exceptioncxx . . $ testing/internal/RethrowAction#exception.](Args...) -> R { stdcxx . . $ std/::rethrow_exception(ex); }; |
| 1831 | } |
| 1832 | }; |
| 1833 | #endif // GTEST_HAS_EXCEPTIONS |
| 1834 | |
| 1835 | } // namespace internal |
| 1836 | |
| 1837 | // An Unused object can be implicitly constructed from ANY value. |
| 1838 | // This is handy when defining actions that ignore some or all of the |
| 1839 | // mock function arguments. For example, given |
| 1840 | // |
| 1841 | // MOCK_METHOD3(Foo, double(const string& label, double x, double y)); |
| 1842 | // MOCK_METHOD3(Bar, double(int index, double x, double y)); |
| 1843 | // |
| 1844 | // instead of |
| 1845 | // |
| 1846 | // double DistanceToOriginWithLabel(const string& label, double x, double y) { |
| 1847 | // return sqrt(x*x + y*y); |
| 1848 | // } |
| 1849 | // double DistanceToOriginWithIndex(int index, double x, double y) { |
| 1850 | // return sqrt(x*x + y*y); |
| 1851 | // } |
| 1852 | // ... |
| 1853 | // EXPECT_CALL(mock, Foo("abc", _, _)) |
| 1854 | // .WillOnce(Invoke(DistanceToOriginWithLabel)); |
| 1855 | // EXPECT_CALL(mock, Bar(5, _, _)) |
| 1856 | // .WillOnce(Invoke(DistanceToOriginWithIndex)); |
| 1857 | // |
| 1858 | // you could write |
| 1859 | // |
| 1860 | // // We can declare any uninteresting argument as Unused. |
| 1861 | // double DistanceToOrigin(Unused, double x, double y) { |
| 1862 | // return sqrt(x*x + y*y); |
| 1863 | // } |
| 1864 | // ... |
| 1865 | // EXPECT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin)); |
| 1866 | // EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin)); |
| 1867 | typedef internalcxx . . $ testing/internal/::IgnoredValuecxx . . $ testing/internal/IgnoredValue# Unusedcxx . . $ testing/Unused#; |
| 1868 | |
| 1869 | // Creates an action that does actions a1, a2, ..., sequentially in |
| 1870 | // each invocation. All but the last action will have a readonly view of the |
| 1871 | // arguments. |
| 1872 | template <typename... Action> |
| 1873 | internalcxx . . $ testing/internal/::DoAllActioncxx . . $ testing/internal/DoAllAction#<typename stdcxx . . $ std/::decay<Action>::type...> DoAllcxx . . $ testing/DoAll(cda9028f454db963).( |
| 1874 | Action&&... action) { |
| 1875 | return internalcxx . . $ testing/internal/::DoAllActioncxx . . $ testing/internal/DoAllAction#<typename stdcxx . . $ std/::decay<Action>::type...>( |
| 1876 | {}, stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<Action>(action)...); |
| 1877 | } |
| 1878 | |
| 1879 | // WithArg<k>(an_action) creates an action that passes the k-th |
| 1880 | // (0-based) argument of the mock function to an_action and performs |
| 1881 | // it. It adapts an action accepting one argument to one that accepts |
| 1882 | // multiple arguments. For convenience, we also provide |
| 1883 | // WithArgs<k>(an_action) (defined below) as a synonym. |
| 1884 | template <size_t k, typename InnerAction> |
| 1885 | internalcxx . . $ testing/internal/::WithArgsActioncxx . . $ testing/internal/WithArgsAction#<typename stdcxx . . $ std/::decay<InnerAction>::type, k> WithArgcxx . . $ testing/WithArg(5c18270db8901b86).( |
| 1886 | InnerAction&& action) { |
| 1887 | return {stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<InnerAction>(action)}; |
| 1888 | } |
| 1889 | |
| 1890 | // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes |
| 1891 | // the selected arguments of the mock function to an_action and |
| 1892 | // performs it. It serves as an adaptor between actions with |
| 1893 | // different argument lists. |
| 1894 | template <size_t k, size_t... ks, typename InnerAction> |
| 1895 | internalcxx . . $ testing/internal/::WithArgsActioncxx . . $ testing/internal/WithArgsAction#<typename stdcxx . . $ std/::decay<InnerAction>::type, k, ks...> |
| 1896 | WithArgscxx . . $ testing/WithArgs(7a3d97c379f68211).(InnerAction&& action) { |
| 1897 | return {stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<InnerAction>(action)}; |
| 1898 | } |
| 1899 | |
| 1900 | // WithoutArgs(inner_action) can be used in a mock function with a |
| 1901 | // non-empty argument list to perform inner_action, which takes no |
| 1902 | // argument. In other words, it adapts an action accepting no |
| 1903 | // argument to one that accepts (and ignores) arguments. |
| 1904 | template <typename InnerAction> |
| 1905 | internalcxx . . $ testing/internal/::WithArgsActioncxx . . $ testing/internal/WithArgsAction#<typename stdcxx . . $ std/::decay<InnerAction>::type> WithoutArgscxx . . $ testing/WithoutArgs(acac6b1869ca5bc4).( |
| 1906 | InnerAction&& action) { |
| 1907 | return {stdcxx . . $ std/::forwardcxx . . $ std/forward(2d11db7e2d3d358e).<InnerAction>(action)}; |
| 1908 | } |
| 1909 | |
| 1910 | // Creates an action that returns a value. |
| 1911 | // |
| 1912 | // The returned type can be used with a mock function returning a non-void, |
| 1913 | // non-reference type U as follows: |
| 1914 | // |
| 1915 | // * If R is convertible to U and U is move-constructible, then the action can |
| 1916 | // be used with WillOnce. |
| 1917 | // |
| 1918 | // * If const R& is convertible to U and U is copy-constructible, then the |
| 1919 | // action can be used with both WillOnce and WillRepeatedly. |
| 1920 | // |
| 1921 | // The mock expectation contains the R value from which the U return value is |
| 1922 | // constructed (a move/copy of the argument to Return). This means that the R |
| 1923 | // value will survive at least until the mock object's expectations are cleared |
| 1924 | // or the mock object is destroyed, meaning that U can safely be a |
| 1925 | // reference-like type such as std::string_view: |
| 1926 | // |
| 1927 | // // The mock function returns a view of a copy of the string fed to |
| 1928 | // // Return. The view is valid even after the action is performed. |
| 1929 | // MockFunction<std::string_view()> mock; |
| 1930 | // EXPECT_CALL(mock, Call).WillOnce(Return(std::string("taco"))); |
| 1931 | // const std::string_view result = mock.AsStdFunction()(); |
| 1932 | // EXPECT_EQ("taco", result); |
| 1933 | // |
| 1934 | template <typename R> |
| 1935 | internalcxx . . $ testing/internal/::ReturnActioncxx . . $ testing/internal/ReturnAction#<R> Returncxx . . $ testing/Return(2c8734c0195ba6dd).(R value) { |
| 1936 | return internalcxx . . $ testing/internal/::ReturnActioncxx . . $ testing/internal/ReturnAction#<R>(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(value)); |
| 1937 | } |
| 1938 | |
| 1939 | // Creates an action that returns NULL. |
| 1940 | inline PolymorphicActioncxx . . $ testing/PolymorphicAction#<internalcxx . . $ testing/internal/::ReturnNullActioncxx . . $ testing/internal/ReturnNullAction#> ReturnNullcxx . . $ testing/ReturnNull(322109c25b24d10f).() { |
| 1941 | return MakePolymorphicActioncxx . . $ testing/MakePolymorphicAction(712d411a1ea0c3b).(internalcxx . . $ testing/internal/::ReturnNullActioncxx . . $ testing/internal/ReturnNullAction#()); |
| 1942 | } |
| 1943 | |
| 1944 | // Creates an action that returns from a void function. |
| 1945 | inline PolymorphicActioncxx . . $ testing/PolymorphicAction#<internalcxx . . $ testing/internal/::ReturnVoidActioncxx . . $ testing/internal/ReturnVoidAction#> Returncxx . . $ testing/Return(337b53692da17877).() { |
| 1946 | return MakePolymorphicActioncxx . . $ testing/MakePolymorphicAction(712d411a1ea0c3b).(internalcxx . . $ testing/internal/::ReturnVoidActioncxx . . $ testing/internal/ReturnVoidAction#()); |
| 1947 | } |
| 1948 | |
| 1949 | // Creates an action that returns the reference to a variable. |
| 1950 | template <typename R> |
| 1951 | inline internalcxx . . $ testing/internal/::ReturnRefActioncxx . . $ testing/internal/ReturnRefAction#<R> ReturnRefcxx . . $ testing/ReturnRef(4e72f4ed443cfa33).(R& x) { // NOLINT |
| 1952 | return internalcxx . . $ testing/internal/::ReturnRefActioncxx . . $ testing/internal/ReturnRefAction#<R>(x); |
| 1953 | } |
| 1954 | |
| 1955 | // Prevent using ReturnRef on reference to temporary. |
| 1956 | template <typename R, R* = nullptr> |
| 1957 | internalcxx . . $ testing/internal/::ReturnRefActioncxx . . $ testing/internal/ReturnRefAction#<R> ReturnRefcxx . . $ testing/ReturnRef(57ec228261fb6d24).(R&&) = delete; |
| 1958 | |
| 1959 | // Creates an action that returns the reference to a copy of the |
| 1960 | // argument. The copy is created when the action is constructed and |
| 1961 | // lives as long as the action. |
| 1962 | template <typename R> |
| 1963 | inline internalcxx . . $ testing/internal/::ReturnRefOfCopyActioncxx . . $ testing/internal/ReturnRefOfCopyAction#<R> ReturnRefOfCopycxx . . $ testing/ReturnRefOfCopy(d42d086563c75bc5).(const R& x) { |
| 1964 | return internalcxx . . $ testing/internal/::ReturnRefOfCopyActioncxx . . $ testing/internal/ReturnRefOfCopyAction#<R>(x); |
| 1965 | } |
| 1966 | |
| 1967 | // DEPRECATED: use Return(x) directly with WillOnce. |
| 1968 | // |
| 1969 | // Modifies the parent action (a Return() action) to perform a move of the |
| 1970 | // argument instead of a copy. |
| 1971 | // Return(ByMove()) actions can only be executed once and will assert this |
| 1972 | // invariant. |
| 1973 | template <typename R> |
| 1974 | internalcxx . . $ testing/internal/::ByMoveWrappercxx . . $ testing/internal/ByMoveWrapper#<R> ByMovecxx . . $ testing/ByMove(ec383bff5ad5e803).(R x) { |
| 1975 | return internalcxx . . $ testing/internal/::ByMoveWrappercxx . . $ testing/internal/ByMoveWrapper#<R>(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(x)); |
| 1976 | } |
| 1977 | |
| 1978 | // Creates an action that returns an element of `vals`. Calling this action will |
| 1979 | // repeatedly return the next value from `vals` until it reaches the end and |
| 1980 | // will restart from the beginning. |
| 1981 | template <typename T> |
| 1982 | internalcxx . . $ testing/internal/::ReturnRoundRobinActioncxx . . $ testing/internal/ReturnRoundRobinAction#<T> ReturnRoundRobincxx . . $ testing/ReturnRoundRobin(249f3c9b2e7f0654).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<T> vals) { |
| 1983 | return internalcxx . . $ testing/internal/::ReturnRoundRobinActioncxx . . $ testing/internal/ReturnRoundRobinAction#<T>(stdcxx . . $ std/::movecxx . . $ std/move(88304b602929f6f4).(vals)); |
| 1984 | } |
| 1985 | |
| 1986 | // Creates an action that returns an element of `vals`. Calling this action will |
| 1987 | // repeatedly return the next value from `vals` until it reaches the end and |
| 1988 | // will restart from the beginning. |
| 1989 | template <typename T> |
| 1990 | internalcxx . . $ testing/internal/::ReturnRoundRobinActioncxx . . $ testing/internal/ReturnRoundRobinAction#<T> ReturnRoundRobincxx . . $ testing/ReturnRoundRobin(c9b3b86188ac6207).( |
| 1991 | stdcxx . . $ std/::initializer_listcxx . . $ std/initializer_list#<T> vals) { |
| 1992 | return internalcxx . . $ testing/internal/::ReturnRoundRobinActioncxx . . $ testing/internal/ReturnRoundRobinAction#<T>(stdcxx . . $ std/::vectorcxx . . $ std/vector#<T>(vals)); |
| 1993 | } |
| 1994 | |
| 1995 | // Creates an action that does the default action for the give mock function. |
| 1996 | inline internalcxx . . $ testing/internal/::DoDefaultActioncxx . . $ testing/internal/DoDefaultAction# DoDefaultcxx . . $ testing/DoDefault(c974be13ff1d6259).() { |
| 1997 | return internalcxx . . $ testing/internal/::DoDefaultActioncxx . . $ testing/internal/DoDefaultAction#(); |
| 1998 | } |
| 1999 | |
| 2000 | // Creates an action that sets the variable pointed by the N-th |
| 2001 | // (0-based) function argument to 'value'. |
| 2002 | template <size_t N, typename T> |
| 2003 | internalcxx . . $ testing/internal/::SetArgumentPointeeActioncxx . . $ testing/internal/SetArgumentPointeeAction#<N, T> SetArgPointeecxx . . $ testing/SetArgPointee(1d254da588ef4d10).(T value) { |
| 2004 | return {stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(value)}; |
| 2005 | } |
| 2006 | |
| 2007 | // The following version is DEPRECATED. |
| 2008 | template <size_t N, typename T> |
| 2009 | internalcxx . . $ testing/internal/::SetArgumentPointeeActioncxx . . $ testing/internal/SetArgumentPointeeAction#<N, T> SetArgumentPointeecxx . . $ testing/SetArgumentPointee(1d254da588ef4d10).(T value) { |
| 2010 | return {stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(value)}; |
| 2011 | } |
| 2012 | |
| 2013 | // Creates an action that sets a pointer referent to a given value. |
| 2014 | template <typename T1, typename T2> |
| 2015 | PolymorphicActioncxx . . $ testing/PolymorphicAction#<internalcxx . . $ testing/internal/::AssignActioncxx . . $ testing/internal/AssignAction#<T1, T2>> Assigncxx . . $ testing/Assign(77d21184e12943bd).(T1* ptr, T2 val) { |
| 2016 | return MakePolymorphicActioncxx . . $ testing/MakePolymorphicAction(712d411a1ea0c3b).(internalcxx . . $ testing/internal/::AssignActioncxx . . $ testing/internal/AssignAction#<T1, T2>(ptr, val)); |
| 2017 | } |
| 2018 | |
| 2019 | #ifndef GTEST_OS_WINDOWS_MOBILE |
| 2020 | |
| 2021 | // Creates an action that sets errno and returns the appropriate error. |
| 2022 | template <typename T> |
| 2023 | PolymorphicActioncxx . . $ testing/PolymorphicAction#<internalcxx . . $ testing/internal/::SetErrnoAndReturnActioncxx . . $ testing/internal/SetErrnoAndReturnAction#<T>> SetErrnoAndReturncxx . . $ testing/SetErrnoAndReturn(2d99abd6bd3efe0d).( |
| 2024 | int errval, T result) { |
| 2025 | return MakePolymorphicActioncxx . . $ testing/MakePolymorphicAction(712d411a1ea0c3b).( |
| 2026 | internalcxx . . $ testing/internal/::SetErrnoAndReturnActioncxx . . $ testing/internal/SetErrnoAndReturnAction#<T>(errval, result)); |
| 2027 | } |
| 2028 | |
| 2029 | #endif // !GTEST_OS_WINDOWS_MOBILE |
| 2030 | |
| 2031 | // Various overloads for Invoke(). |
| 2032 | |
| 2033 | // Legacy function. |
| 2034 | // Actions can now be implicitly constructed from callables. No need to create |
| 2035 | // wrapper objects. |
| 2036 | // This function exists for backwards compatibility. |
| 2037 | template <typename FunctionImpl> |
| 2038 | typename stdcxx . . $ std/::decay<FunctionImpl>::type Invokecxx . . $ testing/Invoke(b26379d769e6536e).(FunctionImpl&& function_impl) { |
| 2039 | return stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<FunctionImpl>(function_impl); |
| 2040 | } |
| 2041 | |
| 2042 | // Creates an action that invokes the given method on the given object |
| 2043 | // with the mock function's arguments. |
| 2044 | template <class Class, typename MethodPtr> |
| 2045 | internalcxx . . $ testing/internal/::InvokeMethodActioncxx . . $ testing/internal/InvokeMethodAction#<Class, MethodPtr> Invokecxx . . $ testing/Invoke(b164d8c479051df9).(Class* obj_ptr, |
| 2046 | MethodPtr method_ptr) { |
| 2047 | return {obj_ptr, method_ptr}; |
| 2048 | } |
| 2049 | |
| 2050 | // Creates an action that invokes 'function_impl' with no argument. |
| 2051 | template <typename FunctionImpl> |
| 2052 | internalcxx . . $ testing/internal/::InvokeWithoutArgsActioncxx . . $ testing/internal/InvokeWithoutArgsAction#<typename stdcxx . . $ std/::decay<FunctionImpl>::type> |
| 2053 | InvokeWithoutArgscxx . . $ testing/InvokeWithoutArgs(45753b617121fe7e).(FunctionImpl function_impl) { |
| 2054 | return {stdcxx . . $ std/::movecxx . . $ std/move(7316eb2979bdd03c).(function_impl)}; |
| 2055 | } |
| 2056 | |
| 2057 | // Creates an action that invokes the given method on the given object |
| 2058 | // with no argument. |
| 2059 | template <class Class, typename MethodPtr> |
| 2060 | internalcxx . . $ testing/internal/::InvokeMethodWithoutArgsActioncxx . . $ testing/internal/InvokeMethodWithoutArgsAction#<Class, MethodPtr> InvokeWithoutArgscxx . . $ testing/InvokeWithoutArgs(44308c4a56ac85d7).( |
| 2061 | Class* obj_ptr, MethodPtr method_ptr) { |
| 2062 | return {obj_ptr, method_ptr}; |
| 2063 | } |
| 2064 | |
| 2065 | // Creates an action that performs an_action and throws away its |
| 2066 | // result. In other words, it changes the return type of an_action to |
| 2067 | // void. an_action MUST NOT return void, or the code won't compile. |
| 2068 | template <typename A> |
| 2069 | inline internalcxx . . $ testing/internal/::IgnoreResultActioncxx . . $ testing/internal/IgnoreResultAction#<A> IgnoreResultcxx . . $ testing/IgnoreResult(3fa5384b6a36bab7).(const A& an_action) { |
| 2070 | return internalcxx . . $ testing/internal/::IgnoreResultActioncxx . . $ testing/internal/IgnoreResultAction#<A>(an_action); |
| 2071 | } |
| 2072 | |
| 2073 | // Creates a reference wrapper for the given L-value. If necessary, |
| 2074 | // you can explicitly specify the type of the reference. For example, |
| 2075 | // suppose 'derived' is an object of type Derived, ByRef(derived) |
| 2076 | // would wrap a Derived&. If you want to wrap a const Base& instead, |
| 2077 | // where Base is a base class of Derived, just write: |
| 2078 | // |
| 2079 | // ByRef<const Base>(derived) |
| 2080 | // |
| 2081 | // N.B. ByRef is redundant with std::ref, std::cref and std::reference_wrapper. |
| 2082 | // However, it may still be used for consistency with ByMove(). |
| 2083 | template <typename T> |
| 2084 | inline ::stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<T> ByRefcxx . . $ testing/ByRef(e56bf1a7c7069789).(T& l_value) { // NOLINT |
| 2085 | return ::stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<T>(l_value); |
| 2086 | } |
| 2087 | |
| 2088 | // The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new |
| 2089 | // instance of type T, constructed on the heap with constructor arguments |
| 2090 | // a1, a2, ..., and a_k. The caller assumes ownership of the returned value. |
| 2091 | template <typename T, typename... Params> |
| 2092 | internalcxx . . $ testing/internal/::ReturnNewActioncxx . . $ testing/internal/ReturnNewAction#<T, typename stdcxx . . $ std/::decay<Params>::type...> ReturnNewcxx . . $ testing/ReturnNew(9645835ab1feb0bf).( |
| 2093 | Params&&... params) { |
| 2094 | return {stdcxx . . $ std/::forward_as_tuplecxx . . $ std/forward_as_tuple(cd19fb0d9524ec73).(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Params>(params)...)}; |
| 2095 | } |
| 2096 | |
| 2097 | // Action ReturnArg<k>() returns the k-th argument of the mock function. |
| 2098 | template <size_t k> |
| 2099 | internalcxx . . $ testing/internal/::ReturnArgActioncxx . . $ testing/internal/ReturnArgAction#<k> ReturnArgcxx . . $ testing/ReturnArg(76dbed392cb252ad).() { |
| 2100 | return {}; |
| 2101 | } |
| 2102 | |
| 2103 | // Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the |
| 2104 | // mock function to *pointer. |
| 2105 | template <size_t k, typename Ptr> |
| 2106 | internalcxx . . $ testing/internal/::SaveArgActioncxx . . $ testing/internal/SaveArgAction#<k, Ptr> SaveArgcxx . . $ testing/SaveArg(8733104622c6ba4e).(Ptr pointer) { |
| 2107 | return {pointer}; |
| 2108 | } |
| 2109 | |
| 2110 | // Action SaveArgByMove<k>(pointer) moves the k-th (0-based) argument of the |
| 2111 | // mock function into *pointer. |
| 2112 | template <size_t k, typename Ptr> |
| 2113 | internalcxx . . $ testing/internal/::SaveArgByMoveActioncxx . . $ testing/internal/SaveArgByMoveAction#<k, Ptr> SaveArgByMovecxx . . $ testing/SaveArgByMove(167db824feadcaa5).(Ptr pointer) { |
| 2114 | return {pointer}; |
| 2115 | } |
| 2116 | |
| 2117 | // Action SaveArgPointee<k>(pointer) saves the value pointed to |
| 2118 | // by the k-th (0-based) argument of the mock function to *pointer. |
| 2119 | template <size_t k, typename Ptr> |
| 2120 | internalcxx . . $ testing/internal/::SaveArgPointeeActioncxx . . $ testing/internal/SaveArgPointeeAction#<k, Ptr> SaveArgPointeecxx . . $ testing/SaveArgPointee(ccac9692218e779e).(Ptr pointer) { |
| 2121 | return {pointer}; |
| 2122 | } |
| 2123 | |
| 2124 | // Action SetArgReferee<k>(value) assigns 'value' to the variable |
| 2125 | // referenced by the k-th (0-based) argument of the mock function. |
| 2126 | template <size_t k, typename T> |
| 2127 | internalcxx . . $ testing/internal/::SetArgRefereeActioncxx . . $ testing/internal/SetArgRefereeAction#<k, typename stdcxx . . $ std/::decay<T>::type> SetArgRefereecxx . . $ testing/SetArgReferee(39421983acf6874e).( |
| 2128 | T&& value) { |
| 2129 | return {stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<T>(value)}; |
| 2130 | } |
| 2131 | |
| 2132 | // Action SetArrayArgument<k>(first, last) copies the elements in |
| 2133 | // source range [first, last) to the array pointed to by the k-th |
| 2134 | // (0-based) argument, which can be either a pointer or an |
| 2135 | // iterator. The action does not take ownership of the elements in the |
| 2136 | // source range. |
| 2137 | template <size_t k, typename I1, typename I2> |
| 2138 | internalcxx . . $ testing/internal/::SetArrayArgumentActioncxx . . $ testing/internal/SetArrayArgumentAction#<k, I1, I2> SetArrayArgumentcxx . . $ testing/SetArrayArgument(92063efa94f8b1f).(I1 first, |
| 2139 | I2 last) { |
| 2140 | return {first, last}; |
| 2141 | } |
| 2142 | |
| 2143 | // Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock |
| 2144 | // function. |
| 2145 | template <size_t k> |
| 2146 | internalcxx . . $ testing/internal/::DeleteArgActioncxx . . $ testing/internal/DeleteArgAction#<k> DeleteArgcxx . . $ testing/DeleteArg(5c7ecd0445fdb83c).() { |
| 2147 | return {}; |
| 2148 | } |
| 2149 | |
| 2150 | // This action returns the value pointed to by 'pointer'. |
| 2151 | template <typename Ptr> |
| 2152 | internalcxx . . $ testing/internal/::ReturnPointeeActioncxx . . $ testing/internal/ReturnPointeeAction#<Ptr> ReturnPointeecxx . . $ testing/ReturnPointee(4d144ae9e94ffdac).(Ptr pointer) { |
| 2153 | return {pointer}; |
| 2154 | } |
| 2155 | |
| 2156 | #if GTEST_HAS_EXCEPTIONScxx . . $ `googletest/include/gtest/internal/gtest-port.h:483:9`! |
| 2157 | // Action Throw(exception) can be used in a mock function of any type |
| 2158 | // to throw the given exception. Any copyable value can be thrown, |
| 2159 | // except for std::exception_ptr, which is likely a mistake if |
| 2160 | // thrown directly. |
| 2161 | template <typename T> |
| 2162 | typename stdcxx . . $ std/::enable_if< |
| 2163 | !std::is_base_of<std::exception_ptr, typename std::decay<T>::type>::value, |
| 2164 | internal::ThrowAction<typename std::decay<T>::type>>::type |
| 2165 | Throwcxx . . $ testing/Throw(c5a4b90783047d89).(T&& exception) { |
| 2166 | return {stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<T>(exception)}; |
| 2167 | } |
| 2168 | // Action Rethrow(exception_ptr) can be used in a mock function of any type |
| 2169 | // to rethrow any exception_ptr. Note that the same object is thrown each time. |
| 2170 | inline internalcxx . . $ testing/internal/::RethrowActioncxx . . $ testing/internal/RethrowAction# Rethrowcxx . . $ testing/Rethrow(acb14287d21f43dd).(stdcxx . . $ std/::exception_ptr exception) { |
| 2171 | return {stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(exception)}; |
| 2172 | } |
| 2173 | #endif // GTEST_HAS_EXCEPTIONS |
| 2174 | |
| 2175 | namespace internalcxx . . $ testing/internal/ { |
| 2176 | |
| 2177 | // A macro from the ACTION* family (defined later in gmock-generated-actions.h) |
| 2178 | // defines an action that can be used in a mock function. Typically, |
| 2179 | // these actions only care about a subset of the arguments of the mock |
| 2180 | // function. For example, if such an action only uses the second |
| 2181 | // argument, it can be used in any mock function that takes >= 2 |
| 2182 | // arguments where the type of the second argument is compatible. |
| 2183 | // |
| 2184 | // Therefore, the action implementation must be prepared to take more |
| 2185 | // arguments than it needs. The ExcessiveArg type is used to |
| 2186 | // represent those excessive arguments. In order to keep the compiler |
| 2187 | // error messages tractable, we define it in the testing namespace |
| 2188 | // instead of testing::internal. However, this is an INTERNAL TYPE |
| 2189 | // and subject to change without notice, so a user MUST NOT USE THIS |
| 2190 | // TYPE DIRECTLY. |
| 2191 | struct ExcessiveArgcxx . . $ testing/internal/ExcessiveArg# {}; |
| 2192 | |
| 2193 | // Builds an implementation of an Action<> for some particular signature, using |
| 2194 | // a class defined by an ACTION* macro. |
| 2195 | template <typename F, typename Impl> |
| 2196 | struct ActionImplcxx . . $ testing/internal/ActionImpl#; |
| 2197 | |
| 2198 | template <typename Impl> |
| 2199 | struct ImplBasecxx . . $ testing/internal/ImplBase# { |
| 2200 | struct Holdercxx . . $ testing/internal/ImplBase#Holder# { |
| 2201 | // Allows each copy of the Action<> to get to the Impl. |
| 2202 | explicit operatorcxx . . $ testing/internal/ImplBase#Holder#`operator const type-parameter-0-0 &`(ea465e50d690edfe). const Impl&() const { return *ptrcxx . . $ testing/internal/ImplBase#Holder#ptr.; } |
| 2203 | stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<Impl> ptrcxx . . $ testing/internal/ImplBase#Holder#ptr.; |
| 2204 | }; |
| 2205 | using typecxx . . $ testing/internal/ImplBase#type# = typename stdcxx . . $ std/::conditional<std::is_constructible<Impl>::value, |
| 2206 | Impl, Holder>::type; |
| 2207 | }; |
| 2208 | |
| 2209 | template <typename R, typename... Args, typename Impl> |
| 2210 | struct ActionImplcxx . . $ testing/internal/ActionImpl#<R(Args...), Impl> : ImplBasecxx . . $ testing/internal/ImplBase#<Impl>::type { |
| 2211 | using Basecxx . . $ testing/internal/ActionImpl#Base# = typename ImplBasecxx . . $ testing/internal/ImplBase#<Impl>::type; |
| 2212 | using function_typecxx . . $ testing/internal/ActionImpl#function_type# = R(Args...); |
| 2213 | using args_typecxx . . $ testing/internal/ActionImpl#args_type# = stdcxx . . $ std/::tuplecxx . . $ std/tuple#<Args...>; |
| 2214 | |
| 2215 | ActionImplcxx . . $ testing/internal/ActionImpl#`ActionImpl<R (Args...), Impl>`(49f6e7a06ebc5aa8).() = default; // Only defined if appropriate for Base. |
| 2216 | explicit ActionImplcxx . . $ testing/internal/ActionImpl#`ActionImpl<R (Args...), Impl>`(37aa49271fde7379).(stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<Impl> impl) : Basecxx . . $ testing/internal/ActionImpl#Base#{stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(impl)} {} |
| 2217 | |
| 2218 | R operatorcxx . . $ testing/internal/ActionImpl#`operator()`(b486b8eaffe87236).()(Args&&... arg) const { |
| 2219 | static constexpr size_t kMaxArgs = |
| 2220 | sizeof...(Args) <= 10 ? sizeof...(Args) : 10; |
| 2221 | return Apply(stdcxx . . $ std/::make_index_sequencecxx . . $ std/make_index_sequence#<kMaxArgs>{}, |
| 2222 | stdcxx . . $ std/::make_index_sequencecxx . . $ std/make_index_sequence#<10 - kMaxArgs>{}, |
| 2223 | args_typecxx . . $ testing/internal/ActionImpl#args_type#{stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Args>(arg)...}); |
| 2224 | } |
| 2225 | |
| 2226 | template <stdcxx . . $ std/::size_tcxx . . $ std/size_t#... arg_id, stdcxx . . $ std/::size_tcxx . . $ std/size_t#... excess_id> |
| 2227 | R Applycxx . . $ testing/internal/ActionImpl#Apply(23ff14225c61280a).(stdcxx . . $ std/::index_sequencecxx . . $ std/index_sequence#<arg_id...>, stdcxx . . $ std/::index_sequencecxx . . $ std/index_sequence#<excess_id...>, |
| 2228 | const args_typecxx . . $ testing/internal/ActionImpl#args_type#& args) const { |
| 2229 | // Impl need not be specific to the signature of action being implemented; |
| 2230 | // only the implementing function body needs to have all of the specific |
| 2231 | // types instantiated. Up to 10 of the args that are provided by the |
| 2232 | // args_type get passed, followed by a dummy of unspecified type for the |
| 2233 | // remainder up to 10 explicit args. |
| 2234 | static constexpr ExcessiveArgcxx . . $ testing/internal/ExcessiveArg# kExcessArg{}; |
| 2235 | return static_cast<const Impl&>(*this) |
| 2236 | .template gmock_PerformImpl< |
| 2237 | /*function_type=*/function_typecxx . . $ testing/internal/ActionImpl#function_type#, /*return_type=*/R, |
| 2238 | /*args_type=*/args_typecxx . . $ testing/internal/ActionImpl#args_type#, |
| 2239 | /*argN_type=*/ |
| 2240 | typename stdcxx . . $ std/::tuple_elementcxx . . $ std/tuple_element#<arg_id, args_type>::type...>( |
| 2241 | /*args=*/args, stdcxx . . $ std/::getcxx . . $ std/get(959d1ca383d8d70e).<arg_id>(args)..., |
| 2242 | ((void)excess_id, kExcessArg)...); |
| 2243 | } |
| 2244 | }; |
| 2245 | |
| 2246 | // Stores a default-constructed Impl as part of the Action<>'s |
| 2247 | // std::function<>. The Impl should be trivial to copy. |
| 2248 | template <typename F, typename Impl> |
| 2249 | ::testingcxx . . $ testing/::Actioncxx . . $ testing/Action#<F> MakeActioncxx . . $ testing/internal/MakeAction(13c2b995afa5293a).() { |
| 2250 | return ::testingcxx . . $ testing/::Actioncxx . . $ testing/Action#<F>(ActionImplcxx . . $ testing/internal/ActionImpl#<F, Impl>()); |
| 2251 | } |
| 2252 | |
| 2253 | // Stores just the one given instance of Impl. |
| 2254 | template <typename F, typename Impl> |
| 2255 | ::testingcxx . . $ testing/::Actioncxx . . $ testing/Action#<F> MakeActioncxx . . $ testing/internal/MakeAction(ef019983bdd8af41).(stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<Impl> impl) { |
| 2256 | return ::testingcxx . . $ testing/::Actioncxx . . $ testing/Action#<F>(ActionImplcxx . . $ testing/internal/ActionImpl#<F, Impl>(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(impl))); |
| 2257 | } |
| 2258 | |
| 2259 | #define GMOCK_INTERNAL_ARG_UNUSEDcxx . . $ `googlemock/include/gmock/gmock-actions.h:2259:9`!(i, data, el) \ |
| 2260 | , [[maybe_unused]] const arg##i##_type& arg##i |
| 2261 | #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_cxx . . $ `googlemock/include/gmock/gmock-actions.h:2261:9`! \ |
| 2262 | [[maybe_unused]] const args_type& args GMOCK_PP_REPEAT( \ |
| 2263 | GMOCK_INTERNAL_ARG_UNUSED, , 10) |
| 2264 | |
| 2265 | #define GMOCK_INTERNAL_ARGcxx . . $ `googlemock/include/gmock/gmock-actions.h:2265:9`!(i, data, el) , const arg##i##_type& arg##i |
| 2266 | #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_cxx . . $ `googlemock/include/gmock/gmock-actions.h:2266:9`! \ |
| 2267 | const args_type& args GMOCK_PP_REPEAT(GMOCK_INTERNAL_ARG, , 10) |
| 2268 | |
| 2269 | #define GMOCK_INTERNAL_TEMPLATE_ARGcxx . . $ `googlemock/include/gmock/gmock-actions.h:2269:9`!(i, data, el) , typename arg##i##_type |
| 2270 | #define GMOCK_ACTION_TEMPLATE_ARGS_NAMES_cxx . . $ `googlemock/include/gmock/gmock-actions.h:2270:9`! \ |
| 2271 | GMOCK_PP_TAIL(GMOCK_PP_REPEAT(GMOCK_INTERNAL_TEMPLATE_ARG, , 10)) |
| 2272 | |
| 2273 | #define GMOCK_INTERNAL_TYPENAME_PARAMcxx . . $ `googlemock/include/gmock/gmock-actions.h:2273:9`!(i, data, param) , typename param##_type |
| 2274 | #define GMOCK_ACTION_TYPENAME_PARAMS_cxx . . $ `googlemock/include/gmock/gmock-actions.h:2274:9`!(params) \ |
| 2275 | GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPENAME_PARAM, , params)) |
| 2276 | |
| 2277 | #define GMOCK_INTERNAL_TYPE_PARAMcxx . . $ `googlemock/include/gmock/gmock-actions.h:2277:9`!(i, data, param) , param##_type |
| 2278 | #define GMOCK_ACTION_TYPE_PARAMS_cxx . . $ `googlemock/include/gmock/gmock-actions.h:2278:9`!(params) \ |
| 2279 | GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_PARAM, , params)) |
| 2280 | |
| 2281 | #define GMOCK_INTERNAL_TYPE_GVALUE_PARAMcxx . . $ `googlemock/include/gmock/gmock-actions.h:2281:9`!(i, data, param) \ |
| 2282 | , param##_type gmock_p##i |
| 2283 | #define GMOCK_ACTION_TYPE_GVALUE_PARAMS_cxx . . $ `googlemock/include/gmock/gmock-actions.h:2283:9`!(params) \ |
| 2284 | GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_GVALUE_PARAM, , params)) |
| 2285 | |
| 2286 | #define GMOCK_INTERNAL_GVALUE_PARAMcxx . . $ `googlemock/include/gmock/gmock-actions.h:2286:9`!(i, data, param) \ |
| 2287 | , std::forward<param##_type>(gmock_p##i) |
| 2288 | #define GMOCK_ACTION_GVALUE_PARAMS_cxx . . $ `googlemock/include/gmock/gmock-actions.h:2288:9`!(params) \ |
| 2289 | GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GVALUE_PARAM, , params)) |
| 2290 | |
| 2291 | #define GMOCK_INTERNAL_INIT_PARAMcxx . . $ `googlemock/include/gmock/gmock-actions.h:2291:9`!(i, data, param) \ |
| 2292 | , param(::std::forward<param##_type>(gmock_p##i)) |
| 2293 | #define GMOCK_ACTION_INIT_PARAMS_cxx . . $ `googlemock/include/gmock/gmock-actions.h:2293:9`!(params) \ |
| 2294 | GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_INIT_PARAM, , params)) |
| 2295 | |
| 2296 | #define GMOCK_INTERNAL_FIELD_PARAMcxx . . $ `googlemock/include/gmock/gmock-actions.h:2296:9`!(i, data, param) param##_type param; |
| 2297 | #define GMOCK_ACTION_FIELD_PARAMS_cxx . . $ `googlemock/include/gmock/gmock-actions.h:2297:9`!(params) \ |
| 2298 | GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_FIELD_PARAM, , params) |
| 2299 | |
| 2300 | #define GMOCK_INTERNAL_ACTIONcxx . . $ `googlemock/include/gmock/gmock-actions.h:2300:9`!(name, full_name, params) \ |
| 2301 | template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \ |
| 2302 | class full_name { \ |
| 2303 | public: \ |
| 2304 | explicit full_name(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) \ |
| 2305 | : impl_(std::make_shared<gmock_Impl>( \ |
| 2306 | GMOCK_ACTION_GVALUE_PARAMS_(params))) {} \ |
| 2307 | full_name(const full_name&) = default; \ |
| 2308 | full_name(full_name&&) noexcept = default; \ |
| 2309 | template <typename F> \ |
| 2310 | operator ::testing::Action<F>() const { \ |
| 2311 | return ::testing::internal::MakeAction<F>(impl_); \ |
| 2312 | } \ |
| 2313 | \ |
| 2314 | private: \ |
| 2315 | class gmock_Impl { \ |
| 2316 | public: \ |
| 2317 | explicit gmock_Impl(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) \ |
| 2318 | : GMOCK_ACTION_INIT_PARAMS_(params) {} \ |
| 2319 | template <typename function_type, typename return_type, \ |
| 2320 | typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ |
| 2321 | return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ |
| 2322 | GMOCK_ACTION_FIELD_PARAMS_(params) \ |
| 2323 | }; \ |
| 2324 | std::shared_ptr<const gmock_Impl> impl_; \ |
| 2325 | }; \ |
| 2326 | template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \ |
| 2327 | [[nodiscard]] inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \ |
| 2328 | GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)); \ |
| 2329 | template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \ |
| 2330 | inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \ |
| 2331 | GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) { \ |
| 2332 | return full_name<GMOCK_ACTION_TYPE_PARAMS_(params)>( \ |
| 2333 | GMOCK_ACTION_GVALUE_PARAMS_(params)); \ |
| 2334 | } \ |
| 2335 | template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \ |
| 2336 | template <typename function_type, typename return_type, typename args_type, \ |
| 2337 | GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ |
| 2338 | return_type \ |
| 2339 | full_name<GMOCK_ACTION_TYPE_PARAMS_(params)>::gmock_Impl::gmock_PerformImpl( \ |
| 2340 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 2341 | |
| 2342 | } // namespace internal |
| 2343 | |
| 2344 | // Similar to GMOCK_INTERNAL_ACTION, but no bound parameters are stored. |
| 2345 | #define ACTIONcxx . . $ `googlemock/include/gmock/gmock-actions.h:2345:9`!(name) \ |
| 2346 | class name##Action { \ |
| 2347 | public: \ |
| 2348 | explicit name##Action() noexcept {} \ |
| 2349 | name##Action(const name##Action&) noexcept {} \ |
| 2350 | template <typename F> \ |
| 2351 | operator ::testing::Action<F>() const { \ |
| 2352 | return ::testing::internal::MakeAction<F, gmock_Impl>(); \ |
| 2353 | } \ |
| 2354 | \ |
| 2355 | private: \ |
| 2356 | class gmock_Impl { \ |
| 2357 | public: \ |
| 2358 | template <typename function_type, typename return_type, \ |
| 2359 | typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ |
| 2360 | return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ |
| 2361 | }; \ |
| 2362 | }; \ |
| 2363 | [[nodiscard]] inline name##Action name(); \ |
| 2364 | inline name##Action name() { return name##Action(); } \ |
| 2365 | template <typename function_type, typename return_type, typename args_type, \ |
| 2366 | GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ |
| 2367 | return_type name##Action::gmock_Impl::gmock_PerformImpl( \ |
| 2368 | GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
| 2369 | |
| 2370 | #define ACTION_Pcxx . . $ `googlemock/include/gmock/gmock-actions.h:2370:9`!(name, ...) \ |
| 2371 | GMOCK_INTERNAL_ACTION(name, name##ActionP, (__VA_ARGS__)) |
| 2372 | |
| 2373 | #define ACTION_P2cxx . . $ `googlemock/include/gmock/gmock-actions.h:2373:9`!(name, ...) \ |
| 2374 | GMOCK_INTERNAL_ACTION(name, name##ActionP2, (__VA_ARGS__)) |
| 2375 | |
| 2376 | #define ACTION_P3cxx . . $ `googlemock/include/gmock/gmock-actions.h:2376:9`!(name, ...) \ |
| 2377 | GMOCK_INTERNAL_ACTION(name, name##ActionP3, (__VA_ARGS__)) |
| 2378 | |
| 2379 | #define ACTION_P4cxx . . $ `googlemock/include/gmock/gmock-actions.h:2379:9`!(name, ...) \ |
| 2380 | GMOCK_INTERNAL_ACTION(name, name##ActionP4, (__VA_ARGS__)) |
| 2381 | |
| 2382 | #define ACTION_P5cxx . . $ `googlemock/include/gmock/gmock-actions.h:2382:9`!(name, ...) \ |
| 2383 | GMOCK_INTERNAL_ACTION(name, name##ActionP5, (__VA_ARGS__)) |
| 2384 | |
| 2385 | #define ACTION_P6cxx . . $ `googlemock/include/gmock/gmock-actions.h:2385:9`!(name, ...) \ |
| 2386 | GMOCK_INTERNAL_ACTION(name, name##ActionP6, (__VA_ARGS__)) |
| 2387 | |
| 2388 | #define ACTION_P7cxx . . $ `googlemock/include/gmock/gmock-actions.h:2388:9`!(name, ...) \ |
| 2389 | GMOCK_INTERNAL_ACTION(name, name##ActionP7, (__VA_ARGS__)) |
| 2390 | |
| 2391 | #define ACTION_P8cxx . . $ `googlemock/include/gmock/gmock-actions.h:2391:9`!(name, ...) \ |
| 2392 | GMOCK_INTERNAL_ACTION(name, name##ActionP8, (__VA_ARGS__)) |
| 2393 | |
| 2394 | #define ACTION_P9cxx . . $ `googlemock/include/gmock/gmock-actions.h:2394:9`!(name, ...) \ |
| 2395 | GMOCK_INTERNAL_ACTION(name, name##ActionP9, (__VA_ARGS__)) |
| 2396 | |
| 2397 | #define ACTION_P10cxx . . $ `googlemock/include/gmock/gmock-actions.h:2397:9`!(name, ...) \ |
| 2398 | GMOCK_INTERNAL_ACTION(name, name##ActionP10, (__VA_ARGS__)) |
| 2399 | |
| 2400 | } // namespace testing |
| 2401 | |
| 2402 | GTEST_DISABLE_MSC_WARNINGS_POP_cxx . . $ `googletest/include/gtest/internal/gtest-port.h:376:9`!() // 4100 |
| 2403 | |
| 2404 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ |