Zephyr API Documentation 4.0.0-rc3
A Scalable Open Source RTOS
|
This module provides simple mocking functions for unit testing. More...
Macros | |
#define | ztest_expect_value(func, param, value) |
Tell function func to expect the value value for param. | |
#define | ztest_check_expected_value(param) |
If param doesn't match the value set by ztest_expect_value(), fail the test. | |
#define | ztest_expect_data(func, param, data) |
Tell function func to expect the data data for param. | |
#define | ztest_check_expected_data(param, length) |
If data pointed by param don't match the data set by ztest_expect_data(), fail the test. | |
#define | ztest_return_data(func, param, data) |
Tell function func to return the data data for param. | |
#define | ztest_copy_return_data(param, length) |
Copy the data set by ztest_return_data to the memory pointed by param. | |
#define | ztest_returns_value(func, value) |
Tell func that it should return value. | |
#define | ztest_get_return_value() |
Get the return value for current function. | |
#define | ztest_get_return_value_ptr() |
Get the return value as a pointer for current function. | |
This module provides simple mocking functions for unit testing.
These need CONFIG_ZTEST_MOCKING=y.
#define ztest_check_expected_data | ( | param, | |
length ) |
#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>
If data pointed by param don't match the data set by ztest_expect_data(), fail the test.
This will first check that param is expected to be null or non-null and then check whether the data pointed by parameter is equal to expected data. If either of these checks fail, the current test will fail. This must be called from the called function.
param | Parameter to check |
length | Length of the data to compare |
#define ztest_check_expected_value | ( | param | ) |
#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>
If param doesn't match the value set by ztest_expect_value(), fail the test.
This will first check that does param have a value to be expected, and then checks whether the value of the parameter is equal to the expected value. If either of these checks fail, the current test will fail. This must be called from the called function.
param | Parameter to check |
#define ztest_copy_return_data | ( | param, | |
length ) |
#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>
Copy the data set by ztest_return_data to the memory pointed by param.
This will first check that param is not null and then copy the data. This must be called from the called function.
param | Parameter to return data for |
length | Length of the data to return |
#define ztest_expect_data | ( | func, | |
param, | |||
data ) |
#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>
Tell function func to expect the data data for param.
When using ztest_check_expected_data(), the data pointed to by param should be same data in this function. Only data pointer is stored by this function, so it must still be valid when ztest_check_expected_data is called.
func | Function in question |
param | Parameter for which the data should be set |
data | pointer for the data for parameter param |
#define ztest_expect_value | ( | func, | |
param, | |||
value ) |
#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>
Tell function func to expect the value value for param.
When using ztest_check_expected_value(), tell that the value of param should be value. The value will internally be stored as an uintptr_t
.
func | Function in question |
param | Parameter for which the value should be set |
value | Value for param |
#define ztest_get_return_value | ( | ) |
#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>
Get the return value for current function.
The return value must have been set previously with ztest_returns_value(). If no return value exists, the current test will fail.
#define ztest_get_return_value_ptr | ( | ) |
#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>
Get the return value as a pointer for current function.
The return value must have been set previously with ztest_returns_value(). If no return value exists, the current test will fail.
void *
#define ztest_return_data | ( | func, | |
param, | |||
data ) |
#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>
Tell function func to return the data data for param.
When using ztest_return_data(), the data pointed to by param should be same data in this function. Only data pointer is stored by this function, so it must still be valid when ztest_copy_return_data is called.
func | Function in question |
param | Parameter for which the data should be set |
data | pointer for the data for parameter param |
#define ztest_returns_value | ( | func, | |
value ) |
#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>
Tell func that it should return value.
func | Function that should return value |
value | Value to return from func |