Add example for the usage of ReturnThruPtr

I found it difficult to decipher the correct syntax for using ReturnThruPtr, and looking at github issues and google groups messages suggests others have had the same trouble. I suggest this example to explicate the correct usage.
This commit is contained in:
Ramon Rakow
2022-07-07 15:21:06 -07:00
committed by GitHub
parent 1b81269e78
commit 7121f51944
+25
View File
@@ -220,6 +220,31 @@ are queued up and copied into the space being pointed at each time the mock is c
* => `void func_ReturnArrayThruPtr_paramName(val_to_return, len)`
* => `void func_ReturnMemThruPtr_paramName(val_to_return, size)`
For example, consider the following function:
`BOOL divide(uint numerator, uint denominator, int* result){
if (denominator == 0){
return FALSE;
}
*result = numerator/denominator;
return TRUE;
}
`
We might want to mock this function so that regardless of the inputs, it returns TRUE and a result of 23.
We could do so like this:
`int result_1 = 23;
divide_ExpectAnyArgsAndReturn(TRUE);
divide_ReturnThruPtr_result(&result_1);
`
If we want to expect a numerator of 5 and a denominator of 2 and return a result of 42:
`int result_1 = 42;
divide_ExpectAndReturn(5,2,NULL,TRUE);
divide_IgnoreArg_result();
divide_ReturnThruPtr_result(&result_1);
`
Callback:
---------