How can i call my mock method two times with two different argument value
up vote
1
down vote
favorite
Suppose I have to test the mock method GetSegment with exclusive value 0 and 1(two times).
EXPECT_CALL(*mock.get(), GetSegment(refrenceId, _, _, _)).
WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(**exclusive**)));
Thanks,
c++ googletest googlemock gmock
add a comment |
up vote
1
down vote
favorite
Suppose I have to test the mock method GetSegment with exclusive value 0 and 1(two times).
EXPECT_CALL(*mock.get(), GetSegment(refrenceId, _, _, _)).
WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(**exclusive**)));
Thanks,
c++ googletest googlemock gmock
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Suppose I have to test the mock method GetSegment with exclusive value 0 and 1(two times).
EXPECT_CALL(*mock.get(), GetSegment(refrenceId, _, _, _)).
WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(**exclusive**)));
Thanks,
c++ googletest googlemock gmock
Suppose I have to test the mock method GetSegment with exclusive value 0 and 1(two times).
EXPECT_CALL(*mock.get(), GetSegment(refrenceId, _, _, _)).
WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(**exclusive**)));
Thanks,
c++ googletest googlemock gmock
c++ googletest googlemock gmock
edited Nov 10 at 11:08
ACupOfBreadTea
215
215
asked Nov 10 at 11:04
Abhi
83
83
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Just do several WillOnce
- one after another.
Like:
EXPECT_CALL(*mock.get(), GetSegment(refrenceId, _, _, _))
.WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(0))).
.WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(1)));
You can read in doc that WillOnce can be used several times in one EXPECT_CALL:
EXPECT_CALL(mock_object, method(matchers))
.WillOnce(action) *
The simplified example that works:
class MockMM
public:
MOCK_METHOD4(GetSegment, void(int refrenceId, int, int, int* a));
;
TEST(A, A)
MockMM mock;
EXPECT_CALL(mock, GetSegment(1, _, _, _))
.WillOnce(SetArgPointee<3>(0))
.WillOnce(SetArgPointee<3>(1));
int a;
int b;
mock.GetSegment(1, 1, 0, &a);
mock.GetSegment(1, 0, 1, &b);
ASSERT_EQ(0, a);
ASSERT_EQ(1, b);
You might also use sequences:
When you have a long chain of sequential expectations, it's easier to
specify the order using sequences, which don't require you to given
each expectation in the chain a different name. All expected calls in
the same sequence must occur in the order they are specified.
using ::testing::Sequence;
Sequence s1, s2;
...
EXPECT_CALL(foo, Reset())
.InSequence(s1, s2)
.WillOnce(Return(true));
EXPECT_CALL(foo, GetSize())
.InSequence(s1)
.WillOnce(Return(1));
EXPECT_CALL(foo, Describe(A<const char*>()))
.InSequence(s2)
.WillOnce(Return("dummy"));
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Just do several WillOnce
- one after another.
Like:
EXPECT_CALL(*mock.get(), GetSegment(refrenceId, _, _, _))
.WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(0))).
.WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(1)));
You can read in doc that WillOnce can be used several times in one EXPECT_CALL:
EXPECT_CALL(mock_object, method(matchers))
.WillOnce(action) *
The simplified example that works:
class MockMM
public:
MOCK_METHOD4(GetSegment, void(int refrenceId, int, int, int* a));
;
TEST(A, A)
MockMM mock;
EXPECT_CALL(mock, GetSegment(1, _, _, _))
.WillOnce(SetArgPointee<3>(0))
.WillOnce(SetArgPointee<3>(1));
int a;
int b;
mock.GetSegment(1, 1, 0, &a);
mock.GetSegment(1, 0, 1, &b);
ASSERT_EQ(0, a);
ASSERT_EQ(1, b);
You might also use sequences:
When you have a long chain of sequential expectations, it's easier to
specify the order using sequences, which don't require you to given
each expectation in the chain a different name. All expected calls in
the same sequence must occur in the order they are specified.
using ::testing::Sequence;
Sequence s1, s2;
...
EXPECT_CALL(foo, Reset())
.InSequence(s1, s2)
.WillOnce(Return(true));
EXPECT_CALL(foo, GetSize())
.InSequence(s1)
.WillOnce(Return(1));
EXPECT_CALL(foo, Describe(A<const char*>()))
.InSequence(s2)
.WillOnce(Return("dummy"));
add a comment |
up vote
0
down vote
accepted
Just do several WillOnce
- one after another.
Like:
EXPECT_CALL(*mock.get(), GetSegment(refrenceId, _, _, _))
.WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(0))).
.WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(1)));
You can read in doc that WillOnce can be used several times in one EXPECT_CALL:
EXPECT_CALL(mock_object, method(matchers))
.WillOnce(action) *
The simplified example that works:
class MockMM
public:
MOCK_METHOD4(GetSegment, void(int refrenceId, int, int, int* a));
;
TEST(A, A)
MockMM mock;
EXPECT_CALL(mock, GetSegment(1, _, _, _))
.WillOnce(SetArgPointee<3>(0))
.WillOnce(SetArgPointee<3>(1));
int a;
int b;
mock.GetSegment(1, 1, 0, &a);
mock.GetSegment(1, 0, 1, &b);
ASSERT_EQ(0, a);
ASSERT_EQ(1, b);
You might also use sequences:
When you have a long chain of sequential expectations, it's easier to
specify the order using sequences, which don't require you to given
each expectation in the chain a different name. All expected calls in
the same sequence must occur in the order they are specified.
using ::testing::Sequence;
Sequence s1, s2;
...
EXPECT_CALL(foo, Reset())
.InSequence(s1, s2)
.WillOnce(Return(true));
EXPECT_CALL(foo, GetSize())
.InSequence(s1)
.WillOnce(Return(1));
EXPECT_CALL(foo, Describe(A<const char*>()))
.InSequence(s2)
.WillOnce(Return("dummy"));
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Just do several WillOnce
- one after another.
Like:
EXPECT_CALL(*mock.get(), GetSegment(refrenceId, _, _, _))
.WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(0))).
.WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(1)));
You can read in doc that WillOnce can be used several times in one EXPECT_CALL:
EXPECT_CALL(mock_object, method(matchers))
.WillOnce(action) *
The simplified example that works:
class MockMM
public:
MOCK_METHOD4(GetSegment, void(int refrenceId, int, int, int* a));
;
TEST(A, A)
MockMM mock;
EXPECT_CALL(mock, GetSegment(1, _, _, _))
.WillOnce(SetArgPointee<3>(0))
.WillOnce(SetArgPointee<3>(1));
int a;
int b;
mock.GetSegment(1, 1, 0, &a);
mock.GetSegment(1, 0, 1, &b);
ASSERT_EQ(0, a);
ASSERT_EQ(1, b);
You might also use sequences:
When you have a long chain of sequential expectations, it's easier to
specify the order using sequences, which don't require you to given
each expectation in the chain a different name. All expected calls in
the same sequence must occur in the order they are specified.
using ::testing::Sequence;
Sequence s1, s2;
...
EXPECT_CALL(foo, Reset())
.InSequence(s1, s2)
.WillOnce(Return(true));
EXPECT_CALL(foo, GetSize())
.InSequence(s1)
.WillOnce(Return(1));
EXPECT_CALL(foo, Describe(A<const char*>()))
.InSequence(s2)
.WillOnce(Return("dummy"));
Just do several WillOnce
- one after another.
Like:
EXPECT_CALL(*mock.get(), GetSegment(refrenceId, _, _, _))
.WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(0))).
.WillOnce(DoAll(SetArgReferee<1>(numSegment), SetArgPointee<2>(points), SetArgPointee<3>(1)));
You can read in doc that WillOnce can be used several times in one EXPECT_CALL:
EXPECT_CALL(mock_object, method(matchers))
.WillOnce(action) *
The simplified example that works:
class MockMM
public:
MOCK_METHOD4(GetSegment, void(int refrenceId, int, int, int* a));
;
TEST(A, A)
MockMM mock;
EXPECT_CALL(mock, GetSegment(1, _, _, _))
.WillOnce(SetArgPointee<3>(0))
.WillOnce(SetArgPointee<3>(1));
int a;
int b;
mock.GetSegment(1, 1, 0, &a);
mock.GetSegment(1, 0, 1, &b);
ASSERT_EQ(0, a);
ASSERT_EQ(1, b);
You might also use sequences:
When you have a long chain of sequential expectations, it's easier to
specify the order using sequences, which don't require you to given
each expectation in the chain a different name. All expected calls in
the same sequence must occur in the order they are specified.
using ::testing::Sequence;
Sequence s1, s2;
...
EXPECT_CALL(foo, Reset())
.InSequence(s1, s2)
.WillOnce(Return(true));
EXPECT_CALL(foo, GetSize())
.InSequence(s1)
.WillOnce(Return(1));
EXPECT_CALL(foo, Describe(A<const char*>()))
.InSequence(s2)
.WillOnce(Return("dummy"));
answered Nov 14 at 11:38
PiotrNycz
15.5k53780
15.5k53780
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238299%2fhow-can-i-call-my-mock-method-two-times-with-two-different-argument-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown