Class hal::spy_handler
template <typename... args_t>
ClassList > hal > spy_handler
Helper utility for making mocks for class functions that return status. More...
#include <testing.hpp>
Public Functions
Type | Name |
---|---|
const auto & | call_history () const Return the call history of the save function. |
const auto & | history (size_t p_call) const Return argument from one of call history parameters. |
status | record (args_t... p_args) Record the arguments of a function being spied on. |
void | reset () Reset call recordings and turns off error trigger. |
void | trigger_error_on_call (int p_call_count_before_trigger) Set the record function to return an error after a specified number of recordings. |
Detailed Description
This class stores records of a functions call history in order to be recovered later for inspection in tests and simulations.
See pwm_mock.hpp and tests/pwm_mock.test.cpp as an example of how this is done in practice.
Template parameters:
args_t
- the arguments of the class function
Public Functions Documentation
function call_history
Return the call history of the save function.
inline const auto & hal::spy_handler::call_history () const
Returns:
const auto& - reference to the call history vector
function history
Return argument from one of call history parameters.
template<size_t ArgumentIndex>
inline const auto & hal::spy_handler::history (
size_t p_call
) const
Parameters:
p_call
- history call from 0 to N
Returns:
const auto& - reference to the call history vector
Exception:
std::out_of_range
- if p_call is beyond the size of call_history
function record
Record the arguments of a function being spied on.
inline status hal::spy_handler::record (
args_t... p_args
)
Parameters:
p_args
- arguments to record
Returns:
status - success or failure error trigger has been reached.
function reset
inline void hal::spy_handler::reset ()
function trigger_error_on_call
Set the record function to return an error after a specified number of recordings.
inline void hal::spy_handler::trigger_error_on_call (
int p_call_count_before_trigger
)
Parameters:
p_call_count_before_trigger
- how many calls before an error is returned.
The documentation for this class was generated from the following file libraries/include/libhal-mock/testing.hpp