diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2013-06-03 18:42:33 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2013-06-04 10:36:49 +0200 |
commit | bccf090fb79ee41e4c614bf91bad3910a74a0dc3 (patch) | |
tree | 466bc5c6dfcf764a5499c84e496be479a1f800a9 /include | |
parent | 7c221a9a18cf9057c2a17d66eaf1107fcf5efe42 (diff) | |
download | cmocka-bccf090fb79ee41e4c614bf91bad3910a74a0dc3.tar.gz cmocka-bccf090fb79ee41e4c614bf91bad3910a74a0dc3.tar.bz2 cmocka-bccf090fb79ee41e4c614bf91bad3910a74a0dc3.zip |
Add new macros mock_type and mock_ptr_type
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/cmocka.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/include/cmocka.h b/include/cmocka.h index cc53cc0..a55acbc 100644 --- a/include/cmocka.h +++ b/include/cmocka.h @@ -150,6 +150,60 @@ void *mock(void); #ifdef DOXYGEN /** + * @brief Retrieve a typed return value of the current function. + * + * The value would be casted to type internally to avoid having the + * caller to do the cast manually. + * + * @param[in] #type The expected type of the return value + * + * @return The value which was stored to return by this function. + * + * @code + * int param; + * + * param = mock_type(int); + * @endcode + * + * @see will_return() + * @see mock() + * @see mock_ptr_type() + */ +void *mock_type(#type); +#else +#define mock_type(type) ((type) mock()) +#endif + +#ifdef DOXYGEN +/** + * @brief Retrieve a typed return value of the current function. + * + * The value would be casted to type internally to avoid having the + * caller to do the cast manually but also casted to uintptr_t to make + * sure the result has a valid size to be used as a pointer. + * + * @param[in] #type The expected type of the return value + * + * @return The value which was stored to return by this function. + * + * @code + * char *param; + * + * param = mock_ptr_type(char *); + * @endcode + * + * @see will_return() + * @see mock() + * @see mock_type() + */ +void *mock_ptr_type(#type); +#else +#define mock_ptr_type(type) ((type) (uintptr_t) mock()) +#endif + + +#ifdef DOXYGEN +/** * @brief Store a value to be returned by mock() later. * * @param[in] #function The function which should return the given value. |