cmocka: Implement _expect_int_in_set()

This commit is contained in:
Andreas Schneider 2024-01-06 13:20:13 +01:00
parent de511ab272
commit 4b2dafe85d
2 changed files with 67 additions and 0 deletions

View File

@ -2868,6 +2868,14 @@ void _expect_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_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_not_in_set(
const char* const function, const char* const parameter,
const char* const file, const int line, const uintmax_t values[],

View File

@ -1692,6 +1692,15 @@ static int check_in_set(const CMockaValueData value,
check_value_data), 0);
}
static int check_int_in_set(const CMockaValueData value,
const CMockaValueData check_value_data) {
return int_value_in_set_display_error(
value.int_val,
cast_cmocka_value_to_pointer(struct check_integer_set *,
check_value_data),
0);
}
/* CheckParameterValue callback to check whether a value isn't within a set. */
static int check_not_in_set(const CMockaValueData value,
@ -1725,6 +1734,39 @@ static void expect_set(
check_data, &check_integer_set->event, count);
}
static 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 CheckParameterValue check_function,
const size_t count)
{
struct check_integer_set *const check_integer_set =
calloc(number_of_values,
sizeof(struct check_integer_set) + sizeof(values[0]));
intmax_t *const set = (intmax_t *)(check_integer_set + 1);
declare_initialize_value_pointer_pointer(check_data, check_integer_set);
assert_non_null(check_integer_set);
assert_non_null(values);
assert_true(number_of_values);
memcpy(set, values, number_of_values * sizeof(values[0]));
check_integer_set->set = set;
check_integer_set->size_of_set = number_of_values;
_expect_check(function,
parameter,
file,
line,
check_function,
check_data,
&check_integer_set->event,
count);
}
/* Add an event to check whether a value is in a set. */
void _expect_in_set(
@ -1736,6 +1778,23 @@ void _expect_in_set(
check_in_set, 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)
{
expect_int_in_set(function,
parameter,
file,
line,
values,
number_of_values,
check_int_in_set,
count);
}
/* Add an event to check whether a value isn't in a set. */
void _expect_not_in_set(