Closed GoogleCodeExporter closed 9 years ago
Was rereading the docs and see a comment in the Section Combining Actions in
Cookbook:
It says " Only the return value of the last action in the sequence will be
used."
So I am thinking that the only way to correctly return an output param for a
function
that returns a non void type is to use a DoAll with the SetArgumentPointee
first in
the list of combined actions and the Return action last. Makes sense when I
think
about it and having looked at the code some more I see that is how it works.
Looks
like this is not a problem afterall.
Original comment by ecurbks...@gmail.com
on 25 Dec 2008 at 4:50
So my corrected code would be:
#include <gmock/gmock.h>
#include <memory>
using testing::_;
using testing::Return;
using testing::Action;
using testing::ActionInterface;
using testing::MakeAction;
using testing::DoAll;
using testing::SetArgumentPointee;
using testing::internal::Function;
class Foo
{
public:
virtual bool func(int*) = 0;
};
class MockFoo : public Foo
{
public:
MOCK_METHOD1(func, bool(int*));
};
class Bar
{
public:
explicit Bar(Foo* pFoo) : m_pFoo(pFoo)
{
}
int CallIt()
{
int i = 0;
m_pFoo->func(&i);
return i;
}
Foo* m_pFoo;
};
TEST(Testitout, argpointee)
{
MockFoo foo;
EXPECT_CALL(foo, func(_))
.WillOnce(DoAll(SetArgumentPointee<0>(5),Return(true)));
Bar bar(&foo);
EXPECT_EQ(5, bar.CallIt());
}
int main(int argc, char **argv) {
std::cout << "Running main() from gtest_main.cc\n";
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Original comment by ecurbks...@gmail.com
on 25 Dec 2008 at 4:56
This is by design. DoAll() is the intended solution.
Original comment by shiq...@gmail.com
on 26 Dec 2008 at 6:56
Original issue reported on code.google.com by
ecurbks...@gmail.com
on 25 Dec 2008 at 2:09