tests: unit: util: add array for-each tests
Add tests for the following two macros * ARRAY_FOR_EACH(array, idx_var) * ARRAY_FOR_EACH_PTR(array, ptr_var) Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This commit is contained in:
parent
42335036b7
commit
1695b5a0b2
1 changed files with 28 additions and 0 deletions
|
@ -462,6 +462,34 @@ ZTEST(util, test_ARRAY_INDEX)
|
|||
}
|
||||
}
|
||||
|
||||
ZTEST(util, test_ARRAY_FOR_EACH)
|
||||
{
|
||||
size_t j = -1;
|
||||
size_t array[3];
|
||||
|
||||
ARRAY_FOR_EACH(array, i) {
|
||||
j = i + 1;
|
||||
}
|
||||
|
||||
zassert_equal(j, ARRAY_SIZE(array));
|
||||
}
|
||||
|
||||
ZTEST(util, test_ARRAY_FOR_EACH_PTR)
|
||||
{
|
||||
size_t j = 0;
|
||||
size_t array[3];
|
||||
size_t *ptr[3];
|
||||
|
||||
ARRAY_FOR_EACH_PTR(array, p) {
|
||||
ptr[j] = p;
|
||||
++j;
|
||||
}
|
||||
|
||||
zassert_equal(ptr[0], &array[0]);
|
||||
zassert_equal(ptr[1], &array[1]);
|
||||
zassert_equal(ptr[2], &array[2]);
|
||||
}
|
||||
|
||||
ZTEST(util, test_PART_OF_ARRAY)
|
||||
{
|
||||
size_t i;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue