48#include "gtest/gtest.h"
53#if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
54# define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
83 virtual long Binary(
short x,
int y) = 0;
84 virtual int Decimal(
bool b,
char c,
short d,
int e,
long f,
85 float g,
double h,
unsigned i,
char* j,
const string& k)
90#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
107 STDMETHOD_(
int, CTNullary)() = 0;
108 STDMETHOD_(
bool, CTUnary)(
int x) = 0;
109 STDMETHOD_(
int, CTDecimal)(
bool b,
char c,
short d,
int e,
long f,
110 float g,
double h,
unsigned i,
char* j,
const 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 string&
str));
141#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
148 std::map<int, string>(
int));
166 short d,
int e,
long f,
float g,
double h,
unsigned i,
char* j,
172 std::map<int, string>());
193 foo_->VoidReturning(0);
227 Lt(100), 5U, NULL,
"hi"))
230 EXPECT_EQ(5, foo_->Decimal(
true,
'a', 0, 0, 1, 0, 0, 5, NULL,
"hi"));
246 .WillOnce(
Return(
"Hello"));
248 EXPECT_EQ(
"Hello", foo_->TakesConstReference(
a));
251#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
263 EXPECT_CALL(mock_foo_, OverloadedOnArgumentNumber())
268 EXPECT_EQ(2, foo_->OverloadedOnArgumentNumber(1));
269 EXPECT_EQ(1, foo_->OverloadedOnArgumentNumber());
279 EXPECT_EQ(1, foo_->OverloadedOnArgumentType(0));
280 EXPECT_EQ(
'b', foo_->OverloadedOnArgumentType(
'a'));
289 EXPECT_EQ(0, foo_->OverloadedOnConstness());
294 const std::map<int, string> a_map;
300 EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma());
301 EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma(42));
306TEST_F(FunctionMockerTest, MocksNullaryFunctionWithCallType) {
316TEST_F(FunctionMockerTest, MocksUnaryFunctionWithCallType) {
329 Lt(100), 5U, NULL,
"hi"))
332 EXPECT_EQ(10, foo_->CTDecimal(
true,
'a', 0, 0, 1, 0, 0, 5, NULL,
"hi"));
344 const std::map<int, string> a_map;
348 EXPECT_EQ(a_map, mock_foo_.CTReturnTypeWithComma());
365TEST(ExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) {
438TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) {
441 const std::map<int, int> a_map;
447 EXPECT_EQ(a_map, mock.ReturnTypeWithComma());
448 EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1));
455class StackInterfaceWithCallType {
457 virtual ~StackInterfaceWithCallType() {}
460 STDMETHOD_(
void, Push)(
const T&
value) = 0;
461 STDMETHOD_(
void, Pop)() = 0;
462 STDMETHOD_(
int, GetSize)()
const = 0;
464 STDMETHOD_(
const T&, GetTop)()
const = 0;
468class MockStackWithCallType :
public StackInterfaceWithCallType<T> {
470 MockStackWithCallType() {}
482TEST(TemplateMockTestWithCallType, Works) {
483 MockStackWithCallType<int> mock;
505#define MY_MOCK_METHODS1_ \
506 MOCK_METHOD0(Overloaded, void()); \
507 MOCK_CONST_METHOD1(Overloaded, int(int n)); \
508 MOCK_METHOD2(Overloaded, bool(bool f, int n))
520TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
531#define MY_MOCK_METHODS2_ \
532 MOCK_CONST_METHOD1(Overloaded, int(int n)); \
533 MOCK_METHOD1(Overloaded, int(int n));
545TEST(OverloadedMockMethodTest, CanOverloadOnConstnessInMacroBody) {
555TEST(MockFunctionTest, WorksForVoidNullary) {
561TEST(MockFunctionTest, WorksForNonVoidNullary) {
570TEST(MockFunctionTest, WorksForVoidUnary) {
576TEST(MockFunctionTest, WorksForNonVoidBinary) {
588TEST(MockFunctionTest, WorksFor10Arguments) {
589 MockFunction<int(
bool a0,
char a1,
int a2,
int a3,
int a4,
590 int a5,
int a6,
char a7,
int a8,
bool a9)>
foo;
591 EXPECT_CALL(
foo, Call(
_,
'a',
_,
_,
_,
_,
_,
_,
_,
_))
594 EXPECT_EQ(1,
foo.Call(
false,
'a', 0, 0, 0, 0, 0,
'b', 0,
true));
595 EXPECT_EQ(2,
foo.Call(
true,
'a', 0, 0, 0, 0, 0,
'b', 1,
false));
598#if GTEST_HAS_STD_FUNCTION_
599TEST(MockFunctionTest, AsStdFunction) {
601 auto call = [](
const std::function<int(
int)> &f,
int i) {
610TEST(MockFunctionTest, AsStdFunctionReturnsReference) {
614 int& ref =
foo.AsStdFunction()();
cryptonote::block b
Definition block.cpp:40
static uint64_t h
Definition blockchain_stats.cpp:55
Definition gmock-generated-function-mockers.h:873
Definition gmock-generated-function-mockers_test.cc:75
virtual int OverloadedOnArgumentNumber(int n)=0
virtual string TakesConstReference(const 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 string &k)=0
virtual int TypeWithComma(const std::map< int, 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 char OverloadedOnConstness() const =0
virtual ~FooInterface()
Definition gmock-generated-function-mockers_test.cc:77
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
Definition gmock-generated-function-mockers_test.cc:182
FunctionMockerTest()
Definition gmock-generated-function-mockers_test.cc:184
MockFoo mock_foo_
Definition gmock-generated-function-mockers_test.cc:187
FooInterface *const foo_
Definition gmock-generated-function-mockers_test.cc:186
Definition gmock-generated-function-mockers_test.cc:353
MockB()
Definition gmock-generated-function-mockers_test.cc:355
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockB)
MOCK_METHOD0(DoB, void())
Definition gmock-generated-function-mockers_test.cc:123
MOCK_METHOD1(VoidReturning, void(int n))
MockFoo()
Definition gmock-generated-function-mockers_test.cc:125
MOCK_METHOD0(OverloadedOnArgumentNumber, int())
MOCK_METHOD0(Nullary, int())
MOCK_METHOD0(OverloadedOnConstness, int())
MOCK_METHOD1(TypeWithHole, int(int(*)()))
MOCK_METHOD1(OverloadedOnArgumentNumber, int(int))
MOCK_METHOD2(Binary, long(short, int))
MOCK_METHOD0(ReturnTypeWithComma, std::map< int, string >())
MOCK_METHOD1(TakesConstReference, string(const int &))
MOCK_CONST_METHOD1(ReturnTypeWithComma, std::map< int, string >(int))
MOCK_METHOD1(TakesNonConstReference, bool(int &))
MOCK_METHOD1(TakesConst, bool(const int))
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo)
MOCK_METHOD1(Unary, bool(int))
MOCK_CONST_METHOD0(OverloadedOnConstness, char())
MOCK_METHOD1(OverloadedOnArgumentType, char(char))
MOCK_METHOD1(TypeWithComma, int(const std::map< int, string > &))
MOCK_METHOD1(OverloadedOnArgumentType, int(int))
MOCK_METHOD10(Decimal, int(bool, char, short, int, long, float, double, unsigned, char *, const string &str))
Definition gmock-generated-function-mockers_test.cc:510
MY_MOCK_METHODS1_
Definition gmock-generated-function-mockers_test.cc:514
MockOverloadedOnArgNumber()
Definition gmock-generated-function-mockers_test.cc:512
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnArgNumber)
Definition gmock-generated-function-mockers_test.cc:535
MY_MOCK_METHODS2_
Definition gmock-generated-function-mockers_test.cc:539
MockOverloadedOnConstness()
Definition gmock-generated-function-mockers_test.cc:537
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnConstness)
Definition gmock-generated-function-mockers_test.cc:398
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))
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStack)
MockStack()
Definition gmock-generated-function-mockers_test.cc:400
MOCK_CONST_METHOD0_T(GetTop, const T &())
Definition gmock-generated-function-mockers_test.cc:385
virtual void Push(const T &value)=0
virtual int GetSize() const =0
virtual ~StackInterface()
Definition gmock-generated-function-mockers_test.cc:387
virtual const T & GetTop() const =0
#define TEST_F(test_fixture, test_name)
Definition gtest.h:2216
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1922
#define EXPECT_TRUE(condition)
Definition gtest.h:1859
#define TEST(test_case_name, test_name)
Definition gtest.h:2187
#define EXPECT_FALSE(condition)
Definition gtest.h:1862
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition gtest-port.h:874
#define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m,...)
Definition gmock-generated-function-mockers.h:782
#define MOCK_METHOD1_WITH_CALLTYPE(ct, m,...)
Definition gmock-generated-function-mockers.h:736
#define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m,...)
Definition gmock-generated-function-mockers.h:803
#define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m,...)
Definition gmock-generated-function-mockers.h:780
#define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m,...)
Definition gmock-generated-function-mockers.h:759
#define MOCK_METHOD0_WITH_CALLTYPE(ct, m,...)
Definition gmock-generated-function-mockers.h:734
#define MOCK_METHOD10_WITH_CALLTYPE(ct, m,...)
Definition gmock-generated-function-mockers.h:754
#define EXPECT_CALL(obj, call)
Definition gmock-spec-builders.h:1845
Definition gtest-printers_test.cc:126
Definition gmock-generated-function-mockers_test.cc:58
Matcher< Lhs > TypedEq(const Rhs &rhs)
Definition gmock-matchers.h:3762
Matcher< T > An()
Definition gmock-matchers.h:3736
const internal::AnythingMatcher _
Definition gmock-matchers.h:3729
const T & Const(const T &x)
Definition gmock-spec-builders.h:1826
GTEST_API_ Cardinality AnyNumber()
Definition gmock-cardinalities.cc:146
internal::ReturnRefAction< R > ReturnRef(R &x)
Definition gmock-actions.h:1077
internal::DoDefaultAction DoDefault()
Definition gmock-actions.h:1099
internal::RefMatcher< T & > Ref(T &x)
Definition gmock-matchers.h:3809
const int foo
Definition gmock-matchers_test.cc:2448
::std::string string
Definition gtest-port.h:1097
Definition gmock-actions.h:53
Matcher< Lhs > TypedEq(const Rhs &rhs)
Definition gmock-matchers.h:3762
Matcher< T > An()
Definition gmock-matchers.h:3736
internal::EqMatcher< T > Eq(T x)
Definition gmock-matchers.h:3742
internal::LtMatcher< Rhs > Lt(Rhs x)
Definition gmock-matchers.h:3784
internal::Lt2Matcher Lt()
Definition gmock-matchers.h:4098
PolymorphicAction< internal::ReturnVoidAction > Return()
Definition gmock-actions.h:1071
const internal::AnythingMatcher _
Definition gmock-matchers.h:3729
Matcher< T > A()
Definition gmock-matchers.h:3732
internal::Ge2Matcher Ge()
Definition gmock-matchers.h:4086
const T & Const(const T &x)
Definition gmock-spec-builders.h:1826
GTEST_API_ Cardinality AnyNumber()
Definition gmock-cardinalities.cc:146
internal::Eq2Matcher Eq()
Definition gmock-matchers.h:4082
internal::ReturnRefAction< R > ReturnRef(R &x)
Definition gmock-actions.h:1077
internal::ReturnAction< R > Return(R value)
Definition gmock-actions.h:1061
internal::DoDefaultAction DoDefault()
Definition gmock-actions.h:1099
internal::RefMatcher< T & > Ref(T &x)
Definition gmock-matchers.h:3809
const GenericPointer< typename T::ValueType > T2 value
Definition pointer.h:1225
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
const char *const str
Definition portlistingparse.c:23