aboutsummaryrefslogtreecommitdiff
path: root/src/cmocka.c
diff options
context:
space:
mode:
authorJoseph Ates <joseph.ates@msasafety.com>2016-02-10 12:16:13 +0100
committerAndreas Schneider <asn@cryptomilk.org>2016-02-10 13:18:11 +0100
commitf8bba4b3a519147de59a2a7c3dc6262549e7e2bb (patch)
tree646f92fcc8b778916a6b380e06ab7bef2cb857da /src/cmocka.c
parentc971d6e5c26549c421d7fc4cc2965cea4c628866 (diff)
downloadcmocka-f8bba4b3a519147de59a2a7c3dc6262549e7e2bb.tar.gz
cmocka-f8bba4b3a519147de59a2a7c3dc6262549e7e2bb.tar.xz
cmocka-f8bba4b3a519147de59a2a7c3dc6262549e7e2bb.zip
cmocka: Add will_return_maybe() for ignoring mock returns
As both parameter and function call order checking allow for ignoring cases where they are never invoked, the mock return values are at somewhat of a mismatch in that they must always be returned at least once (even in the case of will_return_always()). Therefore, the ability to set the count to -2 on will_return_count was added with a new macro (will_return_maybe) that indicates that that the value field may never be returned and still allow a successful test. Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/cmocka.c')
-rw-r--r--src/cmocka.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/cmocka.c b/src/cmocka.c
index 4f13f21..376acba 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -689,8 +689,10 @@ static int get_symbol_value(
assert_true(return_value);
*output = (void*) value_node->value;
return_value = value_node->refcount;
- if (--value_node->refcount == 0) {
+ if (value_node->refcount - 1 == 0) {
list_remove_free(value_node, NULL, NULL);
+ } else if (value_node->refcount > -2) {
+ --value_node->refcount;
}
} else {
return_value = get_symbol_value(
@@ -943,7 +945,7 @@ void _will_return(const char * const function_name, const char * const file,
const int count) {
SymbolValue * const return_value =
(SymbolValue*)malloc(sizeof(*return_value));
- assert_true(count > 0 || count == -1);
+ assert_true(count != 0);
return_value->value = value;
set_source_location(&return_value->location, file, line);
add_symbol_value(&global_function_result_map_head, &function_name, 1,