Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

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)    z_ztest_expect_data(STRINGIFY(func), STRINGIFY(param), (void *)(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)    z_ztest_return_data(STRINGIFY(func), STRINGIFY(param), (void *)(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)    z_ztest_returns_value(STRINGIFY(func), (uintptr_t)(value))
 Tell func that it should return value.
 
#define ztest_get_return_value()   z_ztest_get_return_value(__func__)
 Get the return value for current function.
 
#define ztest_get_return_value_ptr()    ((void *)z_ztest_get_return_value(__func__))
 Get the return value as a pointer for current function.
 

Detailed Description

This module provides simple mocking functions for unit testing.

These need CONFIG_ZTEST_MOCKING=y.

Macro Definition Documentation

◆ ztest_check_expected_data

#define ztest_check_expected_data (   param,
  length 
)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>

Value:
z_ztest_check_expected_data(__func__, STRINGIFY(param), \
(void *)(param), (length))
#define STRINGIFY(s)
Definition: common.h:134

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.

Parameters
paramParameter to check
lengthLength of the data to compare

◆ ztest_check_expected_value

#define ztest_check_expected_value (   param)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>

Value:
z_ztest_check_expected_value(__func__, STRINGIFY(param), \
(uintptr_t)(param))
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:105

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.

Parameters
paramParameter to check

◆ ztest_copy_return_data

#define ztest_copy_return_data (   param,
  length 
)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>

Value:
z_ztest_copy_return_data(__func__, STRINGIFY(param), \
(void *)(param), (length))

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.

Parameters
paramParameter to return data for
lengthLength of the data to return

◆ ztest_expect_data

#define ztest_expect_data (   func,
  param,
  data 
)     z_ztest_expect_data(STRINGIFY(func), STRINGIFY(param), (void *)(data))

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/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.

Parameters
funcFunction in question
paramParameter for which the data should be set
datapointer for the data for parameter param

◆ ztest_expect_value

#define ztest_expect_value (   func,
  param,
  value 
)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>

Value:
z_ztest_expect_value(STRINGIFY(func), STRINGIFY(param), \
(uintptr_t)(value))

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.

Parameters
funcFunction in question
paramParameter for which the value should be set
valueValue for param

◆ ztest_get_return_value

#define ztest_get_return_value ( )    z_ztest_get_return_value(__func__)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/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.

Returns
The value the current function should return

◆ ztest_get_return_value_ptr

#define ztest_get_return_value_ptr ( )     ((void *)z_ztest_get_return_value(__func__))

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/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.

Returns
The value the current function should return as a void *

◆ ztest_return_data

#define ztest_return_data (   func,
  param,
  data 
)     z_ztest_return_data(STRINGIFY(func), STRINGIFY(param), (void *)(data))

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/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.

Parameters
funcFunction in question
paramParameter for which the data should be set
datapointer for the data for parameter param

◆ ztest_returns_value

#define ztest_returns_value (   func,
  value 
)     z_ztest_returns_value(STRINGIFY(func), (uintptr_t)(value))

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_mock.h>

Tell func that it should return value.

Parameters
funcFunction that should return value
valueValue to return from func