From 7121f51944b0f20c4084979b17c4f038efd8b207 Mon Sep 17 00:00:00 2001 From: Ramon Rakow Date: Thu, 7 Jul 2022 15:21:06 -0700 Subject: [PATCH 1/3] 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: --------- From 406a9bcf2eef43c1e58446faecf12e66e902ab88 Mon Sep 17 00:00:00 2001 From: Ramon Rakow Date: Fri, 8 Jul 2022 09:10:45 -0700 Subject: [PATCH 2/3] Update CMock_Summary.md --- docs/CMock_Summary.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md index 6386d1f..39e3f54 100644 --- a/docs/CMock_Summary.md +++ b/docs/CMock_Summary.md @@ -222,7 +222,7 @@ are queued up and copied into the space being pointed at each time the mock is c For example, consider the following function: -`BOOL divide(uint numerator, uint denominator, int* result){ +`BOOL divide(uint numerator, uint denominator, uint* result){ if (denominator == 0){ return FALSE; } From c532d17f9e03bf5012767670822c1bded907cf8b Mon Sep 17 00:00:00 2001 From: Ramon Rakow Date: Fri, 8 Jul 2022 09:11:48 -0700 Subject: [PATCH 3/3] Update CMock_Summary.md --- docs/CMock_Summary.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md index 39e3f54..e63a065 100644 --- a/docs/CMock_Summary.md +++ b/docs/CMock_Summary.md @@ -234,13 +234,13 @@ For example, consider the following function: 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; +`uint 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; +`uint result_1 = 42; divide_ExpectAndReturn(5,2,NULL,TRUE); divide_IgnoreArg_result(); divide_ReturnThruPtr_result(&result_1);