I need to mock a function which has a pointer-to-pointer argument (thus a ** argument).
I tried somehing lik the following piece of pseudo-code (note: NON_ZERO_ENUM_MEMBER stands for an enum-value with a value not equal to 0)
my_arg_type argument;
argument.enummember = NON_ZERO_ENUM_MEMBER;
EXPECT_CALL( *my_mock, mock_function( _, _ ) )
.times(1)
.WillOnce( DoAll( SetArgPointee<1>( &argument ), Return( 0 ) ) );
This builds OK, but when I run my test argument.enummember is 0.
If I'm correct this is caused by googlemock making a copy of what I want to return and in case of SetArgPointee create a pointer for it (hence that in case of a normal * one can say SetArgPointee( argument) ). But in this case I give an address and that address is than turned into a pointer. But the actual value of the variable is not stored (if my assumption is correct).
Is there a standard way that googlemock can handle ** arguments or do I have to create a more 'global' variable and return the address of that variable?
/edit/ moved my previous edit to the 2nd reply to keep the original question short
Without seeing more of the code, I cannot figure out how your argument.enummember becomes 0. With that said, it should be possible to set the pointer to a pointer argument with google mock.
Start with a simple class (similar to what was noted in the original post).
Then set up a mock class that has a mock method called "run" whose argument is a pointer to a pointer.
Set up some initial conditions
Setup the expectations:
Run:
You should see that, rc = 99 and that a is equal to b (they point to the same address).
This can be verified by print out things like this (before and after the run command).