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)
- CMake Error in CMakeLists.txt HOT 2
- Mocking class and callbacks funcitons in 'anonymous namespace'
- test.camke line 16 add_library path error
- Don't throw nested exception from dtor of Mock object
- Gmock test fails(should pass?) HOT 1
- Problems when running tests with mock objects on Open BSD
- Unwanted warning when compiling with Clang HOT 2
- Ability to deinitialize googlemock
- ubhf
- gmock_ex_test.cc fails if exceptions are disabled HOT 1
- This project is still the top hit for [googlemock]
- Leakable mock object isn't really leaked HOT 1
- Pointee with overloaded functions
- Matching std::reference_wrapper objects with RefMatcher yields SEH exceptions or undefined behavior
- Compilation error:
- Mock class generation by running the script
- Misleading documentation about regular expression matcher HOT 2
- redefinition of function IgnoredValue
- How do you know how many times EXPECT_CALL(). Times (3) has been called?
- Warning reported from clang tidy on Call to virtual function during destruction
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.