Loading...
Searching...
No Matches
cmocka.h
/*
* Copyright 2008 Google Inc.
* Copyright 2014-2022 Andreas Schneider <asn@cryptomilk.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CMOCKA_H_
#define CMOCKA_H_
#ifdef _WIN32
# ifdef _MSC_VER
# ifndef CMOCKA_STATIC
# ifdef CMOCKA_EXPORTS
#define CMOCKA_DLLEXTERN __declspec(dllexport)
# else
#define CMOCKA_DLLEXTERN __declspec(dllimport)
# endif /* CMOCKA_EXPORTS */
# endif /* ndef CMOCKA_STATIC */
#ifndef __func__
#define __func__ __FUNCTION__
#endif /* __func__ */
#ifndef inline
#define inline __inline
#endif /* inline */
# endif /* _MSC_VER */
#endif /* _WIN32 */
#ifndef CMOCKA_DLLEXTERN
#define CMOCKA_DLLEXTERN // only needed on MSVC compiler when using a DLL
#endif /* ndef CMOCKA_DLLEXTERN */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef CMOCKA_NO_STANDARD_INCLUDES
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#endif
/* Perform an signed cast to intmax_t. */
#define cast_to_intmax_type(value) \
((intmax_t)(value))
/* Perform an unsigned cast to uintmax_t. */
#define cast_to_uintmax_type(value) \
((uintmax_t)(value))
/* Perform a safe cast from pointer to uintmax_t. */
#define cast_ptr_to_uintmax_type(value) \
((uintmax_t)(uintptr_t)(value))
/* Perform cast to double. */
#define cast_to_double_type(value) \
((double)(value))
/* Perform cast to float. */
#define cast_to_float_type(value) \
((float)(value))
#define cast_to_void_pointer(ptr) \
((void *)(uintptr_t)(ptr))
#define cast_int_to_cmocka_value(value) \
(CMockaValueData) \
{ \
.uint_val = (uintmax_t)(value) \
}
#define cast_ptr_to_cmocka_value(value) \
(CMockaValueData) \
{ \
.const_ptr = (value) \
}
#define assign_int_to_cmocka_value(value) \
(CMockaValueData) \
{ \
.int_val = (value) \
}
#define assign_uint_to_cmocka_value(value) \
(CMockaValueData) \
{ \
.uint_val = (value) \
}
#define assign_float_to_cmocka_value(value) \
(CMockaValueData) \
{ \
.float_val = ((float)(value)) \
}
#define assign_double_to_cmocka_value(value) \
(CMockaValueData) \
{ \
.real_val = ((double)(value)) \
}
/* Nested macros are not expanded when they appear along with # or ## */
#define cmocka_tostring(val) #val
/* GCC have printf type attribute check. */
#ifdef __GNUC__
#define CMOCKA_PRINTF_ATTRIBUTE(a,b) \
__attribute__ ((__format__ (__printf__, a, b)))
#else
#define CMOCKA_PRINTF_ATTRIBUTE(a,b)
#endif /* __GNUC__ */
#if defined(CMOCKA_DISABLE_DEPRECATION_WARNINGS) || defined(CMOCKA_DISABLE_DEPRECTATION_WARNINGS)
#define CMOCKA_DEPRECATED
#define CMOCKA_DEPRECATION_WARNING(msg)
#else /* CMOCKA_DISABLE_DEPRECATION_WARNINGS */
/* Deprecation warnings for functions */
#if defined(__GNUC__)
#define CMOCKA_DEPRECATED __attribute__ ((deprecated))
#else
/* MSVC requires __declspec(deprecated) before the function declaration,
* not after it. Since we already use CMOCKA_DEPRECATION_WARNING() in
* the macro wrappers, we don't need function-level deprecation for MSVC. */
#define CMOCKA_DEPRECATED
#endif
/* Deprecation warnings for macros */
#if defined(__GNUC__) || defined(__clang__)
/* Use a deprecated typedef in a statement expression to generate warnings
* that work even when the header is included as a system header (-isystem).
*/
#define CMOCKA_DEPRECATION_WARNING(msg) \
__extension__({ \
typedef int cmocka_macro __attribute__((deprecated(msg))); \
cmocka_macro cmocka_deprecated_var __attribute__((unused)) = 0; \
(void)sizeof(cmocka_deprecated_var); \
});
#elif defined(_MSC_VER)
#define CMOCKA_DEPRECATION_WARNING(msg) __pragma(message("warning: " msg))
#else
#define CMOCKA_DEPRECATION_WARNING(msg)
#endif
#endif /* CMOCKA_DISABLE_DEPRECATION_WARNINGS */
#if defined(__GNUC__)
#define CMOCKA_NORETURN __attribute__ ((noreturn))
#elif defined(_MSC_VER)
#define CMOCKA_NORETURN __declspec(noreturn)
#else
#define CMOCKA_NORETURN
#endif
/* Function attribute that tells the compiler that we never access the value
* of a/b, just the pointer address.
*
* Without this, newer compilers like GCC-12 will print
* `-Wmaybe-uninitialized` warnings.
*
* See:
* https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes
*/
#ifdef __has_attribute
#if __has_attribute(access)
#define CMOCKA_NO_ACCESS_ATTRIBUTE \
__attribute__((access(none, 1), access(none, 2)))
#endif
#endif
#ifndef CMOCKA_NO_ACCESS_ATTRIBUTE
#define CMOCKA_NO_ACCESS_ATTRIBUTE
#endif
/* cmocka_util */
#define WILL_RETURN_ALWAYS -1
#define WILL_RETURN_ONCE -2
#define EXPECT_ALWAYS -1
#define EXPECT_MAYBE -2
#ifdef DOXYGEN
uintmax_t mock(void);
#else
#define mock() (_mock(__func__, __FILE__, __LINE__, NULL)).uint_val
#endif
#ifdef DOXYGEN
type mock_type(#type);
#else
#define mock_type(type) ((type) mock())
#endif
#ifdef DOXYGEN
bool has_mock(void);
#else
#define has_mock() _has_mock(__func__)
#endif
#ifdef DOXYGEN
intmax_t mock_int();
#else
/* TODO: Enable type safety check by passing intmax_t instead of NULL */
#define mock_int() (_mock(__func__, __FILE__, __LINE__, NULL)).int_val
#endif
#ifdef DOXYGEN
uintmax_t mock_uint(void);
#else
#define mock_uint() (_mock(__func__, __FILE__, __LINE__, "uintmax_t")).uint_val
#endif
#ifdef DOXYGEN
float mock_float(void);
#else
#define mock_float() (_mock(__func__, __FILE__, __LINE__, NULL)).float_val
#endif
#ifdef DOXYGEN
double mock_double(void);
#else
#define mock_double() (_mock(__func__, __FILE__, __LINE__, NULL)).real_val
#endif
#ifdef DOXYGEN
type mock_ptr_type(#type);
#else
#define mock_ptr_type(type) \
((type)(_mock(__func__, __FILE__, __LINE__, NULL)).ptr)
#endif
#ifdef DOXYGEN
type mock_ptr_type_checked(#type);
#else
#define mock_ptr_type_checked(type) \
((type)(_mock(__func__, __FILE__, __LINE__, #type)).ptr)
#endif
#ifdef DOXYGEN
uintmax_t mock_parameter(#name);
#else
#define mock_parameter(name) \
(_mock_parameter(__func__, #name, __FILE__, __LINE__, NULL)).uint_val
#endif
#ifdef DOXYGEN
#type mock_parameter_type(#name, #type);
#else
#define mock_parameter_type(name, type) ((type) mock_parameter(#name))
#endif
#ifdef DOXYGEN
intmax_t mock_parameter_int(#name);
#else
#define mock_parameter_int(name) \
(_mock_parameter(__func__, #name, __FILE__, __LINE__, "intmax_t")).int_val
#endif
#ifdef DOXYGEN
uintmax_t mock_parameter_uint(#name);
#else
#define mock_parameter_uint(name) \
(_mock_parameter(__func__, #name, __FILE__, __LINE__, "uintmax_t")).uint_val
#endif
#ifdef DOXYGEN
float mock_parameter_float(#name);
#else
#define mock_parameter_float(name) \
(_mock_parameter(__func__, #name, __FILE__, __LINE__, "float")).float_val
#endif
#ifdef DOXYGEN
double mock_parameter_double(#name);
#else
#define mock_parameter_double(name) \
(_mock_parameter(__func__, #name, __FILE__, __LINE__, "double")).real_val
#endif
#ifdef DOXYGEN
void *mock_parameter_ptr(#name);
#else
#define mock_parameter_ptr(name) \
((_mock_parameter(__func__, #name, __FILE__, __LINE__, NULL)).ptr)
#endif
#ifdef DOXYGEN
type mock_parameter_ptr_type(#name, #type);
#else
#define mock_parameter_ptr_type(name, type) \
((type)(_mock_parameter(__func__, #name, __FILE__, __LINE__, #type)).ptr)
#endif
#ifdef DOXYGEN
void mock_errno(void);
#else
#define mock_errno() \
do { \
intmax_t err = (_mock_parameter( \
__func__, \
"/errno", \
__FILE__, \
__LINE__, \
"errno")).int_val; \
if (err != 0) { \
errno = err; \
} \
} while (0)
#endif
#ifdef DOXYGEN
void will_return(#function, uintmax_t value);
#else
#define will_return(function, value) \
_will_return(cmocka_tostring(function), \
__FILE__, \
__LINE__, \
NULL, \
cast_int_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_return_int(#function, intmax_t value);
#else
#define will_return_int(function, value) \
_will_return(#function, \
__FILE__, \
__LINE__, \
"intmax_t", \
assign_int_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_return_int_count(#function, intmax_t value, int count);
#else
#define will_return_int_count(function, value, count) \
_will_return(#function, \
__FILE__, \
__LINE__, \
"intmax_t", \
assign_int_to_cmocka_value(value), \
count)
#endif
#ifdef DOXYGEN
void will_return_uint(#function, uintmax_t value);
#else
#define will_return_uint(function, value) \
_will_return(#function, \
__FILE__, \
__LINE__, \
"uintmax_t", \
assign_uint_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_return_uint_count(#function, uintmax_t value, int count);
#else
#define will_return_uint_count(function, value, count) \
_will_return(#function, \
__FILE__, \
__LINE__, \
"uintmax_t", \
assign_uint_to_cmocka_value(value), \
count)
#endif
#ifdef DOXYGEN
void will_return_float(#function, float value);
#else
#define will_return_float(function, value) \
_will_return(#function, \
__FILE__, \
__LINE__, \
"float", \
assign_float_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_return_float_count(#function, float value, int count);
#else
#define will_return_float_count(function, value, count) \
_will_return(#function, \
__FILE__, \
__LINE__, \
"float", \
assign_float_to_cmocka_value(value), \
count)
#endif
#ifdef DOXYGEN
void will_return_double(#function, double value);
#else
#define will_return_double(function, value) \
_will_return(#function, \
__FILE__, \
__LINE__, \
"double", \
assign_double_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_return_double_count(#function, double value, int count);
#else
#define will_return_double_count(function, value, count) \
_will_return(#function, \
__FILE__, \
__LINE__, \
"double", \
assign_double_to_cmocka_value(value), \
count)
#endif
#ifdef DOXYGEN
void will_return_int_always(#function, intmax_t value);
#else
#define will_return_int_always(function, value) \
will_return_int_count(function, (value), WILL_RETURN_ALWAYS)
#endif
#ifdef DOXYGEN
void will_return_uint_always(#function, uintmax_t value);
#else
#define will_return_uint_always(function, value) \
will_return_uint_count(function, (value), WILL_RETURN_ALWAYS)
#endif
#ifdef DOXYGEN
void will_return_float_always(#function, float value);
#else
#define will_return_float_always(function, value) \
will_return_float_count(function, (value), WILL_RETURN_ALWAYS)
#endif
#ifdef DOXYGEN
void will_return_double_always(#function, double value);
#else
#define will_return_double_always(function, value) \
will_return_double_count(function, (value), WILL_RETURN_ALWAYS)
#endif
#ifdef DOXYGEN
void will_return_count(#function, uintmax_t value, int count);
#else
#define will_return_count(function, value, count) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"will_return_count: use will_return_int_count or " \
"will_return_uint_count instead") \
_will_return(cmocka_tostring(function), \
__FILE__, \
__LINE__, \
NULL, \
cast_int_to_cmocka_value(value), \
count); \
} while (0)
#endif
#ifdef DOXYGEN
void will_return_always(#function, uintmax_t value);
#else
#define will_return_always(function, value) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"will_return_always: use will_return_int_always or " \
"will_return_uint_always instead") \
will_return_count(function, (value), WILL_RETURN_ALWAYS); \
} while (0)
#endif
#ifdef DOXYGEN
void will_return_int_maybe(#function, intmax_t value);
#else
#define will_return_int_maybe(function, value) \
will_return_int_count(function, (value), WILL_RETURN_ONCE)
#endif
#ifdef DOXYGEN
void will_return_uint_maybe(#function, uintmax_t value);
#else
#define will_return_uint_maybe(function, value) \
will_return_uint_count(function, (value), WILL_RETURN_ONCE)
#endif
#ifdef DOXYGEN
void will_return_float_maybe(#function, float value);
#else
#define will_return_float_maybe(function, value) \
will_return_float_count(function, (value), WILL_RETURN_ONCE)
#endif
#ifdef DOXYGEN
void will_return_double_maybe(#function, double value);
#else
#define will_return_double_maybe(function, value) \
will_return_double_count(function, (value), WILL_RETURN_ONCE)
#endif
#ifdef DOXYGEN
void will_return_maybe(#function, uintmax_t value);
#else
#define will_return_maybe(function, value) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"will_return_maybe: use will_return_int_maybe or " \
"will_return_uint_maybe instead") \
will_return_count(function, (value), WILL_RETURN_ONCE); \
} while (0)
#endif
#ifdef DOXYGEN
void will_return_ptr(#function, void *value);
#else
#define will_return_ptr(function, value) \
_will_return(#function, \
__FILE__, \
__LINE__, \
NULL, \
cast_ptr_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_return_ptr_type(#function, void *value, type);
#else
#define will_return_ptr_type(function, value, type) \
_will_return(#function, \
__FILE__, \
__LINE__, \
#type, \
cast_ptr_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_return_ptr_count(#function, void *value, int count);
#else
#define will_return_ptr_count(function, value, count) \
_will_return(#function, \
__FILE__, \
__LINE__, \
NULL, \
cast_ptr_to_cmocka_value(value), \
count)
#endif
#ifdef DOXYGEN
void will_return_ptr_always(#function, void *value);
#else
#define will_return_ptr_always(function, value) \
will_return_ptr_count(function, (value), WILL_RETURN_ALWAYS)
#endif
#ifdef DOXYGEN
void will_return_ptr_maybe(#function, void *value);
#else
#define will_return_ptr_maybe(function, value) \
will_return_ptr_count(function, (value), WILL_RETURN_ONCE)
#endif
#ifdef DOXYGEN
void will_set_parameter(#function, #name, uintmax_t value);
#else
#define will_set_parameter(function, name, value) \
_will_set_parameter(cmocka_tostring(function), \
#name, \
__FILE__, \
__LINE__, \
NULL, \
cast_int_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_set_parameter_int(#function, #name, intmax_t value);
#else
#define will_set_parameter_int(function, name, value) \
_will_set_parameter(#function, \
#name, \
__FILE__, \
__LINE__, \
"intmax_t", \
assign_int_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_set_parameter_uint(#function, #name, uintmax_t value);
#else
#define will_set_parameter_uint(function, name, value) \
_will_set_parameter(#function, \
#name, \
__FILE__, \
__LINE__, \
"uintmax_t", \
assign_uint_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_set_parameter_float(#function, #name, float value);
#else
#define will_set_parameter_float(function, name, value) \
_will_set_parameter(#function, \
#name, \
__FILE__, \
__LINE__, \
"float", \
assign_float_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_set_parameter_double(#function, #name, double value);
#else
#define will_set_parameter_double(function, name, value) \
_will_set_parameter(#function, \
#name, \
__FILE__, \
__LINE__, \
"double", \
assign_double_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_set_parameter_int_count(#function, #name, intmax_t value, int count);
#else
#define will_set_parameter_int_count(function, name, value, count) \
_will_set_parameter(#function, \
#name, \
__FILE__, \
__LINE__, \
"intmax_t", \
assign_int_to_cmocka_value(value), \
count)
#endif
#ifdef DOXYGEN
void will_set_parameter_uint_count(#function,
#name,
uintmax_t value,
int count);
#else
#define will_set_parameter_uint_count(function, name, value, count) \
_will_set_parameter(#function, \
#name, \
__FILE__, \
__LINE__, \
"uintmax_t", \
assign_uint_to_cmocka_value(value), \
count)
#endif
#ifdef DOXYGEN
void will_set_parameter_float_count(#function, #name, float value, int count);
#else
#define will_set_parameter_float_count(function, name, value, count) \
_will_set_parameter(#function, \
#name, \
__FILE__, \
__LINE__, \
"float", \
assign_float_to_cmocka_value(value), \
count)
#endif
#ifdef DOXYGEN
void will_set_parameter_double_count(#function, #name, double value, int count);
#else
#define will_set_parameter_double_count(function, name, value, count) \
_will_set_parameter(#function, \
#name, \
__FILE__, \
__LINE__, \
"double", \
assign_double_to_cmocka_value(value), \
count)
#endif
#ifdef DOXYGEN
void will_set_parameter_count(#function, #name, uintmax_t value, int count);
#else
#define will_set_parameter_count(function, name, value, count) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"will_set_parameter_count: use will_set_parameter_int_count or " \
"will_set_parameter_uint_count instead") \
_will_set_parameter(cmocka_tostring(function), \
#name, \
__FILE__, \
__LINE__, \
NULL, \
cast_int_to_cmocka_value(value), \
count); \
} while (0)
#endif
#ifdef DOXYGEN
void will_set_parameter_int_always(#function, #name, intmax_t value);
#else
#define will_set_parameter_int_always(function, name, value) \
will_set_parameter_int_count(function, name, (value), WILL_RETURN_ALWAYS)
#endif
#ifdef DOXYGEN
void will_set_parameter_uint_always(#function, #name, uintmax_t value);
#else
#define will_set_parameter_uint_always(function, name, value) \
will_set_parameter_uint_count(function, name, (value), WILL_RETURN_ALWAYS)
#endif
#ifdef DOXYGEN
void will_set_parameter_float_always(#function, #name, float value);
#else
#define will_set_parameter_float_always(function, name, value) \
will_set_parameter_float_count(function, name, (value), WILL_RETURN_ALWAYS)
#endif
#ifdef DOXYGEN
void will_set_parameter_double_always(#function, #name, double value);
#else
#define will_set_parameter_double_always(function, name, value) \
will_set_parameter_double_count(function, name, (value), WILL_RETURN_ALWAYS)
#endif
#ifdef DOXYGEN
void will_set_parameter_always(#function, #name, uintmax_t value);
#else
#define will_set_parameter_always(function, name, value) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"will_set_parameter_always: use will_set_parameter_int_always or " \
"will_set_parameter_uint_always instead") \
will_set_parameter_count(function, name, (value), WILL_RETURN_ALWAYS); \
} while (0)
#endif
#ifdef DOXYGEN
void will_set_parameter_int_maybe(#function, #name, intmax_t value);
#else
#define will_set_parameter_int_maybe(function, name, value) \
will_set_parameter_int_count(function, name, (value), WILL_RETURN_ONCE)
#endif
#ifdef DOXYGEN
void will_set_parameter_uint_maybe(#function, #name, uintmax_t value);
#else
#define will_set_parameter_uint_maybe(function, name, value) \
will_set_parameter_uint_count(function, name, (value), WILL_RETURN_ONCE)
#endif
#ifdef DOXYGEN
void will_set_parameter_float_maybe(#function, #name, float value);
#else
#define will_set_parameter_float_maybe(function, name, value) \
will_set_parameter_float_count(function, name, (value), WILL_RETURN_ONCE)
#endif
#ifdef DOXYGEN
void will_set_parameter_double_maybe(#function, #name, double value);
#else
#define will_set_parameter_double_maybe(function, name, value) \
will_set_parameter_double_count(function, name, (value), WILL_RETURN_ONCE)
#endif
#ifdef DOXYGEN
void will_set_parameter_maybe(#function, #name, uintmax_t value);
#else
#define will_set_parameter_maybe(function, name, value) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"will_set_parameter_maybe: use will_set_parameter_int_maybe or " \
"will_set_parameter_uint_maybe instead") \
will_set_parameter_count(function, name, (value), WILL_RETURN_ONCE); \
} while (0)
#endif
#ifdef DOXYGEN
void will_set_parameter_ptr(#function, #name, void *value);
#else
#define will_set_parameter_ptr(function, name, value) \
_will_set_parameter(#function, \
#name, \
__FILE__, \
__LINE__, \
NULL, \
cast_ptr_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_set_parameter_ptr_type(#function, #name, void *value, #type);
#else
#define will_set_parameter_ptr_type(function, name, value, type) \
_will_set_parameter(#function, \
#name, \
__FILE__, \
__LINE__, \
#type, \
cast_ptr_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_set_parameter_ptr_count(#function, #name, void *value, int count);
#else
#define will_set_parameter_ptr_count(function, name, value, count) \
_will_set_parameter(#function, \
#name, \
__FILE__, \
__LINE__, \
NULL, \
cast_ptr_to_cmocka_value(value), \
count)
#endif
#ifdef DOXYGEN
void will_set_parameter_ptr_always(#function, #name, void *value);
#else
#define will_set_parameter_ptr_always(function, name, value) \
will_set_parameter_ptr_count(function, name, (value), WILL_RETURN_ALWAYS)
#endif
#ifdef DOXYGEN
void will_set_parameter_ptr_maybe(#function, #name, void *value);
#else
#define will_set_parameter_ptr_maybe(function, name, value) \
will_set_parameter_ptr_count(function, name, (value), WILL_RETURN_ONCE)
#endif
#ifdef DOXYGEN
void will_set_errno(#function, intmax_t value);
#else
#define will_set_errno(function, value) \
_will_set_parameter(#function, \
"/errno", \
__FILE__, \
__LINE__, \
"errno", \
assign_int_to_cmocka_value(value), \
1)
#endif
#ifdef DOXYGEN
void will_set_errno_count(#function, intmax_t value, size_t count);
#else
#define will_set_errno_count(function, value, count) \
_will_set_parameter(#function, \
"/errno", \
__FILE__, \
__LINE__, \
"errno", \
assign_int_to_cmocka_value(value), \
(count))
#endif
#ifdef DOXYGEN
void will_set_errno_always(#function, intmax_t value);
#else
#define will_set_errno_always(function, value) \
will_set_errno_count(function, (value), WILL_RETURN_ALWAYS);
#endif
#ifdef DOXYGEN
void will_set_errno_maybe(#function, intmax_t value);
#else
#define will_set_errno_maybe(function, value) \
will_set_errno_count(function, (value), WILL_RETURN_ONCE);
#endif
/* cmocka_mock */
#ifdef DOXYGEN
void expect_check(function,
parameter,
CheckParameterValue check_function,
const void *check_data);
#else
#define expect_check(function, parameter, check_function, check_data) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"expect_check: use expect_check_data instead") \
_expect_check(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
check_function, \
cast_to_uintmax_type(check_data), \
NULL, \
1); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_check_count(function,
parameter,
CheckParameterValue check_function,
const void *check_data,
size_t count);
#else
#define expect_check_count( \
function, parameter, check_function, check_data, count) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"expect_check_count: use expect_check_data_count instead") \
_expect_check(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
check_function, \
cast_to_uintmax_type(check_data), \
NULL, \
count); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_check_data(function,
parameter,
CheckParameterValueData check_function,
CMockaValueData check_data);
#else
#define expect_check_data(function, parameter, check_function, check_data) \
_expect_check_data(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
check_function, \
check_data, \
NULL, \
1)
#endif
#ifdef DOXYGEN
void expect_check_data_count(function,
parameter,
CheckParameterValueData check_function,
CMockaValueData check_data,
size_t count);
#else
#define expect_check_data_count(function, \
parameter, \
check_function, \
check_data, \
count) \
_expect_check_data(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
check_function, \
check_data, \
NULL, \
count)
#endif
#ifdef DOXYGEN
void expect_in_set(#function, #parameter, uintmax_t value_array[]);
#else
#define expect_in_set(function, parameter, value_array) \
do { \
CMOCKA_DEPRECATION_WARNING("expect_in_set: use expect_int_in_set or " \
"expect_uint_in_set instead") \
expect_in_set_count(function, parameter, value_array, 1); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_in_set(#function, #parameter, intmax_t value_array[]);
#else
#define expect_int_in_set(function, parameter, value_array) \
expect_int_in_set_count(function, parameter, value_array, 1)
#endif
#ifdef DOXYGEN
void expect_in_set(#function, #parameter, intmax_t value_array[]);
#else
#define expect_uint_in_set(function, parameter, value_array) \
expect_uint_in_set_count(function, parameter, value_array, 1)
#endif
#ifdef DOXYGEN
void expect_in_set_count(#function, #parameter, uintmax_t value_array[], size_t count);
#else
#define expect_in_set_count(function, parameter, value_array, count) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"expect_in_set_count: use expect_int_in_set_count or " \
"expect_uint_in_set_count instead") \
_expect_uint_in_set(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value_array, \
sizeof(value_array) / sizeof((value_array)[0]), \
count); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_int_in_set_count(#function, #parameter, intmax_t value_array[], size_t count);
#else
#define expect_int_in_set_count(function, parameter, value_array, count) \
_expect_int_in_set(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value_array, \
sizeof(value_array) / sizeof((value_array)[0]), \
count)
#endif
#ifdef DOXYGEN
void expect_uint_in_set_count(#function, #parameter, uintmax_t value_array[], size_t count);
#else
#define expect_uint_in_set_count(function, parameter, value_array, count) \
_expect_uint_in_set(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value_array, \
sizeof(value_array) / sizeof((value_array)[0]), \
count)
#endif
#ifdef DOXYGEN
void expect_not_in_set(#function, #parameter, uintmax_t value_array[]);
#else
#define expect_not_in_set(function, parameter, value_array) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"expect_not_in_set: use expect_int_not_in_set or " \
"expect_uint_not_in_set instead") \
expect_not_in_set_count(function, parameter, value_array, 1); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_not_in_set_count(#function, #parameter, uintmax_t value_array[], size_t count);
#else
#define expect_not_in_set_count(function, parameter, value_array, count) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"expect_not_in_set_count: use expect_int_not_in_set_count or " \
"expect_uint_not_in_set_count instead") \
_expect_not_in_set(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value_array, \
sizeof(value_array) / sizeof((value_array)[0]), \
count); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_int_not_in_set(#function, #parameter, intmax_t value_array[]);
#else
#define expect_int_not_in_set(function, parameter, value_array) \
expect_int_not_in_set_count(function, parameter, value_array, 1)
#endif
#ifdef DOXYGEN
void expect_int_not_in_set_count(#function,
#parameter,
intmax_t value_array[],
size_t count);
#else
#define expect_int_not_in_set_count(function, parameter, value_array, count) \
_expect_int_not_in_set(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value_array, \
sizeof(value_array) / sizeof((value_array)[0]), \
count)
#endif
#ifdef DOXYGEN
void expect_uint_not_in_set(#function, #parameter, uintmax_t value_array[]);
#else
#define expect_uint_not_in_set(function, parameter, value_array) \
expect_uint_not_in_set_count(function, parameter, value_array, 1)
#endif
#ifdef DOXYGEN
void expect_uint_not_in_set_count(#function,
#parameter,
uintmax_t value_array[],
size_t count);
#else
#define expect_uint_not_in_set_count(function, parameter, value_array, count) \
_expect_uint_not_in_set(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value_array, \
sizeof(value_array) / sizeof((value_array)[0]), \
count)
#endif
#ifdef DOXYGEN
void expect_float_in_set(#function, #parameter, double value_array[], double epsilon);
#else
#define expect_float_in_set(function, parameter, value_array, epsilon) \
expect_float_in_set_count(function, parameter, value_array, epsilon, 1)
#endif
#ifdef DOXYGEN
void expect_float_in_set_count(#function, #parameter, double value_array[], double epsilon, size_t count);
#else
#define expect_float_in_set_count(function, parameter, value_array, epsilon, count) \
_expect_float_in_set(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value_array, \
sizeof(value_array) / sizeof((value_array)[0]), \
epsilon, \
count)
#endif
#ifdef DOXYGEN
void expect_float_not_in_set(#function, #parameter, double value_array[], double epsilon);
#else
#define expect_float_not_in_set(function, parameter, value_array, epsilon) \
expect_float_not_in_set_count(function, parameter, value_array, epsilon, 1)
#endif
#ifdef DOXYGEN
void expect_float_not_in_set_count(#function, #parameter, double value_array[], double epsilon, size_t count);
#else
#define expect_float_not_in_set_count(function, parameter, value_array, epsilon, count) \
_expect_float_not_in_set(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value_array, \
sizeof(value_array) / sizeof((value_array)[0]), \
epsilon, \
count)
#endif
#ifdef DOXYGEN
void expect_in_range(#function, #parameter, uintmax_t minimum, uintmax_t maximum);
#else
#define expect_in_range(function, parameter, minimum, maximum) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"expect_in_range: use expect_int_in_range or " \
"expect_uint_in_range instead") \
expect_in_range_count(function, parameter, minimum, maximum, 1); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_in_range_count(#function, #parameter, uintmax_t minimum, uintmax_t maximum, size_t count);
#else
#define expect_in_range_count(function, parameter, minimum, maximum, count) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"expect_in_range_count: use expect_int_in_range_count or " \
"expect_uint_in_range_count instead") \
_expect_in_range(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
minimum, \
maximum, \
count); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_int_in_range(#function,
#parameter,
intmax_t minimum,
intmax_t maximum);
#else
#define expect_int_in_range(function, parameter, minimum, maximum) \
expect_int_in_range_count(function, parameter, minimum, maximum, 1)
#endif
#ifdef DOXYGEN
void expect_int_in_range_count(#function,
#parameter,
intmax_t minimum,
intmax_t maximum,
size_t count);
#else
#define expect_int_in_range_count( \
function, parameter, minimum, maximum, count) \
_expect_int_in_range(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
minimum, \
maximum, \
count)
#endif
#ifdef DOXYGEN
void expect_uint_in_range(#function,
#parameter,
uintmax_t minimum,
uintmax_t maximum);
#else
#define expect_uint_in_range(function, parameter, minimum, maximum) \
expect_uint_in_range_count(function, parameter, minimum, maximum, 1)
#endif
#ifdef DOXYGEN
void expect_uint_in_range_count(#function,
#parameter,
uintmax_t minimum,
uintmax_t maximum,
size_t count);
#else
#define expect_uint_in_range_count( \
function, parameter, minimum, maximum, count) \
_expect_uint_in_range(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
minimum, \
maximum, \
count)
#endif
#ifdef DOXYGEN
void expect_not_in_range(#function, #parameter, uintmax_t minimum, uintmax_t maximum);
#else
#define expect_not_in_range(function, parameter, minimum, maximum) \
expect_not_in_range_count(function, parameter, minimum, maximum, 1)
#endif
#ifdef DOXYGEN
void expect_not_in_range_count(#function, #parameter, uintmax_t minimum, uintmax_t maximum, size_t count);
#else
#define expect_not_in_range_count(function, parameter, minimum, maximum, \
count) \
_expect_not_in_range(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
minimum, maximum, count)
#endif
#ifdef DOXYGEN
void expect_int_not_in_range(#function,
#parameter,
intmax_t minimum,
intmax_t maximum);
#else
#define expect_int_not_in_range(function, parameter, minimum, maximum) \
expect_int_not_in_range_count(function, parameter, minimum, maximum, 1)
#endif
#ifdef DOXYGEN
void expect_int_not_in_range_count(#function,
#parameter,
intmax_t minimum,
intmax_t maximum,
size_t count);
#else
#define expect_int_not_in_range_count( \
function, parameter, minimum, maximum, count) \
_expect_int_not_in_range(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
minimum, \
maximum, \
count)
#endif
#ifdef DOXYGEN
void expect_uint_not_in_range(#function,
#parameter,
uintmax_t minimum,
uintmax_t maximum);
#else
#define expect_uint_not_in_range(function, parameter, minimum, maximum) \
expect_uint_not_in_range_count(function, parameter, minimum, maximum, 1)
#endif
#ifdef DOXYGEN
void expect_uint_not_in_range_count(#function,
#parameter,
uintmax_t minimum,
uintmax_t maximum,
size_t count);
#else
#define expect_uint_not_in_range_count( \
function, parameter, minimum, maximum, count) \
_expect_uint_not_in_range(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
minimum, \
maximum, \
count)
#endif
#ifdef DOXYGEN
void expect_float_in_range(#function, #parameter, double minimum, double maximum, double epsilon);
#else
#define expect_float_in_range(function, parameter, minimum, maximum, epsilon) \
expect_float_in_range_count(function, parameter, minimum, maximum, epsilon, 1)
#endif
#ifdef DOXYGEN
void expect_float_in_range_count(#function, #parameter, double minimum, double maximum, double epsilon, size_t count);
#else
#define expect_float_in_range_count(function, parameter, minimum, maximum, epsilon, count) \
_expect_float_in_range(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
cast_to_double_type(minimum), \
cast_to_double_type(maximum), \
cast_to_double_type(epsilon), \
count)
#endif
#ifdef DOXYGEN
void expect_float_not_in_range(#function, #parameter, double minimum, double maximum, double epsilon);
#else
#define expect_float_not_in_range(function, parameter, minimum, maximum, epsilon) \
expect_float_not_in_range_count(function, parameter, minimum, maximum, epsilon, 1)
#endif
#ifdef DOXYGEN
void expect_float_not_in_range_count(#function, #parameter, double minimum, double maximum, double epsilon, size_t count);
#else
#define expect_float_not_in_range_count(function, parameter, minimum, maximum, \
epsilon, count) \
_expect_float_not_in_range(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
cast_to_double_type(minimum), \
cast_to_double_type(maximum), \
cast_to_double_type(epsilon), \
count)
#endif
#ifdef DOXYGEN
void expect_value(#function, #parameter, uintmax_t value);
#else
#define expect_value(function, parameter, value) \
do { \
CMOCKA_DEPRECATION_WARNING("expect_value: use expect_int_value or " \
"expect_uint_value instead") \
expect_value_count(function, parameter, value, 1); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_value_count(#function, #parameter, uintmax_t value, size_t count);
#else
#define expect_value_count(function, parameter, value, count) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"expect_value_count: use expect_int_value_count or " \
"expect_uint_value_count instead") \
_expect_value(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
cast_to_uintmax_type(value), \
count); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_int_value(#function, #parameter, intmax_t value);
#else
#define expect_int_value(function, parameter, value) \
expect_int_value_count(function, parameter, value, 1)
#endif
#ifdef DOXYGEN
void expect_int_value_count(#function,
#parameter,
intmax_t value,
size_t count);
#else
#define expect_int_value_count(function, parameter, value, count) \
_expect_int_value(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value, \
count)
#endif
#ifdef DOXYGEN
void expect_uint_value(#function, #parameter, uintmax_t value);
#else
#define expect_uint_value(function, parameter, value) \
expect_uint_value_count(function, parameter, value, 1)
#endif
#ifdef DOXYGEN
void expect_uint_value_count(#function,
#parameter,
uintmax_t value,
size_t count);
#else
#define expect_uint_value_count(function, parameter, value, count) \
_expect_uint_value(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value, \
count)
#endif
#ifdef DOXYGEN
void expect_int_not_value(#function, #parameter, intmax_t value);
#else
#define expect_int_not_value(function, parameter, value) \
expect_int_not_value_count(function, parameter, value, 1)
#endif
#ifdef DOXYGEN
void expect_int_not_value_count(#function,
#parameter,
intmax_t value,
size_t count);
#else
#define expect_int_not_value_count(function, parameter, value, count) \
_expect_int_not_value(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value, \
count)
#endif
#ifdef DOXYGEN
void expect_uint_not_value(#function, #parameter, uintmax_t value);
#else
#define expect_uint_not_value(function, parameter, value) \
expect_uint_not_value_count(function, parameter, value, 1)
#endif
#ifdef DOXYGEN
void expect_uint_not_value_count(#function,
#parameter,
uintmax_t value,
size_t count);
#else
#define expect_uint_not_value_count(function, parameter, value, count) \
_expect_uint_not_value(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
value, \
count)
#endif
#ifdef DOXYGEN
void expect_not_value(#function, #parameter, uintmax_t value);
#else
#define expect_not_value(function, parameter, value) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"expect_not_value: use expect_int_not_value or " \
"expect_uint_not_value instead") \
expect_not_value_count(function, parameter, value, 1); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_not_value_count(#function, #parameter, uintmax_t value, size_t count);
#else
#define expect_not_value_count(function, parameter, value, count) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"expect_not_value_count: use expect_int_not_value_count or " \
"expect_uint_not_value_count instead") \
_expect_not_value(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
cast_to_uintmax_type(value), \
count); \
} while (0)
#endif
#ifdef DOXYGEN
void expect_float(#function, #parameter, double value, double epsilon);
#else
#define expect_float(function, parameter, value, epsilon) \
expect_float_count(function, parameter, cast_to_double_type(value), \
cast_to_double_type(epsilon), 1)
#endif
#ifdef DOXYGEN
void expect_float_count(#function, #parameter, double value, double epsilon, size_t count);
#else
#define expect_float_count(function, parameter, value, epsilon, count) \
_expect_float(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
cast_to_double_type(value), cast_to_double_type(epsilon), count)
#endif
#ifdef DOXYGEN
void expect_not_float(#function, #parameter, double value, double epsilon);
#else
#define expect_not_float(function, parameter, value, epsilon) \
expect_not_float_count(function, \
parameter, \
cast_to_float_type(value), \
cast_to_float_type(epsilon), \
1)
#endif
#ifdef DOXYGEN
void expect_not_float_count(#function, #parameter, double value, double epsilon, size_t count);
#else
#define expect_not_float_count(function, parameter, value, epsilon, count) \
_expect_not_float(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
cast_to_float_type(value), \
cast_to_float_type(epsilon), \
count)
#endif
#ifdef DOXYGEN
void expect_double(#function, #parameter, double value, double epsilon);
#else
#define expect_double(function, parameter, value, epsilon) \
expect_double_count(function, \
parameter, \
cast_to_double_type(value), \
cast_to_double_type(epsilon), \
1)
#endif
#ifdef DOXYGEN
void expect_double_count(#function,
#parameter,
double value,
double epsilon,
size_t count);
#else
#define expect_double_count(function, parameter, value, epsilon, count) \
_expect_double(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
cast_to_double_type(value), \
cast_to_double_type(epsilon), \
count)
#endif
#ifdef DOXYGEN
void expect_not_double(#function, #parameter, double value, double epsilon);
#else
#define expect_not_double(function, parameter, value, epsilon) \
expect_not_double_count(function, \
parameter, \
cast_to_double_type(value), \
cast_to_double_type(epsilon), \
1)
#endif
#ifdef DOXYGEN
void expect_not_double_count(#function,
#parameter,
double value,
double epsilon,
size_t count);
#else
#define expect_not_double_count(function, parameter, value, epsilon, count) \
_expect_not_double(cmocka_tostring(function), \
cmocka_tostring(parameter), \
__FILE__, \
__LINE__, \
cast_to_double_type(value), \
cast_to_double_type(epsilon), \
count)
#endif
#ifdef DOXYGEN
void expect_string(#function, #parameter, const char *string);
#else
#define expect_string(function, parameter, string) \
expect_string_count(function, parameter, string, 1)
#endif
#ifdef DOXYGEN
void expect_string_count(#function, #parameter, const char *string, size_t count);
#else
#define expect_string_count(function, parameter, string, count) \
_expect_string(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
(const char*)(string), count)
#endif
#ifdef DOXYGEN
void expect_not_string(#function, #parameter, const char *string);
#else
#define expect_not_string(function, parameter, string) \
expect_not_string_count(function, parameter, string, 1)
#endif
#ifdef DOXYGEN
void expect_not_string_count(#function, #parameter, const char *string, size_t count);
#else
#define expect_not_string_count(function, parameter, string, count) \
_expect_not_string(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
(const char*)(string), count)
#endif
#ifdef DOXYGEN
void expect_memory(#function, #parameter, void *memory, size_t size);
#else
#define expect_memory(function, parameter, memory, size) \
expect_memory_count(function, parameter, memory, size, 1)
#endif
#ifdef DOXYGEN
void expect_memory_count(#function, #parameter, void *memory, size_t size, size_t count);
#else
#define expect_memory_count(function, parameter, memory, size, count) \
_expect_memory(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
(const void*)(memory), size, count)
#endif
#ifdef DOXYGEN
void expect_not_memory(#function, #parameter, void *memory, size_t size);
#else
#define expect_not_memory(function, parameter, memory, size) \
expect_not_memory_count(function, parameter, memory, size, 1)
#endif
#ifdef DOXYGEN
void expect_not_memory_count(#function, #parameter, void *memory, size_t size, size_t count);
#else
#define expect_not_memory_count(function, parameter, memory, size, count) \
_expect_not_memory(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
(const void*)(memory), size, count)
#endif
#ifdef DOXYGEN
void expect_any(#function, #parameter);
#else
#define expect_any(function, parameter) \
expect_any_count(function, parameter, 1)
#endif
#ifdef DOXYGEN
void expect_any_always(#function, #parameter);
#else
#define expect_any_always(function, parameter) \
expect_any_count(function, parameter, WILL_RETURN_ALWAYS)
#endif
#ifdef DOXYGEN
void expect_any_count(#function, #parameter, size_t count);
#else
#define expect_any_count(function, parameter, count) \
_expect_any(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, count)
#endif
#ifdef DOXYGEN
void check_expected(#parameter);
#else
#define check_expected(parameter) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"check_expected: use check_expected_int or " \
"check_expected_uint instead") \
_check_expected(__func__, \
#parameter, \
__FILE__, \
__LINE__, \
cast_int_to_cmocka_value(parameter)); \
} while (0)
#endif
#ifdef DOXYGEN
void check_expected_any(#parameter);
#else
#define check_expected_any(parameter) \
_check_expected(__func__, #parameter, __FILE__, __LINE__, \
cast_ptr_to_cmocka_value(&(parameter)))
#endif
#ifdef DOXYGEN
void check_expected_ptr(#parameter);
#else
#define check_expected_ptr(parameter) \
_check_expected(__func__, #parameter, __FILE__, __LINE__, \
cast_ptr_to_cmocka_value(parameter))
#endif
#ifdef DOXYGEN
void check_expected_int(#parameter);
#else
#define check_expected_int(parameter) \
_check_expected(__func__, \
#parameter, \
__FILE__, \
__LINE__, \
assign_int_to_cmocka_value(parameter))
#endif
#ifdef DOXYGEN
void check_expected_uint(#parameter);
#else
#define check_expected_uint(parameter) \
_check_expected(__func__, \
#parameter, \
__FILE__, \
__LINE__, \
assign_uint_to_cmocka_value(parameter))
#endif
#ifdef DOXYGEN
void check_expected_float(#parameter);
#else
#define check_expected_float(parameter) \
_check_expected(__func__, \
#parameter, \
__FILE__, \
__LINE__, \
assign_float_to_cmocka_value(parameter))
#endif
#ifdef DOXYGEN
void check_expected_double(#parameter);
#else
#define check_expected_double(parameter) \
_check_expected(__func__, \
#parameter, \
__FILE__, \
__LINE__, \
assign_double_to_cmocka_value(parameter))
#endif
/* cmocka_param */
#ifdef DOXYGEN
void assert_true(scalar expression);
#else
#define assert_true(c) _assert_true(cast_to_uintmax_type(c), #c, \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_false(scalar expression);
#else
#define assert_false(c) _assert_false(cast_to_uintmax_type(c), #c, \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_return_code(intmax_t rc, int32_t error);
#else
#define assert_return_code(rc, error) \
_assert_return_code((rc), \
(error), \
#rc, __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_non_null(void *pointer);
#else
#define assert_non_null(c) assert_ptr_not_equal((c), NULL)
#endif
#ifdef DOXYGEN
void assert_non_null_msg(void *pointer, const char *const message);
#else
#define assert_non_null_msg(c, msg) assert_ptr_not_equal_msg((c), NULL, (msg))
#endif
#ifdef DOXYGEN
void assert_null(void *pointer);
#else
#define assert_null(c) assert_ptr_equal((c), NULL)
#endif
#ifdef DOXYGEN
void assert_null_msg(void *pointer, const char *const message);
#else
#define assert_null_msg(c, msg) assert_ptr_equal_msg((c), NULL, (msg))
#endif
#ifdef DOXYGEN
void assert_ptr_equal(void *a, void *b);
#else
#define assert_ptr_equal(a, b) assert_ptr_equal_msg((a), (b), NULL)
#endif
#ifdef DOXYGEN
void assert_ptr_equal_msg(void *a, void *b, const char *const msg);
#else
#define assert_ptr_equal_msg(a, b, msg) \
_assert_ptr_equal_msg(cast_to_void_pointer(a), \
cast_to_void_pointer(b), \
__FILE__, __LINE__, (msg))
#endif
#ifdef DOXYGEN
void assert_ptr_not_equal(void *a, void *b);
#else
#define assert_ptr_not_equal(a, b) \
assert_ptr_not_equal_msg((a), (b), NULL)
#endif
#ifdef DOXYGEN
void assert_ptr_not_equal_msg(void *a, void *b, const char *const msg);
#else /* DOXYGEN */
#if defined(__has_builtin)
#if __has_builtin(__builtin_unreachable)
#define assert_ptr_not_equal_msg(a, b, msg) \
do { \
const void *cmocka_p1 = cast_to_void_pointer(a), \
*cmocka_p2 = cast_to_void_pointer(b); \
_assert_ptr_not_equal_msg( \
cmocka_p1, cmocka_p2, __FILE__, __LINE__, (msg)); \
if (cmocka_p1 == cmocka_p2) { \
__builtin_unreachable(); \
} \
} while (0)
#else /* __has_builtin(__builtin_unreachable) */
#define assert_ptr_not_equal_msg(a, b, msg) \
_assert_ptr_not_equal_msg(cast_to_void_pointer(a), \
cast_to_void_pointer(b), \
__FILE__, \
__LINE__, \
(msg))
#endif /* __has_builtin(__builtin_unreachable) */
#else /* defined(__has_builtin) */
#define assert_ptr_not_equal_msg(a, b, msg) \
_assert_ptr_not_equal_msg(cast_to_void_pointer(a), \
cast_to_void_pointer(b), \
__FILE__, \
__LINE__, \
(msg))
#endif /* __has_builtin(__builtin_unreachable) */
#endif /* DOXYGEN */
#ifdef DOXYGEN
void assert_int_equal(intmax_t a, intmax_t b);
#else
#define assert_int_equal(a, b) \
_assert_int_equal(cast_to_intmax_type(a), \
cast_to_intmax_type(b), \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_uint_equal(uintmax_t a, uintmax_t b);
#else
#define assert_uint_equal(a, b) \
_assert_uint_equal(cast_to_uintmax_type(a), \
cast_to_uintmax_type(b), \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_int_not_equal(intmax_t a, intmax_t b);
#else
#define assert_int_not_equal(a, b) \
_assert_int_not_equal(cast_to_intmax_type(a), \
cast_to_intmax_type(b), \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_uint_not_equal(uintmax_t a, uintmax_t b);
#else
#define assert_uint_not_equal(a, b) \
_assert_uint_not_equal(cast_to_uintmax_type(a), \
cast_to_uintmax_type(b), \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_float_equal(float a, float b, float epsilon);
#else
#define assert_float_equal(a, b, epsilon) \
_assert_float_equal((float)a, \
(float)b, \
(float)epsilon, \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_float_not_equal(float a, float b, float epsilon);
#else
#define assert_float_not_equal(a, b, epsilon) \
_assert_float_not_equal((float)a, \
(float)b, \
(float)epsilon, \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_double_equal(double a, double b, double epsilon);
#else
#define assert_double_equal(a, b, epsilon) \
_assert_double_equal((double)a, \
(double)b, \
(double)epsilon, \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_double_not_equal(double a, double b, double epsilon);
#else
#define assert_double_not_equal(a, b, epsilon) \
_assert_double_not_equal((double)a, \
(double)b, \
(double)epsilon, \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_string_equal(const char *a, const char *b);
#else
#define assert_string_equal(a, b) \
_assert_string_equal((a), (b), __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_string_not_equal(const char *a, const char *b);
#else
#define assert_string_not_equal(a, b) \
_assert_string_not_equal((a), (b), __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_memory_equal(const void *a, const void *b, size_t size);
#else
#define assert_memory_equal(a, b, size) \
_assert_memory_equal((const void*)(a), (const void*)(b), size, __FILE__, \
__LINE__)
#endif
#ifdef DOXYGEN
void assert_memory_not_equal(const void *a, const void *b, size_t size);
#else
#define assert_memory_not_equal(a, b, size) \
_assert_memory_not_equal((const void*)(a), (const void*)(b), size, \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_int_in_range(intmax_t value, intmax_t minimum, intmax_t maximum);
#else
#define assert_int_in_range(value, minimum, maximum) \
_assert_int_in_range( \
cast_to_intmax_type(value), \
cast_to_intmax_type(minimum), \
cast_to_intmax_type(maximum), __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_uint_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum);
#else
#define assert_uint_in_range(value, minimum, maximum) \
_assert_uint_in_range( \
cast_to_intmax_type(value), \
cast_to_intmax_type(minimum), \
cast_to_intmax_type(maximum), __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_int_not_in_range(intmax_t value,
intmax_t minimum,
intmax_t maximum);
#else
#define assert_int_not_in_range(value, minimum, maximum) \
_assert_int_not_in_range(cast_to_intmax_type(value), \
cast_to_intmax_type(minimum), \
cast_to_intmax_type(maximum), \
__FILE__, \
__LINE__)
#endif
#ifdef DOXYGEN
void assert_uint_not_in_range(uintmax_t value,
uintmax_t minimum,
uintmax_t maximum);
#else
#define assert_uint_not_in_range(value, minimum, maximum) \
_assert_uint_not_in_range(cast_to_uintmax_type(value), \
cast_to_uintmax_type(minimum), \
cast_to_uintmax_type(maximum), \
__FILE__, \
__LINE__)
#endif
#ifdef DOXYGEN
void assert_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum);
#else
#define assert_in_range(value, minimum, maximum) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"assert_in_range: use assert_int_in_range or " \
"assert_uint_in_range instead") \
_assert_uint_in_range(cast_to_uintmax_type(value), \
cast_to_uintmax_type(minimum), \
cast_to_uintmax_type(maximum), \
__FILE__, \
__LINE__); \
} while (0)
#endif
#ifdef DOXYGEN
void assert_not_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum);
#else
#define assert_not_in_range(value, minimum, maximum) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"assert_not_in_range: use assert_int_not_in_range or " \
"assert_uint_not_in_range instead") \
_assert_uint_not_in_range(cast_to_uintmax_type(value), \
cast_to_uintmax_type(minimum), \
cast_to_uintmax_type(maximum), \
__FILE__, \
__LINE__); \
} while (0)
#endif
#ifdef DOXYGEN
void assert_float_not_in_range(double value, double minimum, double maximum, double epsilon);
#else
#define assert_float_not_in_range(value, minimum, maximum, epsilon) \
_assert_float_not_in_range(cast_to_double_type(value), \
cast_to_double_type(minimum), \
cast_to_double_type(maximum), \
cast_to_double_type(epsilon), \
__FILE__, \
__LINE__)
#endif
#ifdef DOXYGEN
void assert_float_in_range(double value, double minimum, double maximum, double epsilon);
#else
#define assert_float_in_range(value, minimum, maximum, epsilon) \
_assert_float_in_range( \
cast_to_double_type(value), \
cast_to_double_type(minimum), \
cast_to_double_type(maximum), \
cast_to_double_type(epsilon), __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_in_set(uintmax_t value, uintmax_t values[], size_t count);
#else
#define assert_in_set(value, values, number_of_values) \
do { \
CMOCKA_DEPRECATION_WARNING("assert_in_set: use assert_int_in_set or " \
"assert_uint_in_set instead") \
_assert_uint_in_set( \
value, values, number_of_values, __FILE__, __LINE__); \
} while (0)
#endif
#ifdef DOXYGEN
void assert_not_in_set(uintmax_t value, uintmax_t values[], size_t count);
#else
#define assert_not_in_set(value, values, number_of_values) \
_assert_not_in_set(value, values, number_of_values, __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void assert_int_in_set(intmax_t value, intmax_t values[], size_t count);
#else
#define assert_int_in_set(value, values, number_of_values) \
if (number_of_values > 0) { \
intmax_t _cmocka_set[number_of_values]; \
for (size_t _i = 0; _i < number_of_values; _i++) { \
_cmocka_set[_i] = values[_i]; \
} \
_assert_int_in_set(value, _cmocka_set, number_of_values, __FILE__, __LINE__); \
}
#endif
#ifdef DOXYGEN
void assert_int_not_in_set(intmax_t value, intmax_t values[], size_t count);
#else
#define assert_int_not_in_set(value, values, number_of_values) \
if (number_of_values > 0) { \
intmax_t _cmocka_set[number_of_values]; \
for (size_t _i = 0; _i < number_of_values; _i++) { \
_cmocka_set[_i] = values[_i]; \
} \
_assert_int_not_in_set(value, _cmocka_set, number_of_values, __FILE__, __LINE__); \
}
#endif
#ifdef DOXYGEN
void assert_uint_in_set(uintmax_t value, uintmax_t values[], size_t count);
#else
#define assert_uint_in_set(value, values, number_of_values) \
if (number_of_values > 0) { \
uintmax_t _cmocka_set[number_of_values]; \
for (size_t _i = 0; _i < number_of_values; _i++) { \
_cmocka_set[_i] = values[_i]; \
} \
_assert_uint_in_set(value, _cmocka_set, number_of_values, __FILE__, __LINE__); \
}
#endif
#ifdef DOXYGEN
void assert_uint_not_in_set(uintmax_t value, uintmax_t values[], size_t count);
#else
#define assert_uint_not_in_set(value, values, number_of_values) \
if (number_of_values > 0) { \
uintmax_t _cmocka_set[number_of_values]; \
for (size_t _i = 0; _i < number_of_values; _i++) { \
_cmocka_set[_i] = values[_i]; \
} \
_assert_uint_not_in_set(value, _cmocka_set, number_of_values, __FILE__, __LINE__); \
}
#endif
#ifdef DOXYGEN
void assert_float_in_set(double value, double values[], size_t count, double epsilon);
#else
#define assert_float_in_set(value, values, number_of_values, epsilon) \
if (number_of_values > 0) { \
double _cmocka_set[number_of_values]; \
for (size_t _i = 0; _i < number_of_values; _i++) { \
_cmocka_set[_i] = values[_i]; \
} \
_assert_float_in_set(value, _cmocka_set, number_of_values, epsilon, __FILE__, __LINE__); \
}
#endif
#ifdef DOXYGEN
void assert_float_not_in_set(double value, double values[], size_t count, double epsilon);
#else
#define assert_float_not_in_set(value, values, number_of_values, epsilon) \
if (number_of_values > 0) { \
double _cmocka_set[number_of_values]; \
for (size_t _i = 0; _i < number_of_values; _i++) { \
_cmocka_set[_i] = values[_i]; \
} \
_assert_float_not_in_set(value, _cmocka_set, number_of_values, epsilon, __FILE__, __LINE__); \
}
#endif
/* cmocka_asserts */
#ifdef DOXYGEN
void function_called(void);
#else
#define function_called() _function_called(__func__, __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void expect_function_calls(#function, const int times);
#else
#define expect_function_calls(function, times) \
_expect_function_call(cmocka_tostring(function), __FILE__, __LINE__, times)
#endif
#ifdef DOXYGEN
void expect_function_call(#function);
#else
#define expect_function_call(function) \
_expect_function_call(cmocka_tostring(function), __FILE__, __LINE__, 1)
#endif
#ifdef DOXYGEN
void expect_function_call_any(#function);
#else
#define expect_function_call_any(function) \
_expect_function_call(cmocka_tostring(function), __FILE__, __LINE__, -1)
#endif
#ifdef DOXYGEN
void ignore_function_calls(#function);
#else
#define ignore_function_calls(function) \
_expect_function_call(cmocka_tostring(function), __FILE__, __LINE__, -2)
#endif
/* cmocka_call_order */
#ifdef DOXYGEN
void fail(void);
#else
#define fail() _fail(__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void skip(void);
#else
#define skip() _skip(__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void stop(void);
#else
#define stop() _stop()
#endif
#ifdef DOXYGEN
void fail_msg(const char *msg, ...);
#else
#define fail_msg(msg, ...) do { \
cmocka_print_error("ERROR: " msg "\n", ##__VA_ARGS__); \
fail(); \
} while (0)
#endif
static inline void _unit_test_dummy(void **state) {
(void)state;
}
#define unit_test(f) \
(CMOCKA_DEPRECATION_WARNING("unit_test: use cmocka_unit_test instead")( \
UnitTest){#f, f, UNIT_TEST_FUNCTION_TYPE_TEST})
#define _unit_test_setup(test, setup) \
{ #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP }
#define unit_test_setup(test, setup) \
CMOCKA_DEPRECATION_WARNING( \
"unit_test_setup: use cmocka_unit_test_setup instead") \
_unit_test_setup(test, setup), unit_test(test), \
_unit_test_teardown(test, _unit_test_dummy)
#define _unit_test_teardown(test, teardown) \
{ #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN }
#define unit_test_teardown(test, teardown) \
CMOCKA_DEPRECATION_WARNING( \
"unit_test_teardown: use cmocka_unit_test_teardown instead") \
_unit_test_setup(test, _unit_test_dummy), unit_test(test), \
_unit_test_teardown(test, teardown)
#define group_test_setup(setup) \
(CMOCKA_DEPRECATION_WARNING( \
"group_test_setup: use cmocka_run_group_tests instead")(UnitTest){ \
"group_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP})
#define group_test_teardown(teardown) \
(CMOCKA_DEPRECATION_WARNING( \
"group_test_teardown: use cmocka_run_group_tests instead")(UnitTest){ \
"group_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN})
#define unit_test_setup_teardown(test, setup, teardown) \
CMOCKA_DEPRECATION_WARNING("unit_test_setup_teardown: use " \
"cmocka_unit_test_setup_teardown instead") \
_unit_test_setup(test, setup), unit_test(test), \
_unit_test_teardown(test, teardown)
#define cmocka_unit_test(f) { #f, f, NULL, NULL, NULL }
#define cmocka_unit_test_setup(f, setup) { #f, f, setup, NULL, NULL }
#define cmocka_unit_test_teardown(f, teardown) { #f, f, NULL, teardown, NULL }
#define cmocka_unit_test_setup_teardown(f, setup, teardown) { #f, f, setup, teardown, NULL }
#define cmocka_unit_test_prestate(f, state) { #f, f, NULL, NULL, state }
#define cmocka_unit_test_prestate_setup_teardown(f, setup, teardown, state) { #f, f, setup, teardown, state }
#ifdef DOXYGEN
int cmocka_run_group_tests(const struct CMUnitTest group_tests[],
CMFixtureFunction group_setup,
CMFixtureFunction group_teardown);
#else
# define cmocka_run_group_tests(group_tests, group_setup, group_teardown) \
_cmocka_run_group_tests(#group_tests, group_tests, sizeof(group_tests) / sizeof((group_tests)[0]), group_setup, group_teardown)
#endif
#ifdef DOXYGEN
int cmocka_run_group_tests_name(const char *group_name,
const struct CMUnitTest group_tests[],
CMFixtureFunction group_setup,
CMFixtureFunction group_teardown);
#else
# define cmocka_run_group_tests_name(group_name, group_tests, group_setup, group_teardown) \
_cmocka_run_group_tests(group_name, group_tests, sizeof(group_tests) / sizeof((group_tests)[0]), group_setup, group_teardown)
#endif
/* cmocka_exec */
#ifdef DOXYGEN
void *test_malloc(size_t size);
#else
#define test_malloc(size) _test_malloc(size, __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void *test_calloc(size_t nmemb, size_t size);
#else
#define test_calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void *test_realloc(void *ptr, size_t size);
#else
#define test_realloc(ptr, size) _test_realloc(ptr, size, __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
void test_free(void *ptr);
#else
#define test_free(ptr) _test_free(ptr, __FILE__, __LINE__)
#endif
#if defined(UNIT_TESTING) && defined(ALLOCATION_TESTING)
#define malloc test_malloc
#define realloc test_realloc
#define calloc test_calloc
#define free test_free
#endif /* UNIT_TESTING && ALLOCATION_TESTING */
/* cmocka_alloc */
void mock_assert(const int result, const char* const expression,
const char * const file, const int line);
#ifdef DOXYGEN
void expect_assert_failure(function fn_call);
#else
#define expect_assert_failure(function_call) \
{ \
global_expecting_assert = 1; \
if (setjmp(global_expect_assert_env) != 0) { \
print_message("Expected assertion %s occurred\n", \
global_last_failed_assert); \
global_expecting_assert = 0; \
} else { \
function_call ; \
global_expecting_assert = 0; \
print_error("Expected assert in %s\n", #function_call); \
_fail(__FILE__, __LINE__); \
} \
}
#endif
/* cmocka_mock_assert */
typedef union {
intmax_t int_val;
uintmax_t uint_val;
float float_val;
double real_val; // TODO: Should we use `long double` instead
void *ptr;
const void *const_ptr;
// The following aren't used by CMocka currently, but are added to avoid
// breaking ABI compatibility in the future
void *(*func)(void);
} CMockaValueData;
#ifndef DOXYGEN
#define LargestIntegralType uintmax_t
#if defined(__GNUC__)
#define cast_ptr_to_largest_integral_type(value) \
__extension__({ \
CMOCKA_DEPRECATION_WARNING( \
"cast_ptr_to_largest_integral_type: " \
"use cast_ptr_to_uintmax_type instead"); \
cast_ptr_to_uintmax_type(value); \
})
#else
#define cast_ptr_to_largest_integral_type(value) \
cast_ptr_to_uintmax_type(value)
#endif
#endif
typedef void (*UnitTestFunction)(void **state);
typedef int (*CheckParameterValue)(const uintmax_t value,
const uintmax_t check_value_data);
typedef int (*CheckParameterValueData)(const CMockaValueData value,
const CMockaValueData check_value_data);
typedef int (*CheckIntParameterValue)(const intmax_t value,
const intmax_t check_value_data);
typedef int (*CheckUintParameterValue)(const uintmax_t value,
const uintmax_t check_value_data);
typedef enum UnitTestFunctionType {
UNIT_TEST_FUNCTION_TYPE_TEST = 0,
UNIT_TEST_FUNCTION_TYPE_SETUP,
UNIT_TEST_FUNCTION_TYPE_TEARDOWN,
UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP,
UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN,
} UnitTestFunctionType;
typedef struct UnitTest {
const char* name;
UnitTestFunction function;
UnitTestFunctionType function_type;
} UnitTest;
typedef struct GroupTest {
UnitTestFunction setup;
UnitTestFunction teardown;
const UnitTest *tests;
const size_t number_of_tests;
} GroupTest;
typedef void (*CMUnitTestFunction)(void **state);
typedef int (*CMFixtureFunction)(void **state);
struct CMUnitTest {
const char *name;
CMUnitTestFunction test_func;
CMFixtureFunction setup_func;
CMFixtureFunction teardown_func;
void *initial_state;
};
typedef struct SourceLocation {
const char* file;
int line;
} SourceLocation;
typedef struct CheckParameterEvent {
SourceLocation location;
const char *parameter_name;
CheckParameterValue check_value;
uintmax_t check_value_data;
} CheckParameterEvent;
typedef struct CheckParameterEventData {
SourceLocation location;
const char *parameter_name;
CheckParameterValueData check_value;
CMockaValueData check_value_data;
} CheckParameterEventData;
/* Standard output and error print methods. */
void print_message(const char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
void print_error(const char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
void vprint_message(const char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
void vprint_error(const char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
struct CMCallbacks {
void (*vprint_message)(const char * const format, va_list args);
void (*vprint_error)(const char * const format, va_list args);
};
void cmocka_set_callbacks(const struct CMCallbacks *f_callbacks);
enum cm_message_output {
CM_OUTPUT_STANDARD = 0x00000001,
CM_OUTPUT_STDOUT = 0x00000001,
CM_OUTPUT_SUBUNIT = 0x00000002,
CM_OUTPUT_TAP = 0x00000004,
CM_OUTPUT_XML = 0x00000008,
};
#ifdef DOXYGEN
void cm_print_error(const char* const format, ...);
#else
#define cm_print_error(format, ...) \
do { \
CMOCKA_DEPRECATION_WARNING( \
"cm_print_error: use cmocka_print_error instead") \
cmocka_print_error(format, ##__VA_ARGS__); \
} while (0)
#endif
void cmocka_print_error(const char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
void cmocka_set_message_output(uint32_t output);
void cmocka_set_test_filter(const char *pattern);
void cmocka_set_skip_filter(const char *pattern);
/* cmocka_config */
/* Used by expect_assert_failure() and mock_assert(). */
CMOCKA_DLLEXTERN extern int global_expecting_assert;
CMOCKA_DLLEXTERN extern jmp_buf global_expect_assert_env;
CMOCKA_DLLEXTERN extern const char * global_last_failed_assert;
/* Retrieves a value for the given function, as set by "will_return". */
CMockaValueData _mock(const char *const function,
const char *const file,
const int line,
const char *name);
CMockaValueData _mock_parameter(const char *const function,
const char *name,
const char *const file,
const int line,
const char *type);
bool _has_mock(const char *const function);
void _expect_function_call(
const char * const function_name,
const char * const file,
const int line,
const int count);
void _function_called(const char * const function, const char* const file,
const int line);
/* Old API function using uintmax_t */
void _expect_check(
const char* const function, const char* const parameter,
const char* const file, const int line,
const CheckParameterValue check_function,
const uintmax_t check_data, CheckParameterEvent * const event,
const int count) CMOCKA_DEPRECATED;
/* New API function using CMockaValueData */
void _expect_check_data(
const char* const function, const char* const parameter,
const char* const file, const int line,
const CheckParameterValueData check_function,
const CMockaValueData check_data, CheckParameterEventData * const event,
const int count);
void _expect_int_in_set(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const intmax_t values[],
const size_t number_of_values,
const size_t count);
void _expect_uint_in_set(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const uintmax_t values[],
const size_t number_of_values,
const size_t count);
void _expect_float_in_set(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const double values[],
const size_t number_of_values,
const double epsilon,
const size_t count);
void _expect_not_in_set(
const char* const function, const char* const parameter,
const char* const file, const int line, const uintmax_t values[],
const size_t number_of_values, const int count);
void _expect_int_not_in_set(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const intmax_t values[],
const size_t number_of_values,
const size_t count);
void _expect_uint_not_in_set(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const uintmax_t values[],
const size_t number_of_values,
const size_t count);
void _expect_float_not_in_set(
const char* const function, const char* const parameter,
const char* const file, const size_t line, const double values[],
const size_t number_of_values, const double epsilon, const size_t count);
void _expect_in_range(const char *const function,
const char *const parameter,
const char *const file,
const int line,
const uintmax_t minimum,
const uintmax_t maximum,
const int count) CMOCKA_DEPRECATED;
void _expect_int_in_range(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const intmax_t minimum,
const intmax_t maximum,
const size_t count);
void _expect_uint_in_range(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const uintmax_t minimum,
const uintmax_t maximum,
const size_t count);
void _expect_not_in_range(
const char* const function, const char* const parameter,
const char* const file, const int line,
const uintmax_t minimum,
const uintmax_t maximum, const int count);
void _expect_int_not_in_range(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const intmax_t minimum,
const intmax_t maximum,
const size_t count);
void _expect_uint_not_in_range(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const uintmax_t minimum,
const uintmax_t maximum,
const size_t count);
void _expect_float_in_range(
const char* const function, const char* const parameter,
const char* const file, const int line,
const double minimum, const double maximum, const double epsilon,
const int count);
void _expect_float_not_in_range(
const char* const function, const char* const parameter,
const char* const file, const int line,
const double minimum, const double maximum, const double epsilon,
const int count);
void _expect_value(
const char* const function, const char* const parameter,
const char* const file, const int line, const uintmax_t value,
const int count);
void _expect_int_value(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const intmax_t value,
const size_t count);
void _expect_uint_value(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const uintmax_t value,
const size_t count);
void _expect_int_not_value(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const intmax_t value,
const size_t count);
void _expect_uint_not_value(const char *const function,
const char *const parameter,
const char *const file,
const size_t line,
const uintmax_t value,
const size_t count);
void _expect_not_value(
const char* const function, const char* const parameter,
const char* const file, const int line, const uintmax_t value,
const int count);
void _expect_float(
const char* const function, const char* const parameter,
const char* const file, const int line, const double value,
const double epsilon, const int count);
void _expect_not_float(
const char* const function, const char* const parameter,
const char* const file, const int line, const double value,
const double epsilon, const int count);
void _expect_double(const char *const function,
const char *const parameter,
const char *const file,
const int line,
const double value,
const double epsilon,
const int count);
void _expect_not_double(const char *const function,
const char *const parameter,
const char *const file,
const int line,
const double value,
const double epsilon,
const int count);
void _expect_string(
const char* const function, const char* const parameter,
const char* const file, const int line, const char* string,
const int count);
void _expect_not_string(
const char* const function, const char* const parameter,
const char* const file, const int line, const char* string,
const int count);
void _expect_memory(
const char* const function, const char* const parameter,
const char* const file, const int line, const void* const memory,
const size_t size, const int count);
void _expect_not_memory(
const char* const function, const char* const parameter,
const char* const file, const int line, const void* const memory,
const size_t size, const int count);
void _expect_any(
const char* const function, const char* const parameter,
const char* const file, const int line, const int count);
void _check_expected(
const char * const function_name, const char * const parameter_name,
const char* file, const int line, const CMockaValueData value);
void _will_return(const char *const function_name,
const char *const file,
const int line,
const char *name,
const CMockaValueData value,
const int count);
void _will_set_parameter(const char *const function_name,
const char *name,
const char *const file,
const int line,
const char *type,
const CMockaValueData value,
const int count);
void _assert_true(const uintmax_t result,
const char* const expression,
const char * const file, const int line);
void _assert_false(const uintmax_t result,
const char * const expression,
const char * const file, const int line);
void _assert_return_code(const intmax_t result,
const int32_t error,
const char * const expression,
const char * const file,
const int line);
void _assert_float_equal(const float a, const float n,
const float epsilon, const char* const file,
const int line);
void _assert_float_not_equal(const float a, const float n,
const float epsilon, const char* const file,
const int line);
void _assert_double_equal(const double a, const double n,
const double epsilon, const char* const file,
const int line);
void _assert_double_not_equal(const double a, const double n,
const double epsilon, const char* const file,
const int line);
void _assert_int_equal(const intmax_t a,
const intmax_t b,
const char * const file,
const int line);
void _assert_int_not_equal(const intmax_t a,
const intmax_t b,
const char * const file,
const int line);
void _assert_uint_equal(const uintmax_t a,
const uintmax_t b,
const char * const file,
const int line);
void _assert_uint_not_equal(const uintmax_t a,
const uintmax_t b,
const char * const file,
const int line);
CMOCKA_NO_ACCESS_ATTRIBUTE
void _assert_ptr_equal_msg(const void *a,
const void *b,
const char *const file,
const int line,
const char *const msg);
CMOCKA_NO_ACCESS_ATTRIBUTE
void _assert_ptr_not_equal_msg(const void *a,
const void *b,
const char *const file,
const int line,
const char *const msg);
void _assert_string_equal(const char * const a, const char * const b,
const char * const file, const int line);
void _assert_string_not_equal(const char * const a, const char * const b,
const char *file, const int line);
void _assert_memory_equal(const void * const a, const void * const b,
const size_t size, const char* const file,
const int line);
void _assert_memory_not_equal(const void * const a, const void * const b,
const size_t size, const char* const file,
const int line);
void _assert_int_in_range(const intmax_t value,
const intmax_t minimum,
const intmax_t maximum,
const char* const file,
const int line);
void _assert_int_not_in_range(const intmax_t value,
const intmax_t minimum,
const intmax_t maximum,
const char *const file,
const int line);
void _assert_uint_in_range(const uintmax_t value,
const uintmax_t minimum,
const uintmax_t maximum,
const char* const file,
const int line);
void _assert_uint_not_in_range(const uintmax_t value,
const uintmax_t minimum,
const uintmax_t maximum,
const char* const file,
const int line);
void _assert_float_in_range(const double value,
const double minimum,
const double maximum,
const double epsilon,
const char* const file,
const int line);
void _assert_float_not_in_range(const double value,
const double minimum,
const double maximum,
const double epsilon,
const char* const file,
const int line);
void _assert_not_in_set(
const uintmax_t value, const uintmax_t values[],
const size_t number_of_values, const char* const file, const int line);
void _assert_int_in_set(const intmax_t value,
const intmax_t values[],
const size_t number_of_values,
const char *const file,
const int line);
void _assert_int_not_in_set(const intmax_t value,
const intmax_t values[],
const size_t number_of_values,
const char *const file,
const int line);
void _assert_uint_in_set(const uintmax_t value,
const uintmax_t values[],
const size_t number_of_values,
const char *const file,
const int line);
void _assert_uint_not_in_set(const uintmax_t value,
const uintmax_t values[],
const size_t number_of_values,
const char *const file,
const int line);
void _assert_float_in_set(const double value,
const double values[],
const size_t number_of_values,
const double epsilon,
const char *const file,
const int line);
void _assert_float_not_in_set(const double value,
const double values[],
const size_t number_of_values,
const double epsilon,
const char *const file,
const int line);
void* _test_malloc(const size_t size, const char* file, const int line);
void* _test_realloc(void *ptr, const size_t size, const char* file, const int line);
void* _test_calloc(const size_t number_of_elements, const size_t size,
const char* file, const int line);
void _test_free(void* const ptr, const char* file, const int line);
CMOCKA_NORETURN void _fail(const char * const file, const int line);
CMOCKA_NORETURN void _skip(const char * const file, const int line);
CMOCKA_NORETURN void _stop(void);
/* Test runner */
int _cmocka_run_group_tests(const char *group_name,
const struct CMUnitTest * const tests,
const size_t num_tests,
CMFixtureFunction group_setup,
CMFixtureFunction group_teardown);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* CMOCKA_H_ */
test_realloc
void * test_realloc(void *ptr, size_t size)
Test function overriding realloc which detects buffer overruns and memory leaks.
test_free
void test_free(void *ptr)
Test function overriding free(3).
test_calloc
void * test_calloc(size_t nmemb, size_t size)
Test function overriding calloc.
test_malloc
void * test_malloc(size_t size)
Test function overriding malloc.
assert_ptr_equal
void assert_ptr_equal(void *a, void *b)
Assert that the two given pointers are equal.
assert_int_equal
void assert_int_equal(intmax_t a, intmax_t b)
Assert that the two given integers are equal.
assert_int_in_set
void assert_int_in_set(intmax_t value, intmax_t values[], size_t count)
Assert that the specified integer value is within a set.
assert_not_in_set
void assert_not_in_set(uintmax_t value, uintmax_t values[], size_t count)
Assert that the specified value is not within a set.
assert_int_not_in_set
void assert_int_not_in_set(intmax_t value, intmax_t values[], size_t count)
Assert that the specified value is not within a set.
assert_string_equal
void assert_string_equal(const char *a, const char *b)
Assert that the two given strings are equal.
assert_null
void assert_null(void *pointer)
Assert that the given pointer is NULL.
assert_not_in_range
void assert_not_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum)
assert_float_not_in_range
void assert_float_not_in_range(double value, double minimum, double maximum, double epsilon)
Assert that the specified float value is smaller than the minimum or greater than the maximum.
assert_memory_not_equal
void assert_memory_not_equal(const void *a, const void *b, size_t size)
Assert that the two given areas of memory are not equal.
assert_float_not_in_set
void assert_float_not_in_set(double value, double values[], size_t count, double epsilon)
Assert that the specified float value is not within a set.
assert_ptr_not_equal
void assert_ptr_not_equal(void *a, void *b)
Assert that the two given pointers are not equal.
assert_double_equal
void assert_double_equal(double a, double b, double epsilon)
Assert that the two given double are equal given an epsilon.
assert_ptr_not_equal_msg
void assert_ptr_not_equal_msg(void *a, void *b, const char *const msg)
Assert that the two given pointers are not equal.
assert_float_in_range
void assert_float_in_range(double value, double minimum, double maximum, double epsilon)
Assert that the specified float value is not smaller than the minimum and and not greater than the ma...
assert_float_in_set
void assert_float_in_set(double value, double values[], size_t count, double epsilon)
Assert that the specified float value is within a set.
assert_in_range
void assert_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum)
assert_uint_equal
void assert_uint_equal(uintmax_t a, uintmax_t b)
Assert that the two given unsigned integers are equal.
assert_non_null
void assert_non_null(void *pointer)
Assert that the given pointer is non-NULL.
assert_null_msg
void assert_null_msg(void *pointer, const char *const message)
Assert that the given pointer is NULL.
assert_true
void assert_true(scalar expression)
Assert that the given expression is true.
assert_ptr_equal_msg
void assert_ptr_equal_msg(void *a, void *b, const char *const msg)
Assert that the two given pointers are equal.
assert_false
void assert_false(scalar expression)
Assert that the given expression is false.
assert_in_set
void assert_in_set(uintmax_t value, uintmax_t values[], size_t count)
assert_int_in_range
void assert_int_in_range(intmax_t value, intmax_t minimum, intmax_t maximum)
Assert that the specified integer value is not smaller than the minimum and and not greater than the ...
assert_uint_not_in_range
void assert_uint_not_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum)
Assert that the specified value is smaller than the minimum or greater than the maximum.
assert_int_not_equal
void assert_int_not_equal(intmax_t a, intmax_t b)
Assert that the two given integers are not equal.
assert_uint_not_equal
void assert_uint_not_equal(uintmax_t a, uintmax_t b)
Assert that the two given unsigned integers are not equal.
assert_memory_equal
void assert_memory_equal(const void *a, const void *b, size_t size)
Assert that the two given areas of memory are equal, otherwise fail.
assert_float_equal
void assert_float_equal(float a, float b, float epsilon)
Assert that the two given float are equal given an epsilon.
assert_double_not_equal
void assert_double_not_equal(double a, double b, double epsilon)
Assert that the two given double are not equal given an epsilon.
assert_string_not_equal
void assert_string_not_equal(const char *a, const char *b)
Assert that the two given strings are not equal.
assert_int_not_in_range
void assert_int_not_in_range(intmax_t value, intmax_t minimum, intmax_t maximum)
Assert that the specified value is smaller than the minimum or greater than the maximum.
assert_uint_not_in_set
void assert_uint_not_in_set(uintmax_t value, uintmax_t values[], size_t count)
Assert that the specified unsigned integer value is not within a set.
assert_uint_in_set
void assert_uint_in_set(uintmax_t value, uintmax_t values[], size_t count)
Assert that the specified unsigned integer value is within a set.
assert_float_not_equal
void assert_float_not_equal(float a, float b, float epsilon)
Assert that the two given float are not equal given an epsilon.
assert_non_null_msg
void assert_non_null_msg(void *pointer, const char *const message)
Assert that the given pointer is non-NULL.
assert_uint_in_range
void assert_uint_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum)
Assert that the specified unsigned integer value is not smaller than the minimum and and not greater ...
assert_return_code
void assert_return_code(intmax_t rc, int32_t error)
Assert that the return_code is greater than or equal to 0.
ignore_function_calls
void ignore_function_calls(#function)
Ignores function_called() invocations from given mock function.
expect_function_call_any
void expect_function_call_any(#function)
Expects function_called() from given mock at least once.
expect_function_call
void expect_function_call(#function)
Store expected single call to a mock to be checked by function_called() later.
function_called
void function_called(void)
Check that current mocked function is being called in the expected order.
expect_function_calls
void expect_function_calls(#function, const int times)
Store expected call(s) to a mock to be checked by function_called() later.
cmocka_set_message_output
void cmocka_set_message_output(uint32_t output)
Function to set the output format for a test.
Definition cmocka.c:4795
cm_print_error
void cm_print_error(const char *const format,...)
cmocka_set_callbacks
void cmocka_set_callbacks(const struct CMCallbacks *f_callbacks)
Set callback functions for CMocka.
Definition cmocka.c:154
cmocka_print_error
void cmocka_print_error(const char *const format,...) CMOCKA_PRINTF_ATTRIBUTE(1
Print error message using the cmocka output format.
cm_message_output
cm_message_output
Output format options for test results.
Definition cmocka.h:6593
cmocka_set_skip_filter
void cmocka_set_skip_filter(const char *pattern)
Set a pattern to skip tests matching the pattern.
Definition cmocka.c:4855
cmocka_set_test_filter
void cmocka_set_test_filter(const char *pattern)
Set a pattern to only run the test matching the pattern.
Definition cmocka.c:4838
CM_OUTPUT_TAP
@ CM_OUTPUT_TAP
Definition cmocka.h:6601
CM_OUTPUT_STDOUT
@ CM_OUTPUT_STDOUT
Definition cmocka.h:6597
CM_OUTPUT_SUBUNIT
@ CM_OUTPUT_SUBUNIT
Definition cmocka.h:6599
CM_OUTPUT_STANDARD
@ CM_OUTPUT_STANDARD
Definition cmocka.h:6595
CM_OUTPUT_XML
@ CM_OUTPUT_XML
Definition cmocka.h:6603
UnitTestFunction
void(* UnitTestFunction)(void **state)
Definition cmocka.h:6394
CMFixtureFunction
int(* CMFixtureFunction)(void **state)
Definition cmocka.h:6476
cmocka_run_group_tests
int cmocka_run_group_tests(const struct CMUnitTest group_tests[], CMFixtureFunction group_setup, CMFixtureFunction group_teardown)
Run tests specified by an array of CMUnitTest structures.
fail
void fail(void)
Forces the test to fail immediately and quit.
stop
void stop(void)
Forces the test to be stopped immediately.
UnitTestFunctionType
UnitTestFunctionType
Definition cmocka.h:6433
fail_msg
void fail_msg(const char *msg,...)
Forces the test to fail immediately and quit, printing the reason.
cmocka_run_group_tests_name
int cmocka_run_group_tests_name(const char *group_name, const struct CMUnitTest group_tests[], CMFixtureFunction group_setup, CMFixtureFunction group_teardown)
Run tests specified by an array of CMUnitTest structures and specify a name.
skip
void skip(void)
Forces the test to not be executed, but marked as skipped.
CMUnitTestFunction
void(* CMUnitTestFunction)(void **state)
Definition cmocka.h:6469
mock_assert
void mock_assert(const int result, const char *const expression, const char *const file, const int line)
Function to replace assert(3) in tested code.
Definition cmocka.c:3446
expect_assert_failure
void expect_assert_failure(function fn_call)
Ensure that mock_assert() is called.
will_return_int
void will_return_int(#function, intmax_t value)
Store an integer value to be returned by mock() later.
will_set_parameter_float_always
void will_set_parameter_float_always(#function, #name, float value)
Store a named float value that will always be returned by mock_parameter_float().
mock_parameter
uintmax_t mock_parameter(#name)
Retrieve a named value for the current function.
will_return_float_maybe
void will_return_float_maybe(#function, float value)
Store a float value that may always be returned by mock_float().
will_set_parameter_int
void will_set_parameter_int(#function, #name, intmax_t value)
Store a named integer value to be returned by mock_parameter() later.
mock_int
intmax_t mock_int()
Retrieve an integer return value of the current function.
will_return_float_always
void will_return_float_always(#function, float value)
Store a float value that will always be returned by mock_float().
will_set_parameter_int_count
void will_set_parameter_int_count(#function, #name, intmax_t value, int count)
Store a named integer value to be returned a specified number of times by mock_parameter_int() later.
will_return_double_count
void will_return_double_count(#function, double value, int count)
Store a double precision floating point value to be returned a specified number of times by mock() la...
will_set_parameter_double_count
void will_set_parameter_double_count(#function, #name, double value, int count)
Store a named double value to be returned a specified number of times by mock_parameter_double() late...
will_set_parameter_uint
void will_set_parameter_uint(#function, #name, uintmax_t value)
Store a named unsigned integer value to be returned by mock_parameter() later.
will_set_parameter_float_maybe
void will_set_parameter_float_maybe(#function, #name, float value)
Store a named float value that may always be returned by mock_parameter_float().
mock_parameter_ptr
void * mock_parameter_ptr(#name)
Retrieve a named pointer for the current function.
will_return_count
void will_return_count(#function, uintmax_t value, int count)
will_set_parameter
void will_set_parameter(#function, #name, uintmax_t value)
Store a named value to be returned by mock_parameter() later.
will_return_int_maybe
void will_return_int_maybe(#function, intmax_t value)
Store an integer value that may always be returned by mock_int().
will_set_parameter_ptr_type
void will_set_parameter_ptr_type(#function, #name, void *value, #type)
Store a named pointer value to be returned by mock_parameter() later.
will_set_parameter_ptr
void will_set_parameter_ptr(#function, #name, void *value)
Store a named pointer value to be returned by mock_parameter() later.
will_return
void will_return(#function, uintmax_t value)
Store a value to be returned by mock() later.
will_return_ptr_type
void will_return_ptr_type(#function, void *value, type)
Store a pointer value to be returned by mock_ptr_type_checked() later.
will_return_double_always
void will_return_double_always(#function, double value)
Store a double value that will always be returned by mock_double().
will_set_errno_always
void will_set_errno_always(#function, intmax_t value)
Store an integer value to set errno to by mock_errno() later, for a specified number of times.
mock_parameter_ptr_type
type mock_parameter_ptr_type(#name, #type)
Retrieve a named pointer for the current function.
mock_double
double mock_double(void)
Retrieve a double precision floating point return value of the current function.
will_return_uint_maybe
void will_return_uint_maybe(#function, uintmax_t value)
Store an unsigned integer value that may always be returned by mock_uint().
will_set_errno_count
void will_set_errno_count(#function, intmax_t value, size_t count)
Store an integer value to always set errno to by mock_errno().
will_return_uint_always
void will_return_uint_always(#function, uintmax_t value)
Store an unsigned integer value that will always be returned by mock_uint().
will_set_parameter_double_maybe
void will_set_parameter_double_maybe(#function, #name, double value)
Store a named double value that may always be returned by mock_parameter_double().
will_set_parameter_int_maybe
void will_set_parameter_int_maybe(#function, #name, intmax_t value)
Store a named integer value that may always be returned by mock_parameter_int().
will_set_errno_maybe
void will_set_errno_maybe(#function, intmax_t value)
Store an integer value to set errno to by mock_errno() later, for a specified number of times.
will_return_uint_count
void will_return_uint_count(#function, uintmax_t value, int count)
Store an unsigned integer value to be returned a specified number of times by mock() later.
will_return_double_maybe
void will_return_double_maybe(#function, double value)
Store a double value that may always be returned by mock_double().
mock_uint
uintmax_t mock_uint(void)
Retrieve an unsigned integer return value of the current function.
will_set_parameter_double
void will_set_parameter_double(#function, #name, double value)
Store a named double precision floating point value to be returned by mock_parameter() later.
will_set_parameter_ptr_always
void will_set_parameter_ptr_always(#function, #name, void *value)
Store a named pointer value that will be always returned by mock_parameter_ptr().
will_return_always
void will_return_always(#function, uintmax_t value)
will_return_ptr
void will_return_ptr(#function, void *value)
Store a pointer value to be returned by mock_ptr_type() later.
will_return_ptr_always
void will_return_ptr_always(#function, void *value)
Store a value that will be always returned by mock_ptr_type().
will_return_int_always
void will_return_int_always(#function, intmax_t value)
Store an integer value that will always be returned by mock_int().
mock_type
type mock_type(#type)
Retrieve a value of the current function and cast it to given type.
will_set_parameter_float
void will_set_parameter_float(#function, #name, float value)
Store a named float value to be returned by mock_parameter() later.
will_set_parameter_double_always
void will_set_parameter_double_always(#function, #name, double value)
Store a named double value that will always be returned by mock_parameter_double().
has_mock
bool has_mock(void)
Check if data is available for the current mock function.
mock_parameter_float
float mock_parameter_float(#name)
Retrieve a named float value for the current function.
will_set_parameter_uint_maybe
void will_set_parameter_uint_maybe(#function, #name, uintmax_t value)
Store a named unsigned integer value that may always be returned by mock_parameter_uint().
will_set_parameter_int_always
void will_set_parameter_int_always(#function, #name, intmax_t value)
Store a named integer value that will always be returned by mock_parameter_int().
will_return_maybe
void will_return_maybe(#function, uintmax_t value)
will_set_parameter_always
void will_set_parameter_always(#function, #name, uintmax_t value)
will_set_parameter_count
void will_set_parameter_count(#function, #name, uintmax_t value, int count)
will_return_int_count
void will_return_int_count(#function, intmax_t value, int count)
Store an integer value to be returned a specified number of times by mock() later.
will_set_parameter_float_count
void will_set_parameter_float_count(#function, #name, float value, int count)
Store a named float value to be returned a specified number of times by mock_parameter_float() later.
will_return_ptr_count
void will_return_ptr_count(#function, void *value, int count)
Store a pointer value to be returned by mock_ptr_type() later.
will_set_parameter_uint_always
void will_set_parameter_uint_always(#function, #name, uintmax_t value)
Store a named unsigned integer value that will always be returned by mock_parameter_uint().
will_set_parameter_maybe
void will_set_parameter_maybe(#function, #name, uintmax_t value)
mock_parameter_uint
uintmax_t mock_parameter_uint(#name)
Retrieve an unsigned integer return value of the current function.
will_return_uint
void will_return_uint(#function, uintmax_t value)
Store a unsigned integer value to be returned by mock() later.
will_return_float
void will_return_float(#function, float value)
Store a float value to be returned by mock() later.
will_set_errno
void will_set_errno(#function, intmax_t value)
Store an integer value to set errno to by mock_errno() later.
will_return_float_count
void will_return_float_count(#function, float value, int count)
Store a float value to be returned a specified number of times by mock() later.
mock_ptr_type
type mock_ptr_type(#type)
Retrieve a typed return value of the current function.
will_set_parameter_ptr_count
void will_set_parameter_ptr_count(#function, #name, void *value, int count)
Store a named pointer value to be returned a specified number of times by mock_parameter_ptr() later.
mock_float
float mock_float(void)
Retrieve a float return value of the current function.
mock
uintmax_t mock(void)
Retrieve a return value of the current function.
mock_errno
void mock_errno(void)
set errno for the current function.
mock_parameter_int
intmax_t mock_parameter_int(#name)
Retrieve a named value for the current function and cast it to given type.
will_return_double
void will_return_double(#function, double value)
Store a double precision floating point value to be returned by mock() later.
will_set_parameter_ptr_maybe
void will_set_parameter_ptr_maybe(#function, #name, void *value)
Store a named pointer value that may be always returned by mock_parameter_ptr().
will_return_ptr_maybe
void will_return_ptr_maybe(#function, void *value)
Store a value that may be always returned by mock_ptr_type().
will_set_parameter_uint_count
void will_set_parameter_uint_count(#function, uintmax_t value, int count)
Store a named unsigned integer value to be returned a specified number of times by mock_parameter_uin...
mock_parameter_double
double mock_parameter_double(#name)
Retrieve a named double precision floating point value for the current function.
mock_ptr_type_checked
type mock_ptr_type_checked(#type)
Retrieve a typed return value of the current function with type checking.
expect_float_not_in_set
void expect_float_not_in_set(#function, #parameter, double value_array[], double epsilon)
Add an event to check if the float parameter value is not part of the provided array.
expect_not_in_range_count
void expect_not_in_range_count(#function, #parameter, uintmax_t minimum, uintmax_t maximum, size_t count)
Add an event to repeatedly check a parameter is outside a numerical range. The check would succeed if...
expect_float_not_in_range_count
void expect_float_not_in_range_count(#function, #parameter, double minimum, double maximum, double epsilon, size_t count)
Add an event to repeatedly check a parameter is outside a numerical range. The check would succeed if...
expect_uint_not_in_range_count
void expect_uint_not_in_range_count(#function, uintmax_t minimum, uintmax_t maximum, size_t count)
Add an event to repeatedly check an unsigned integer parameter is outside a numerical range....
expect_float_not_in_set_count
void expect_float_not_in_set_count(#function, #parameter, double value_array[], double epsilon, size_t count)
Add an event to check if the float parameter value is not part of the provided integer array.
expect_uint_not_in_range
void expect_uint_not_in_range(#function, uintmax_t minimum, uintmax_t maximum)
Add an event to check an unsigned integer parameter is outside a numerical range. The check would suc...
expect_any_count
void expect_any_count(#function, #parameter, size_t count)
Add an event to repeatedly check if a parameter (of any value) has been passed.
expect_not_string
void expect_not_string(#function, #parameter, const char *string)
Add an event to check if the parameter value isn't equal to the provided string.
check_expected_ptr
void check_expected_ptr(#parameter)
Determine whether a function parameter is correct.
expect_in_set_count
void expect_in_set_count(#function, #parameter, uintmax_t value_array[], size_t count)
expect_not_in_set_count
void expect_not_in_set_count(#function, #parameter, uintmax_t value_array[], size_t count)
check_expected
void check_expected(#parameter)
expect_not_string_count
void expect_not_string_count(#function, #parameter, const char *string, size_t count)
Add an event to check if the parameter value isn't equal to the provided string.
expect_in_range_count
void expect_in_range_count(#function, #parameter, uintmax_t minimum, uintmax_t maximum, size_t count)
expect_not_memory_count
void expect_not_memory_count(#function, #parameter, void *memory, size_t size, size_t count)
Add an event to repeatedly check if the parameter doesn't match an area of memory.
expect_int_in_set_count
void expect_int_in_set_count(#function, #parameter, intmax_t value_array[], size_t count)
Add an event to check if the parameter value is part of the provided integer array.
expect_check_data
void expect_check_data(function, parameter, CheckParameterValueData check_function, CMockaValueData check_data)
Add a custom parameter checking function using CMockaValueData (new API).
expect_in_range
void expect_in_range(#function, #parameter, uintmax_t minimum, uintmax_t maximum)
expect_float_in_set_count
void expect_float_in_set_count(#function, #parameter, double value_array[], double epsilon, size_t count)
Add an event to check if the float parameter value is part of the provided integer array.
expect_float
void expect_float(#function, #parameter, double value, double epsilon)
Add an event to check if a parameter is the given floating point value.
expect_uint_in_range_count
void expect_uint_in_range_count(#function, uintmax_t minimum, uintmax_t maximum, size_t count)
Add an event to repeatedly check an unsigned integer parameter is inside a numerical range....
check_expected_float
void check_expected_float(#parameter)
Determine whether a function parameter is correct.
expect_float_in_range
void expect_float_in_range(#function, #parameter, double minimum, double maximum, double epsilon)
Add an event to check a parameter is inside a numerical range. The check would succeed if minimum <= ...
expect_double
void expect_double(#function, #parameter, double value, double epsilon)
Add an event to check if a parameter is the given double precision floating point value.
expect_int_not_value_count
void expect_int_not_value_count(#function, intmax_t value, size_t count)
Add an event to repeatedly check if a parameter (int) isn't the given value.
expect_string
void expect_string(#function, #parameter, const char *string)
Add an event to check if the parameter value is equal to the provided string.
expect_int_value
void expect_int_value(#function, #parameter, intmax_t value)
Add an event to check if an integer parameter is the given value.
expect_int_not_in_set
void expect_int_not_in_set(#function, #parameter, intmax_t value_array[])
Add an event to check if the integer parameter value is not part of the provided integer array.
expect_any_always
void expect_any_always(#function, #parameter)
Add an event to always check if a parameter (of any value) has been passed.
expect_uint_in_range
void expect_uint_in_range(#function, uintmax_t minimum, uintmax_t maximum)
Add an event to check an unsigned integer parameter is inside a numerical range. The check would succ...
expect_not_memory
void expect_not_memory(#function, #parameter, void *memory, size_t size)
Add an event to check if the parameter doesn't match an area of memory.
expect_memory_count
void expect_memory_count(#function, #parameter, void *memory, size_t size, size_t count)
Add an event to repeatedly check if the parameter does match an area of memory.
expect_not_in_range
void expect_not_in_range(#function, #parameter, uintmax_t minimum, uintmax_t maximum)
Add an event to check a parameter is outside a numerical range. The check would succeed if minimum > ...
expect_float_in_range_count
void expect_float_in_range_count(#function, #parameter, double minimum, double maximum, double epsilon, size_t count)
Add an event to repeatedly check a parameter is inside a numerical range. The check would succeed if ...
expect_int_value_count
void expect_int_value_count(#function, intmax_t value, size_t count)
Add an event to repeatedly check if an integer parameter is the given value.
CheckParameterValue
int(* CheckParameterValue)(const uintmax_t value, const uintmax_t check_value_data)
Definition cmocka.h:6401
expect_uint_value
void expect_uint_value(#function, #parameter, uintmax_t value)
Add an event to check if an unsigned integer parameter is the given value.
expect_uint_value_count
void expect_uint_value_count(#function, uintmax_t value, size_t count)
Add an event to repeatedly check if an unsigned integer parameter is the given value.
check_expected_int
void check_expected_int(#parameter)
Determine whether a function parameter is correct.
expect_int_not_in_range_count
void expect_int_not_in_range_count(#function, intmax_t minimum, intmax_t maximum, size_t count)
Add an event to repeatedly check an integer parameter is outside a numerical range....
check_expected_double
void check_expected_double(#parameter)
Determine whether a function parameter is correct.
CheckIntParameterValue
int(* CheckIntParameterValue)(const intmax_t value, const intmax_t check_value_data)
Definition cmocka.h:6417
CheckParameterValueData
int(* CheckParameterValueData)(const CMockaValueData value, const CMockaValueData check_value_data)
Definition cmocka.h:6409
expect_not_value
void expect_not_value(#function, #parameter, uintmax_t value)
expect_memory
void expect_memory(#function, #parameter, void *memory, size_t size)
Add an event to check if the parameter does match an area of memory.
expect_int_in_range
void expect_int_in_range(#function, intmax_t minimum, intmax_t maximum)
Add an event to check an integer parameter is inside a numerical range. The check would succeed if mi...
expect_not_float
void expect_not_float(#function, #parameter, double value, double epsilon)
Add an event to check if a parameter isn't the given floating point value.
check_expected_uint
void check_expected_uint(#parameter)
Determine whether a function parameter is correct.
expect_uint_not_value_count
void expect_uint_not_value_count(#function, uintmax_t value, size_t count)
Add an event to repeatedly check if a parameter (uint) isn't the given value.
expect_uint_not_in_set_count
void expect_uint_not_in_set_count(#function, uintmax_t value_array[], size_t count)
Add an event to check if the unsigned integer parameter value is not part of the provided unsigned in...
expect_check_data_count
void expect_check_data_count(function, parameter, CheckParameterValueData check_function, CMockaValueData check_data, size_t count)
Add a custom parameter checking function using CMockaValueData with count (new API).
expect_any
void expect_any(#function, #parameter)
Add an event to check if a parameter (of any value) has been passed.
expect_check_count
void expect_check_count(function, parameter, CheckParameterValue check_function, const void *check_data, size_t count)
expect_int_in_range_count
void expect_int_in_range_count(#function, intmax_t minimum, intmax_t maximum, size_t count)
Add an event to repeatedly check an integer parameter is inside a numerical range....
expect_float_in_set
void expect_float_in_set(#function, #parameter, double value_array[], double epsilon)
Add an event to check if the float parameter value is part of the provided array.
expect_not_in_set
void expect_not_in_set(#function, #parameter, uintmax_t value_array[])
expect_float_not_in_range
void expect_float_not_in_range(#function, #parameter, double minimum, double maximum, double epsilon)
Add an event to check a parameter is outside a numerical range. The check would succeed if minimum > ...
expect_float_count
void expect_float_count(#function, #parameter, double value, double epsilon, size_t count)
Add an event to repeatedly check if a parameter is the given floating point value.
CheckUintParameterValue
int(* CheckUintParameterValue)(const uintmax_t value, const uintmax_t check_value_data)
Definition cmocka.h:6425
check_expected_any
void check_expected_any(#parameter)
Check that any parameter value matches the next value in the queue.
expect_value
void expect_value(#function, #parameter, uintmax_t value)
expect_double_count
void expect_double_count(#function, double value, double epsilon, size_t count)
Add an event to repeatedly check if a parameter is the given double precision floating point value.
expect_uint_in_set_count
void expect_uint_in_set_count(#function, #parameter, uintmax_t value_array[], size_t count)
Add an event to check if the parameter value is part of the provided unsigned integer array.
expect_check
void expect_check(function, parameter, CheckParameterValue check_function, const void *check_data)
expect_string_count
void expect_string_count(#function, #parameter, const char *string, size_t count)
Add an event to check if the parameter value is equal to the provided string.
expect_not_double_count
void expect_not_double_count(#function, double value, double epsilon, size_t count)
Add an event to repeatedly check if a parameter isn't the double precision floating point value.
expect_not_float_count
void expect_not_float_count(#function, #parameter, double value, double epsilon, size_t count)
Add an event to repeatedly check if a parameter isn't the floating point value.
expect_not_double
void expect_not_double(#function, #parameter, double value, double epsilon)
Add an event to check if a parameter isn't the given double precision floating point value.
expect_uint_not_value
void expect_uint_not_value(#function, #parameter, uintmax_t value)
Add an event to check if a parameter (uint) isn't the given value.
expect_int_not_value
void expect_int_not_value(#function, #parameter, intmax_t value)
Add an event to check if a parameter (int) isn't the given value.
expect_value_count
void expect_value_count(#function, #parameter, uintmax_t value, size_t count)
expect_not_value_count
void expect_not_value_count(#function, #parameter, uintmax_t value, size_t count)
expect_in_set
void expect_in_set(#function, #parameter, uintmax_t value_array[])
expect_uint_not_in_set
void expect_uint_not_in_set(#function, #parameter, uintmax_t value_array[])
Add an event to check if the unsigned integer parameter value is not part of the provided unsigned in...
expect_int_not_in_range
void expect_int_not_in_range(#function, intmax_t minimum, intmax_t maximum)
Add an event to check an integer parameter is outside a numerical range. The check would succeed if m...
expect_int_not_in_set_count
void expect_int_not_in_set_count(#function, intmax_t value_array[], size_t count)
Add an event to check if the integer parameter value is not part of the provided integer array.
CMCallbacks
Definition cmocka.h:6549
CMCallbacks::vprint_message
void(* vprint_message)(const char *const format, va_list args)
Definition cmocka.h:6557
CMCallbacks::vprint_error
void(* vprint_error)(const char *const format, va_list args)
Definition cmocka.h:6566
CMUnitTest
Definition cmocka.h:6481
CheckParameterEventData
Definition cmocka.h:6516
CheckParameterEvent
Definition cmocka.h:6504
GroupTest
Definition cmocka.h:6457
SourceLocation
Definition cmocka.h:6494
UnitTest
Definition cmocka.h:6448
CMockaValueData
Definition cmocka.h:6346
CMockaValueData::real_val
double real_val
Definition cmocka.h:6354
CMockaValueData::float_val
float float_val
Definition cmocka.h:6352
CMockaValueData::const_ptr
const void * const_ptr
Definition cmocka.h:6358
CMockaValueData::ptr
void * ptr
Definition cmocka.h:6356
CMockaValueData::int_val
intmax_t int_val
Definition cmocka.h:6348
CMockaValueData::uint_val
uintmax_t uint_val
Definition cmocka.h:6350