KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a class that takes a boolean as a reference parameter and returns an integer: class Foo { public: Bar my_bar; virtual int myMethod(bool &my_boolean) = 0; } /*...*/ int Foo::myMethod(bool &my_boolean){ if (my_bar == NULL){ my_boolean = false; return -1; } else{ my_boolean = true; return 0; } } And I created a mock for this class: class MockFoo : public Foo { MOCK_METHOD1(myMethod,int(bool &my_boolean)); } I'm having problems on how to set the expectations for this kind of function,because I need to set the return value and the reference parameter to specific values to properly create my unit tests.How can I deal with this kind of function with gmock?I tried following what I thought was the solution on the documentation: using ::testing::SetArgPointee; class MockMutator : public Mutator { public: MOCK_METHOD2(Mutate, void(bool mutate, int* value)); ... }; ... MockMutator mutator; EXPECT_CALL(mutator, Mutate(true, _)) .WillOnce(SetArgPointee<1>(5)); But either I didn't understood the example or it wasn't applicable for this case.Has anyone dealt whith this kind of situation before? Thanks in advance.
Tags (comma-separated)
Save Edits
Cancel