From 7121f51944b0f20c4084979b17c4f038efd8b207 Mon Sep 17 00:00:00 2001 From: Ramon Rakow Date: Thu, 7 Jul 2022 15:21:06 -0700 Subject: [PATCH] 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. --- docs/CMock_Summary.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md index 0660619..6386d1f 100644 --- a/docs/CMock_Summary.md +++ b/docs/CMock_Summary.md @@ -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: ---------