53#if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
54# define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
58namespace gmock_generated_function_mockers_test {
82 virtual long Binary(
short x,
int y) = 0;
83 virtual int Decimal(
bool b,
char c,
short d,
int e,
long f,
84 float g,
double h,
unsigned i,
char*
j,
85 const std::string& k) = 0;
89#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
106 STDMETHOD_(
int, CTNullary)() = 0;
107 STDMETHOD_(
bool, CTUnary)(
int x) = 0;
108 STDMETHOD_(
int, CTDecimal)
109 (
bool b,
char c,
short d,
int e,
long f,
110 float g,
double h,
unsigned i,
char*
j,
const std::string& k) = 0;
111 STDMETHOD_(
char, CTConst)(
int x)
const = 0;
120# pragma warning(push)
121# pragma warning(disable : 4373)
136 double,
unsigned,
char*,
const std::string& str));
141#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
148 std::map<int, std::string>(
int));
161 int(
const std::map<int, std::string>&));
167 int(
bool b,
char c,
short d,
int e,
long f,
168 float g,
double h,
unsigned i,
char*
j,
169 const std::string& k));
174 std::map<int, std::string>());
195 foo_->VoidReturning(0);
228 EXPECT_CALL(mock_foo_, Decimal(
true,
'a', 0, 0, 1L, A<float>(),
229 Lt(100), 5U, NULL,
"hi"))
232 EXPECT_EQ(5, foo_->Decimal(
true,
'a', 0, 0, 1, 0, 0, 5, NULL,
"hi"));
248 .WillOnce(
Return(
"Hello"));
250 EXPECT_EQ(
"Hello", foo_->TakesConstReference(
a));
253#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
265 EXPECT_CALL(mock_foo_, OverloadedOnArgumentNumber())
267 EXPECT_CALL(mock_foo_, OverloadedOnArgumentNumber(_))
270 EXPECT_EQ(2, foo_->OverloadedOnArgumentNumber(1));
271 EXPECT_EQ(1, foo_->OverloadedOnArgumentNumber());
276 EXPECT_CALL(mock_foo_, OverloadedOnArgumentType(An<int>()))
278 EXPECT_CALL(mock_foo_, OverloadedOnArgumentType(TypedEq<char>(
'a')))
281 EXPECT_EQ(1, foo_->OverloadedOnArgumentType(0));
282 EXPECT_EQ(
'b', foo_->OverloadedOnArgumentType(
'a'));
291 EXPECT_EQ(0, foo_->OverloadedOnConstness());
296 const std::map<int, std::string> a_map;
302 EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma());
303 EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma(42));
308TEST_F(FunctionMockerTest, MocksNullaryFunctionWithCallType) {
318TEST_F(FunctionMockerTest, MocksUnaryFunctionWithCallType) {
329TEST_F(FunctionMockerTest, MocksDecimalFunctionWithCallType) {
330 EXPECT_CALL(mock_foo_, CTDecimal(
true,
'a', 0, 0, 1L, A<float>(),
331 Lt(100), 5U, NULL,
"hi"))
334 EXPECT_EQ(10, foo_->CTDecimal(
true,
'a', 0, 0, 1, 0, 0, 5, NULL,
"hi"));
338TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
345TEST_F(FunctionMockerTest, MocksReturnTypeWithCommaAndCallType) {
346 const std::map<int, std::string> a_map;
350 EXPECT_EQ(a_map, mock_foo_.CTReturnTypeWithComma());
367TEST(ExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) {
440TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) {
443 const std::map<int, int> a_map;
449 EXPECT_EQ(a_map, mock.ReturnTypeWithComma());
450 EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1));
457class StackInterfaceWithCallType {
459 virtual ~StackInterfaceWithCallType() {}
462 STDMETHOD_(
void, Push)(
const T&
value) = 0;
463 STDMETHOD_(
void, Pop)() = 0;
464 STDMETHOD_(
int, GetSize)()
const = 0;
466 STDMETHOD_(
const T&, GetTop)()
const = 0;
470class MockStackWithCallType :
public StackInterfaceWithCallType<T> {
472 MockStackWithCallType() {}
484TEST(TemplateMockTestWithCallType, Works) {
485 MockStackWithCallType<int> mock;
507#define MY_MOCK_METHODS1_ \
508 MOCK_METHOD0(Overloaded, void()); \
509 MOCK_CONST_METHOD1(Overloaded, int(int n)); \
510 MOCK_METHOD2(Overloaded, bool(bool f, int n))
522TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
533#define MY_MOCK_METHODS2_ \
534 MOCK_CONST_METHOD1(Overloaded, int(int n)); \
535 MOCK_METHOD1(Overloaded, int(int n));
547TEST(OverloadedMockMethodTest, CanOverloadOnConstnessInMacroBody) {
557TEST(MockFunctionTest, WorksForVoidNullary) {
563TEST(MockFunctionTest, WorksForNonVoidNullary) {
572TEST(MockFunctionTest, WorksForVoidUnary) {
578TEST(MockFunctionTest, WorksForNonVoidBinary) {
590TEST(MockFunctionTest, WorksFor10Arguments) {
591 MockFunction<int(
bool a0,
char a1,
int a2,
int a3,
int a4,
592 int a5,
int a6,
char a7,
int a8,
bool a9)>
foo;
593 EXPECT_CALL(
foo,
Call(_,
'a', _, _, _, _, _, _, _, _))
596 EXPECT_EQ(1,
foo.Call(
false,
'a', 0, 0, 0, 0, 0,
'b', 0,
true));
597 EXPECT_EQ(2,
foo.Call(
true,
'a', 0, 0, 0, 0, 0,
'b', 1,
false));
600#if GTEST_HAS_STD_FUNCTION_
601TEST(MockFunctionTest, AsStdFunction) {
603 auto call = [](
const std::function<int(
int)> &
f,
int i) {
612TEST(MockFunctionTest, AsStdFunctionReturnsReference) {
613 MockFunction<
int&()>
foo;
616 int& ref =
foo.AsStdFunction()();
639TEST(MockFunctionTest, MockMethodSizeOverhead) {
virtual int OverloadedOnArgumentNumber(int n)=0
virtual long Binary(short x, int y)=0
virtual int Decimal(bool b, char c, short d, int e, long f, float g, double h, unsigned i, char *j, const std::string &k)=0
virtual int TypeWithComma(const std::map< int, std::string > &a_map)=0
virtual bool TakesNonConstReference(int &n)=0
virtual bool TakesConst(const int x)=0
virtual char OverloadedOnArgumentType(char c)=0
virtual int TypeWithHole(int(*func)())=0
virtual std::string TakesConstReference(const int &n)=0
virtual char OverloadedOnConstness() const =0
virtual int OverloadedOnArgumentType(int n)=0
virtual void VoidReturning(int x)=0
virtual bool Unary(int x)=0
virtual int OverloadedOnArgumentNumber()=0
virtual int OverloadedOnConstness()=0
MOCK_METHOD0(DoB, void())
MOCK_METHOD1(VoidReturning, void(int n))
MOCK_METHOD0(OverloadedOnArgumentNumber, int())
MOCK_METHOD0(Nullary, int())
MOCK_METHOD0(OverloadedOnConstness, int())
MOCK_METHOD1(TypeWithHole, int(int(*)()))
MOCK_METHOD1(TypeWithComma, int(const std::map< int, std::string > &))
MOCK_METHOD1(OverloadedOnArgumentNumber, int(int))
MOCK_METHOD2(Binary, long(short, int))
MOCK_METHOD1(TakesNonConstReference, bool(int &))
MOCK_METHOD1(TakesConst, bool(const int))
MOCK_CONST_METHOD1(ReturnTypeWithComma, std::map< int, std::string >(int))
MOCK_METHOD1(TakesConstReference, std::string(const int &))
MOCK_METHOD1(Unary, bool(int))
MOCK_CONST_METHOD0(OverloadedOnConstness, char())
MOCK_METHOD10(Decimal, int(bool, char, short, int, long, float, double, unsigned, char *, const std::string &str))
MOCK_METHOD1(OverloadedOnArgumentType, char(char))
MOCK_METHOD1(OverloadedOnArgumentType, int(int))
MOCK_METHOD0(ReturnTypeWithComma, std::map< int, std::string >())
MockOverloadedOnArgNumber()
MockOverloadedOnConstness()
MOCK_METHOD1_T(Push, void(const T &elem))
MOCK_METHOD0_T(ReturnTypeWithComma, std::map< int, int >())
MOCK_METHOD0_T(Pop, void())
MOCK_CONST_METHOD0_T(GetSize, int())
MOCK_CONST_METHOD1_T(ReturnTypeWithComma, std::map< int, int >(int))
MOCK_CONST_METHOD0_T(GetTop, const T &())
virtual void Push(const T &value)=0
virtual int GetSize() const =0
virtual ~StackInterface()
virtual const T & GetTop() const =0
#define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m,...)
#define MOCK_METHOD1_WITH_CALLTYPE(ct, m,...)
#define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m,...)
#define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m,...)
#define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m,...)
#define MOCK_METHOD0_WITH_CALLTYPE(ct, m,...)
#define MOCK_METHOD10_WITH_CALLTYPE(ct, m,...)
#define EXPECT_CALL(obj, call)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
#define TEST_F(test_fixture, test_name)
#define EXPECT_EQ(val1, val2)
#define EXPECT_TRUE(condition)
#define TEST(test_case_name, test_name)
#define EXPECT_FALSE(condition)
Matcher< Lhs > TypedEq(const Rhs &rhs)
internal::Lt2Matcher Lt()
PolymorphicAction< internal::ReturnVoidAction > Return()
const internal::AnythingMatcher _
internal::Ge2Matcher Ge()
const T & Const(const T &x)
GTEST_API_ Cardinality AnyNumber()
internal::Eq2Matcher Eq()
internal::ReturnRefAction< R > ReturnRef(R &x)
internal::DoDefaultAction DoDefault()
internal::RefMatcher< T & > Ref(T &x)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
#define T(meth, val, expected)
fc::variant call(const std::string &url, const std::string &path, const T &v)
MOCK_METHOD0(func, void())
MOCK_METHOD1(func, void(int))
MOCK_METHOD2(func, void(int, int))
MOCK_METHOD3(func, void(int, int, int))
MOCK_METHOD4(func, void(int, int, int, int))