cmocka: 🔨 Utility Macros and Types

cmocka 2.0.0 Unit testing library with mock support

Loading...
Searching...
No Matches
Data Structures | Macros
🔨 Utility Macros and Types
📚 The CMocka API

Type conversions, casting helpers, and common data structures. More...

## Data Structures
union | CMockaValueData

## Macros
#define | cast_to_intmax_type(value)
#define | cast_to_uintmax_type(value)
#define | cast_ptr_to_uintmax_type(value)
#define | cast_to_double_type(value)
#define | cast_to_float_type(value)
#define | cast_to_void_pointer(ptr)
#define | cast_int_to_cmocka_value(value)
#define | cast_ptr_to_cmocka_value(value)
#define | assign_int_to_cmocka_value(value)
#define | assign_uint_to_cmocka_value(value)
#define | assign_float_to_cmocka_value(value)
#define | assign_double_to_cmocka_value(value)
#define | cmocka_tostring(val)

## Detailed Description

Type conversions, casting helpers, and common data structures.

Internal utilities and data types used throughout the CMocka API.

## Macro Definition Documentation

## ◆ assign_double_to_cmocka_value

#define assign_double_to_cmocka_value | ( |  | value | ) |

Value:
(CMockaValueData) \
{ \
.real_val = ((double)(value)) \
}
CMockaValueData
Definition cmocka.h:6338

Assign a double floating point value to CMockaValueData.

## ◆ assign_float_to_cmocka_value

#define assign_float_to_cmocka_value | ( |  | value | ) |

Value:
(CMockaValueData) \
{ \
.float_val = ((float)(value)) \
}

Assign a floating point value to CMockaValueData.

## ◆ assign_int_to_cmocka_value

#define assign_int_to_cmocka_value | ( |  | value | ) |

Value:
(CMockaValueData) \
{ \
.int_val = (value) \
}

Assign an integer value to CMockaValueData.

## ◆ assign_uint_to_cmocka_value

#define assign_uint_to_cmocka_value | ( |  | value | ) |

Value:
(CMockaValueData) \
{ \
.uint_val = (value) \
}

Assign an unsigned integer value to CMockaValueData.

## ◆ cast_int_to_cmocka_value

#define cast_int_to_cmocka_value | ( |  | value | ) |

Value:
(CMockaValueData) \
{ \
.uint_val = (uintmax_t)(value) \
}

Perform a cast from an integer to CMockaValueData.

For backwards compatibility reasons, this explicitly casts to uintmax_t. For most compilers, this will suppress warnings about passing float/intmax_t to this macro.

## ◆ cast_ptr_to_cmocka_value

#define cast_ptr_to_cmocka_value | ( |  | value | ) |

Value:
(CMockaValueData) \
{ \
.ptr = (value) \
}

Perform a cast from a pointer to CMockaValueData.

## ◆ cast_ptr_to_uintmax_type

#define cast_ptr_to_uintmax_type | ( |  | value | ) |

Value:
((uintmax_t)(uintptr_t)(value))

## ◆ cast_to_double_type

#define cast_to_double_type | ( |  | value | ) |

Value:
((double)(value))

## ◆ cast_to_float_type

#define cast_to_float_type | ( |  | value | ) |

Value:
((float)(value))

## ◆ cast_to_intmax_type

#define cast_to_intmax_type | ( |  | value | ) |

Value:
((intmax_t)(value))

## ◆ cast_to_uintmax_type

#define cast_to_uintmax_type | ( |  | value | ) |

Value:
((uintmax_t)(value))

## ◆ cast_to_void_pointer

#define cast_to_void_pointer | ( |  | ptr | ) |

Value:
((void *)(uintptr_t)(ptr))

Perform cast to void pointer.

ISO C forbids conversion between function pointers and void*. This macro provides a portable way to perform such conversions by casting through uintptr_t, which is allowed by POSIX and works on all practical platforms.

## ◆ cmocka_tostring

#define cmocka_tostring | ( |  | val | ) |

Value:
#val