mimic++ v9.2.1
Loading...
Searching...
No Matches
requirement

Requirements determine, whether an expectation matches an incoming call. More...

Collaboration diagram for requirement:

Functions

template<std::size_t index, typename Matcher, typename Projection = std::identity>
constexpr auto mimicpp::expect::arg (Matcher &&matcher, Projection &&projection={}) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Matcher >, Matcher > &&std::is_nothrow_constructible_v< std::remove_cvref_t< Projection >, Projection >)
 Checks whether the selected argument satisfies the given matcher.
 
template<std::size_t first, std::size_t... others, typename Matcher, typename... Projections>
constexpr auto mimicpp::expect::args (Matcher &&matcher, Projections &&... projections) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Matcher >, Matcher > &&(... &&std::is_nothrow_move_constructible_v< std::remove_cvref_t< Projections > >))
 Checks whether the selected arguments satisfy the given matcher.
 
template<typename Matcher>
constexpr auto mimicpp::expect::all_args (Matcher &&matcher) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Matcher >, Matcher >)
 Checks whether the all arguments satisfy the given matcher.
 

Detailed Description

Requirements determine, whether an expectation matches an incoming call.

Requirements are the building blocks, which determine whether a call satisfies the expectation. If any of the specified requirements fail, there is no match.

Note
An expectation without requirements matches any call.

Function Documentation

◆ all_args()

template<typename Matcher>
auto mimicpp::expect::all_args ( Matcher && matcher)
nodiscardconstexprnoexcept

Checks whether the all arguments satisfy the given matcher.

Template Parameters
MatcherThe matcher type.
Parameters
matcherThe matcher.

This requirement checks, whether the all arguments satisfy the given matcher. It's useful, when all arguments must be checked together, because they have some kind of relationship. When n arguments are provided the matcher must accept n arguments.

For a list of built-in matchers, see matcher section.

namespace matches = mimicpp::matches;
using matches::_;
namespace expect = mimicpp::expect;
const std::string str{"Hello, World!"};
mimicpp::Mock<void(const char*, std::size_t)> mock{};
SCOPED_EXP mock.expect_call(_, _)
and expect::all_args(matches::predicate(
[&](const char* data, std::size_t length) { return str == std::string_view{data, length}; }));
mock(str.data(), str.size());

◆ arg()

template<std::size_t index, typename Matcher, typename Projection = std::identity>
auto mimicpp::expect::arg ( Matcher && matcher,
Projection && projection = {} )
nodiscardconstexprnoexcept

Checks whether the selected argument satisfies the given matcher.

Template Parameters
indexThe index of the selected argument.
MatcherThe matcher type.
Parameters
matcherThe matcher.
projectionProjection to apply to the argument.

This requirement checks, whether the selected argument matches the given matcher. One argument can be checked multiple times in different requirements and all results will be combined as conjunction.

For a list of built-in matchers, see matcher section.

namespace matches = mimicpp::matches;
namespace expect = mimicpp::expect;
mimicpp::Mock<void(int)> mock{};
SCOPED_EXP mock.expect_call(_)
and expect::arg<0>(matches::gt(42))
and expect::arg<0>(matches::lt(1338));
mock(1337);

◆ args()

template<std::size_t first, std::size_t... others, typename Matcher, typename... Projections>
auto mimicpp::expect::args ( Matcher && matcher,
Projections &&... projections )
nodiscardconstexprnoexcept

Checks whether the selected arguments satisfy the given matcher.

Template Parameters
firstThe index of the first selected argument.
othersThe indices of other selected arguments.
MatcherThe matcher type.
Parameters
matcherThe matcher.
projectionsProjections, the arguments will be applied on.

This requirement checks, whether the selected arguments match the given matcher. It's useful, when multiple arguments must be checked together, because they have some kind of relationship. When n indices are provided the matcher must accept n arguments.

The projections will be applied from the beginning: E.g. if n arguments and p projections are given (with 0 <= p <= n), then the first p arguments will be applied on these projections (the i-th argument on the i-th projection).

Note
std::identity can be used to skip arguments, which shall not be projected.
See also
https://en.cppreference.com/w/cpp/utility/functional/identity

For a list of built-in matchers, see matcher section.

namespace matches = mimicpp::matches;
using matches::_;
namespace expect = mimicpp::expect;
mimicpp::Mock<void(int, int)> mock{};
SCOPED_EXP mock.expect_call(_, _)
and expect::args<0, 1>(matches::predicate(std::less{})); // this requires 0th arg < 1st arg
mock(42, 1337);
SCOPED_EXP mock.expect_call(_, _)
and expect::args<1, 0>(matches::predicate(std::less{})); // the index order can be freely changed
mock(1337, 42);
SCOPED_EXP mock.expect_call(_, _)
and expect::args<1, 1>(matches::predicate(std::equal_to{})); // the same index may appear more than once
mock(42, 42);