1$$ -*- mode: c++; -*- 2$$ This is a Pump source file. Please use Pump to convert 3$$ it to gmock-generated-function-mockers.h. 4$$ 5$var n = 10 $$ The maximum arity we support. 6// Copyright 2007, Google Inc. 7// All rights reserved. 8// 9// Redistribution and use in source and binary forms, with or without 10// modification, are permitted provided that the following conditions are 11// met: 12// 13// * Redistributions of source code must retain the above copyright 14// notice, this list of conditions and the following disclaimer. 15// * Redistributions in binary form must reproduce the above 16// copyright notice, this list of conditions and the following disclaimer 17// in the documentation and/or other materials provided with the 18// distribution. 19// * Neither the name of Google Inc. nor the names of its 20// contributors may be used to endorse or promote products derived from 21// this software without specific prior written permission. 22// 23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 35 36// Google Mock - a framework for writing C++ mock classes. 37// 38// This file implements function mockers of various arities. 39 40// GOOGLETEST_CM0002 DO NOT DELETE 41 42#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ 43#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ 44 45#include <functional> 46#include <utility> 47 48#include "gmock/gmock-spec-builders.h" 49#include "gmock/internal/gmock-internal-utils.h" 50 51namespace testing { 52namespace internal { 53 54$range i 0..n 55// Removes the given pointer; this is a helper for the expectation setter method 56// for parameterless matchers. 57// 58// We want to make sure that the user cannot set a parameterless expectation on 59// overloaded methods, including methods which are overloaded on const. Example: 60// 61// class MockClass { 62// MOCK_METHOD0(GetName, string&()); 63// MOCK_CONST_METHOD0(GetName, const string&()); 64// }; 65// 66// TEST() { 67// // This should be an error, as it's not clear which overload is expected. 68// EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value)); 69// } 70// 71// Here are the generated expectation-setter methods: 72// 73// class MockClass { 74// // Overload 1 75// MockSpec<string&()> gmock_GetName() { ... } 76// // Overload 2. Declared const so that the compiler will generate an 77// // error when trying to resolve between this and overload 4 in 78// // 'gmock_GetName(WithoutMatchers(), nullptr)'. 79// MockSpec<string&()> gmock_GetName( 80// const WithoutMatchers&, const Function<string&()>*) const { 81// // Removes const from this, calls overload 1 82// return AdjustConstness_(this)->gmock_GetName(); 83// } 84// 85// // Overload 3 86// const string& gmock_GetName() const { ... } 87// // Overload 4 88// MockSpec<const string&()> gmock_GetName( 89// const WithoutMatchers&, const Function<const string&()>*) const { 90// // Does not remove const, calls overload 3 91// return AdjustConstness_const(this)->gmock_GetName(); 92// } 93// } 94// 95template <typename MockType> 96const MockType* AdjustConstness_const(const MockType* mock) { 97 return mock; 98} 99 100// Removes const from and returns the given pointer; this is a helper for the 101// expectation setter method for parameterless matchers. 102template <typename MockType> 103MockType* AdjustConstness_(const MockType* mock) { 104 return const_cast<MockType*>(mock); 105} 106 107} // namespace internal 108 109// The style guide prohibits "using" statements in a namespace scope 110// inside a header file. However, the FunctionMocker class template 111// is meant to be defined in the ::testing namespace. The following 112// line is just a trick for working around a bug in MSVC 8.0, which 113// cannot handle it if we define FunctionMocker in ::testing. 114using internal::FunctionMocker; 115 116// GMOCK_RESULT_(tn, F) expands to the result type of function type F. 117// We define this as a variadic macro in case F contains unprotected 118// commas (the same reason that we use variadic macros in other places 119// in this file). 120// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 121#define GMOCK_RESULT_(tn, ...) \ 122 tn ::testing::internal::Function<__VA_ARGS__>::Result 123 124// The type of argument N of the given function type. 125// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 126#define GMOCK_ARG_(tn, N, ...) \ 127 tn ::testing::internal::Function<__VA_ARGS__>::template Arg<N-1>::type 128 129// The matcher type for argument N of the given function type. 130// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 131#define GMOCK_MATCHER_(tn, N, ...) \ 132 const ::testing::Matcher<GMOCK_ARG_(tn, N, __VA_ARGS__)>& 133 134// The variable for mocking the given method. 135// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 136#define GMOCK_MOCKER_(arity, constness, Method) \ 137 GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) 138 139 140$for i [[ 141$range j 1..i 142$var arg_as = [[$for j, [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]] 143$var as = [[$for j, \ 144 [[::std::forward<GMOCK_ARG_(tn, $j, __VA_ARGS__)>(gmock_a$j)]]]] 145$var matcher_arg_as = [[$for j, \ 146 [[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]] 147$var matcher_as = [[$for j, [[gmock_a$j]]]] 148$var anything_matchers = [[$for j, \ 149 [[::testing::A<GMOCK_ARG_(tn, $j, __VA_ARGS__)>()]]]] 150// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 151#define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \ 152 static_assert($i == ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, "MOCK_METHOD<N> must match argument count.");\ 153 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 154 $arg_as) constness { \ 155 GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \ 156 return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \ 157 } \ 158 ::testing::MockSpec<__VA_ARGS__> \ 159 gmock_##Method($matcher_arg_as) constness { \ 160 GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \ 161 return GMOCK_MOCKER_($i, constness, Method).With($matcher_as); \ 162 } \ 163 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ 164 const ::testing::internal::WithoutMatchers&, \ 165 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ 166 return ::testing::internal::AdjustConstness_##constness(this)-> \ 167 gmock_##Method($anything_matchers); \ 168 } \ 169 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method) 170 171 172]] 173$for i [[ 174#define MOCK_METHOD$i(m, ...) GMOCK_METHOD$i[[]]_(, , , m, __VA_ARGS__) 175 176]] 177 178 179$for i [[ 180#define MOCK_CONST_METHOD$i(m, ...) GMOCK_METHOD$i[[]]_(, const, , m, __VA_ARGS__) 181 182]] 183 184 185$for i [[ 186#define MOCK_METHOD$i[[]]_T(m, ...) GMOCK_METHOD$i[[]]_(typename, , , m, __VA_ARGS__) 187 188]] 189 190 191$for i [[ 192#define MOCK_CONST_METHOD$i[[]]_T(m, ...) \ 193 GMOCK_METHOD$i[[]]_(typename, const, , m, __VA_ARGS__) 194 195]] 196 197 198$for i [[ 199#define MOCK_METHOD$i[[]]_WITH_CALLTYPE(ct, m, ...) \ 200 GMOCK_METHOD$i[[]]_(, , ct, m, __VA_ARGS__) 201 202]] 203 204 205$for i [[ 206#define MOCK_CONST_METHOD$i[[]]_WITH_CALLTYPE(ct, m, ...) \ 207 GMOCK_METHOD$i[[]]_(, const, ct, m, __VA_ARGS__) 208 209]] 210 211 212$for i [[ 213#define MOCK_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, ...) \ 214 GMOCK_METHOD$i[[]]_(typename, , ct, m, __VA_ARGS__) 215 216]] 217 218 219$for i [[ 220#define MOCK_CONST_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, ...) \ 221 GMOCK_METHOD$i[[]]_(typename, const, ct, m, __VA_ARGS__) 222 223]] 224 225} // namespace testing 226 227#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ 228