42 #endif // GTEST_OS_WINDOWS
50 namespace gmock_generated_function_mockers_test {
60 using testing::MockFunction;
64 using testing::TypedEq;
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,
102 virtual int TypeWithComma(
const std::map<int, std::string>& a_map) = 0;
107 STDMETHOD_(
int, CTNullary)() = 0;
108 STDMETHOD_(
bool, CTUnary)(
int x) = 0;
109 STDMETHOD_(
int, CTDecimal)
110 (
bool b,
char c,
short d,
int e,
long f,
111 float g,
double h,
unsigned i,
char* j,
const std::string& k) = 0;
112 STDMETHOD_(
char, CTConst)(
int x)
const = 0;
113 #endif // GTEST_OS_WINDOWS
121 # pragma warning(push)
122 # pragma warning(disable : 4373)
144 MOCK_METHOD0(ReturnTypeWithComma, std::map<int, std::string>());
146 std::map<int, std::string>(
int));
159 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,
174 std::map<int, std::string>());
175 #endif // GTEST_OS_WINDOWS
181 # pragma warning(pop)
195 foo_->VoidReturning(0);
228 EXPECT_CALL(mock_foo_, Decimal(
true,
'a', 0, 0, 1L, A<float>(), Lt(100), 5U,
232 EXPECT_EQ(5, foo_->Decimal(
true,
'a', 0, 0, 1, 0, 0, 5,
nullptr,
"hi"));
248 .WillOnce(
Return(
"Hello"));
250 EXPECT_EQ(
"Hello", foo_->TakesConstReference(
a));
263 EXPECT_CALL(mock_foo_, OverloadedOnArgumentNumber())
268 EXPECT_EQ(2, foo_->OverloadedOnArgumentNumber(1));
269 EXPECT_EQ(1, foo_->OverloadedOnArgumentNumber());
274 EXPECT_CALL(mock_foo_, OverloadedOnArgumentType(An<int>()))
276 EXPECT_CALL(mock_foo_, OverloadedOnArgumentType(TypedEq<char>(
'a')))
279 EXPECT_EQ(1, foo_->OverloadedOnArgumentType(0));
280 EXPECT_EQ(
'b', foo_->OverloadedOnArgumentType(
'a'));
286 EXPECT_CALL(Const(mock_foo_), OverloadedOnConstness())
289 EXPECT_EQ(0, foo_->OverloadedOnConstness());
290 EXPECT_EQ(
'a', Const(*foo_).OverloadedOnConstness());
294 const std::map<int, std::string> a_map;
300 EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma());
301 EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma(42));
311 TEST_F(FunctionMockerTest, MocksNullaryFunctionWithCallType) {
321 TEST_F(FunctionMockerTest, MocksUnaryFunctionWithCallType) {
332 TEST_F(FunctionMockerTest, MocksDecimalFunctionWithCallType) {
337 EXPECT_EQ(10, foo_->CTDecimal(
true,
'a', 0, 0, 1, 0, 0, 5,
nullptr,
"hi"));
341 TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
348 TEST_F(FunctionMockerTest, MocksReturnTypeWithCommaAndCallType) {
349 const std::map<int, std::string> a_map;
353 EXPECT_EQ(a_map, mock_foo_.CTReturnTypeWithComma());
356 #endif // GTEST_OS_WINDOWS
370 TEST(ExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) {
389 template <
typename T>
396 virtual void Pop() = 0;
397 virtual int GetSize()
const = 0;
399 virtual const T&
GetTop()
const = 0;
402 template <
typename T>
421 TEST(TemplateMockTest, Works) {
443 TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) {
446 const std::map<int, int> a_map;
452 EXPECT_EQ(a_map, mock.ReturnTypeWithComma());
453 EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1));
459 template <
typename T>
460 class StackInterfaceWithCallType {
462 virtual ~StackInterfaceWithCallType() {}
465 STDMETHOD_(
void, Push)(
const T&
value) = 0;
466 STDMETHOD_(
void,
Pop)() = 0;
467 STDMETHOD_(
int, GetSize)()
const = 0;
469 STDMETHOD_(
const T&, GetTop)()
const = 0;
472 template <
typename T>
473 class MockStackWithCallType :
public StackInterfaceWithCallType<T> {
475 MockStackWithCallType() {}
487 TEST(TemplateMockTestWithCallType, Works) {
488 MockStackWithCallType<int> mock;
508 #endif // GTEST_OS_WINDOWS
510 #define MY_MOCK_METHODS1_ \
511 MOCK_METHOD0(Overloaded, void()); \
512 MOCK_CONST_METHOD1(Overloaded, int(int n)); \
513 MOCK_METHOD2(Overloaded, bool(bool f, int n))
525 TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
536 #define MY_MOCK_METHODS2_ \
537 MOCK_CONST_METHOD1(Overloaded, int(int n)); \
538 MOCK_METHOD1(Overloaded, int(int n));
550 TEST(OverloadedMockMethodTest, CanOverloadOnConstnessInMacroBody) {
560 TEST(MockFunctionTest, WorksForVoidNullary) {
566 TEST(MockFunctionTest, WorksForNonVoidNullary) {
567 MockFunction<int()>
foo;
575 TEST(MockFunctionTest, WorksForVoidUnary) {
581 TEST(MockFunctionTest, WorksForNonVoidBinary) {
582 MockFunction<int(
bool,
int)>
foo;
593 TEST(MockFunctionTest, WorksFor10Arguments) {
594 MockFunction<int(
bool a0,
char a1,
int a2,
int a3,
int a4,
595 int a5,
int a6,
char a7,
int a8,
bool a9)>
foo;
596 EXPECT_CALL(
foo, Call(
_,
'a',
_,
_,
_,
_,
_,
_,
_,
_))
599 EXPECT_EQ(1,
foo.Call(
false,
'a', 0, 0, 0, 0, 0,
'b', 0,
true));
600 EXPECT_EQ(2,
foo.Call(
true,
'a', 0, 0, 0, 0, 0,
'b', 1,
false));
603 TEST(MockFunctionTest, AsStdFunction) {
604 MockFunction<int(
int)>
foo;
605 auto call = [](
const std::function<int(
int)> &
f,
int i) {
614 TEST(MockFunctionTest, AsStdFunctionReturnsReference) {
615 MockFunction<
int&()>
foo;
618 int&
ref =
foo.AsStdFunction()();
624 TEST(MockFunctionTest, AsStdFunctionWithReferenceParameter) {
625 MockFunction<int(
int &)>
foo;
626 auto call = [](
const std::function<int(
int& )> &
f,
int &
i) {
651 TEST(MockFunctionTest, MockMethodSizeOverhead) {