aboutsummaryrefslogtreecommitdiff
path: root/include
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 /include
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 'include')
-rw-r--r--include/cmocka.h35
1 files changed, 32 insertions, 3 deletions
diff --git a/include/cmocka.h b/include/cmocka.h
index 6242ff2..fecd873 100644
--- a/include/cmocka.h
+++ b/include/cmocka.h
@@ -304,9 +304,11 @@ void will_return(#function, LargestIntegralType value);
*
* @param[in] value The value to be returned by mock().
*
- * @param[in] count The parameter returns the number of times the value should
- * be returned by mock(). If count is set to -1 the value will
- * always be returned.
+ * @param[in] count The parameter indicates the number of times the value should
+ * be returned by mock(). If count is set to -1, the value
+ * will always be returned but must be returned at least once.
+ * If count is set to -2, the value will always be returned
+ * by mock(), but is not required to be returned.
*
* @see mock()
*/
@@ -339,6 +341,33 @@ void will_return_always(#function, LargestIntegralType value);
will_return_count(function, (value), -1)
#endif
+#ifdef DOXYGEN
+/**
+ * @brief Store a value that may be always returned by mock().
+ *
+ * This stores a value which will always be returned by mock() but is not
+ * required to be returned by at least one call to mock(). Therefore,
+ * in contrast to will_return_always() which causes a test failure if it
+ * is not returned at least once, will_return_maybe() will never cause a test
+ * to fail if its value is not returned.
+ *
+ * @param[in] #function The function which should return the given value.
+ *
+ * @param[in] #value The value to be returned by mock().
+ *
+ * This is equivalent to:
+ * @code
+ * will_return_count(function, value, -2);
+ * @endcode
+ *
+ * @see will_return_count()
+ * @see mock()
+ */
+void will_return_maybe(#function, LargestIntegralType value);
+#else
+#define will_return_maybe(function, value) \
+ will_return_count(function, (value), -2)
+#endif
/** @} */
/**