43 #endif // GTEST_OS_WINDOWS 47 #include "gmock/gmock.h" 48 #include "gtest/gtest.h" 53 #if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500) 54 # define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS 55 #endif // !GTEST_OS_WINDOWS || (_MSC_VER >= 1500) 58 namespace gmock_generated_function_mockers_test {
82 virtual bool Unary(
int x) = 0;
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 92 #endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS 104 virtual int TypeWithComma(
const std::map<int, string>& a_map) = 0;
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;
112 #endif // GTEST_OS_WINDOWS 128 double,
unsigned,
char*,
const string& str));
133 #ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS 138 MOCK_METHOD0(ReturnTypeWithComma, std::map<int, string>());
140 std::map<int, string>(
int));
158 short d,
int e,
long f,
float g,
double h,
unsigned i,
char* j,
164 std::map<int, string>());
165 #endif // GTEST_OS_WINDOWS 182 foo_->VoidReturning(0);
216 Lt(100), 5U, NULL,
"hi"))
219 EXPECT_EQ(5, foo_->Decimal(
true,
'a', 0, 0, 1, 0, 0, 5, NULL,
"hi"));
235 .WillOnce(
Return(
"Hello"));
237 EXPECT_EQ(
"Hello", foo_->TakesConstReference(a));
240 #ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS 248 #endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS 257 EXPECT_EQ(2, foo_->OverloadedOnArgumentNumber(1));
258 EXPECT_EQ(1, foo_->OverloadedOnArgumentNumber());
268 EXPECT_EQ(1, foo_->OverloadedOnArgumentType(0));
269 EXPECT_EQ(
'b', foo_->OverloadedOnArgumentType(
'a'));
278 EXPECT_EQ(0, foo_->OverloadedOnConstness());
283 const std::map<int, string> a_map;
289 EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma());
290 EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma(42));
317 EXPECT_CALL(mock_foo_, CTDecimal(
true,
'a', 0, 0, 1L, A<float>(),
318 Lt(100), 5U, NULL,
"hi"))
321 EXPECT_EQ(10, foo_->CTDecimal(
true,
'a', 0, 0, 1, 0, 0, 5, NULL,
"hi"));
333 const std::map<int, string> a_map;
337 EXPECT_EQ(a_map, mock_foo_.CTReturnTypeWithComma());
340 #endif // GTEST_OS_WINDOWS 354 TEST(ExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) {
373 template <
typename T>
379 virtual void Push(
const T& value) = 0;
380 virtual void Pop() = 0;
381 virtual int GetSize()
const = 0;
383 virtual const T& GetTop()
const = 0;
386 template <
typename T>
405 TEST(TemplateMockTest, Works) {
427 TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) {
430 const std::map<int, int> a_map;
436 EXPECT_EQ(a_map, mock.ReturnTypeWithComma());
437 EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1));
443 template <
typename T>
444 class StackInterfaceWithCallType {
446 virtual ~StackInterfaceWithCallType() {}
449 STDMETHOD_(
void, Push)(
const T& value) = 0;
450 STDMETHOD_(
void, Pop)() = 0;
451 STDMETHOD_(
int, GetSize)()
const = 0;
453 STDMETHOD_(
const T&, GetTop)()
const = 0;
456 template <
typename T>
457 class MockStackWithCallType :
public StackInterfaceWithCallType<T> {
459 MockStackWithCallType() {}
471 TEST(TemplateMockTestWithCallType, Works) {
472 MockStackWithCallType<int> mock;
492 #endif // GTEST_OS_WINDOWS 494 #define MY_MOCK_METHODS1_ \ 495 MOCK_METHOD0(Overloaded, void()); \ 496 MOCK_CONST_METHOD1(Overloaded, int(int n)); \ 497 MOCK_METHOD2(Overloaded, bool(bool f, int n)) 509 TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
520 #define MY_MOCK_METHODS2_ \ 521 MOCK_CONST_METHOD1(Overloaded, int(int n)); \ 522 MOCK_METHOD1(Overloaded, int(int n)); 534 TEST(OverloadedMockMethodTest, CanOverloadOnConstnessInMacroBody) {
544 TEST(MockFunctionTest, WorksForVoidNullary) {
550 TEST(MockFunctionTest, WorksForNonVoidNullary) {
559 TEST(MockFunctionTest, WorksForVoidUnary) {
565 TEST(MockFunctionTest, WorksForNonVoidBinary) {
577 TEST(MockFunctionTest, WorksFor10Arguments) {
578 MockFunction<int(
bool a0,
char a1,
int a2,
int a3,
int a4,
579 int a5,
int a6,
char a7,
int a8,
bool a9)>
foo;
580 EXPECT_CALL(foo, Call(
_,
'a',
_,
_,
_,
_,
_,
_,
_,
_))
583 EXPECT_EQ(1, foo.Call(
false,
'a', 0, 0, 0, 0, 0,
'b', 0,
true));
584 EXPECT_EQ(2, foo.Call(
true,
'a', 0, 0, 0, 0, 0,
'b', 1,
false));
MockOverloadedOnConstness()
#define MOCK_METHOD0_T(m,...)
#define MOCK_METHOD0(m,...)
#define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m,...)
#define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m,...)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
MockOverloadedOnArgNumber()
virtual bool TakesNonConstReference(int &n)=0
internal::EqMatcher< T > Eq(T x)
#define MOCK_CONST_METHOD0(m,...)
virtual bool Unary(int x)=0
virtual bool TakesConst(const int x)=0
virtual long Binary(short x, int y)=0
#define EXPECT_TRUE(condition)
internal::ReturnRefAction< R > ReturnRef(R &x)
#define MOCK_METHOD0_WITH_CALLTYPE(ct, m,...)
internal::RefMatcher< T & > Ref(T &x)
#define MOCK_METHOD10_WITH_CALLTYPE(ct, m,...)
internal::LtMatcher< Rhs > Lt(Rhs x)
virtual int TypeWithHole(int(*func)())=0
#define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m,...)
#define MOCK_METHOD2(m,...)
#define MOCK_METHOD1_WITH_CALLTYPE(ct, m,...)
#define EXPECT_FALSE(condition)
virtual string TakesConstReference(const int &n)=0
virtual int OverloadedOnConstness()=0
virtual int OverloadedOnArgumentNumber()=0
#define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m,...)
virtual const T & GetTop() const =0
#define MOCK_CONST_METHOD1(m,...)
#define MOCK_METHOD1(m,...)
Matcher< Lhs > TypedEq(const Rhs &rhs)
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
GTEST_API_ Cardinality AnyNumber()
internal::DoDefaultAction DoDefault()
TEST_F(FunctionMockerTest, MocksVoidFunction)
virtual int OverloadedOnArgumentType(int n)=0
#define EXPECT_CALL(obj, call)
virtual int GetSize() const =0
virtual void Push(const T &value)=0
#define MOCK_METHOD10(m,...)
const internal::AnythingMatcher _
#define MOCK_CONST_METHOD0_T(m,...)
#define MOCK_CONST_METHOD1_T(m,...)
virtual ~StackInterface()
internal::GeMatcher< Rhs > Ge(Rhs x)
#define MOCK_METHOD1_T(m,...)
virtual void VoidReturning(int x)=0
TEST(ExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes)
#define EXPECT_EQ(expected, actual)
const T & Const(const T &x)
virtual int TypeWithComma(const std::map< int, string > &a_map)=0
internal::ReturnAction< R > Return(R value)