I have a class that takes a boolean as a reference parameter and gives an integer: < Pre> and I made a fake for this class: I'm having problems setting expectations for this type of function because I return value and Specify the parameters to make my unit tests properly. How do I deal with this type of function with gmock After I thought what I thought, then I tried to solve the documentation: But either I did not understand this example or it was not applicable for this matter. That are disposed of before the event? Thanks in advance. It's hard to get your question! Google mocks 'cook book' samples are so good. Do you want to reuse the implementation for Usually this means that your If you have a second case, then you have You should expect the call to look like this: If you really want to reuse your original classes logic for square fu {public: bar my_bar; Virtual difference myMethod (bool & my_boolean) = 0; } /*...*/Inte Foo :: myMethod (bull & my_boolean) {if (my_bar == faucet) {my_boolean = false; Return -1; } And (my_boolean = true; return 0;}}
class mockfu: public fu {MOCK_METHOD1 (MyMethod, int (bool & my_boolean))}}
using
: test :: setArgpontai; class mockmutter: public mutator {public: MOCK_METHOD2 (mutate , Blank (boolean mutate, int * value)); ...}; ... MockMutator mutator; EXPECT_CALL (mutator, mutate (true, _) .WillOnce (SetArgPointee <1> (5));
Foo: myMethod () , with the duplicate class, or what you do, only for specific call states Want to duplicate the effects (changed by return value and ref parameter)?
FU class is to be changed / tailored, nor should it be directly inherited or behaved, do not know that the way you Define this 'default' behavior for the pure method, but it is doubtful that. You can leave only
= 0 A better approach is to separate a real interface announcement such as:
struct IFoo {virtual inte myMethod (bool & my_boolean) = 0 ; Virtual ~ IFoo () {}}; Square Fu: Public IFoo {// ...}; Class Mockfoo: Public IFoo {MOCK_METHOD1 (myMethod, int (bool & my_boolean)); };
test :: return (value) and
test :: setArgreefree < N & gt; (Value) (it has been found in very useful)
Mokfu Fu; // Expect calls to your Mathith () Return-1 and set the correct EXPECT_CALL (foo, myMethod (_)) by the RIF object. Willon (DoAll (SetArgReferee & lt; 0> (Truth), Return (-1)); Expect to call // myMethod () 0 Return and set the false EXPECT_CALL (foo, myMethod (_)) with the ref argument. Willon (DoAll (SetArgReferee <0> (wrong), returns (0)));
myMethod () , then see again.
No comments:
Post a Comment