Comments (3)
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 [email protected]
on 25 Dec 2008 at 4:50
from googlemock.
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 [email protected]
on 25 Dec 2008 at 4:56
from googlemock.
This is by design. DoAll() is the intended solution.
Original comment by [email protected]
on 26 Dec 2008 at 6:56
- Changed state: WontFix
from googlemock.
Related Issues (20)
- Make thread-safe on Windows HOT 2
- Use override keyword with new C++11 compilers HOT 15
- MOCK_METHOD with an std::pair argument doesn't compile with VS2010 HOT 11
- got segmentation error in Linux, When gtest library is linked from /usr/lib/lgtest HOT 1
- Visual Studio 10 release link fails
- smart pointers are leaked with InSequence
- [deleted issue]
- Enable make install, just set the library to nodist.
- complie 1.7 with vs 2010 fail HOT 2
- Crash caused by missing lock HOT 4
- Suport for Variadic Templates
- Building fails on r477 HOT 1
- Is it possible to mock function template methods? HOT 1
- looser throw specifier for
- Infinite Loop when calling a mock function that takes boost::filesystem::path as parameter HOT 5
- Throwing an exception as default breaks call count expectation
- MatchAndExplainImpl fails to compile with VC++ 2013 /analyze HOT 1
- FormatTimeInMillisAsSeconds in gtest/src/gtest.cc:3504 causes compile errors when using conversion checking HOT 3
- moving to GITHUB ?
- Multiple GCC warnings on TypedEq HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from googlemock.