6#ifndef MIMICPP_EXPECTATION_BUILDER_HPP
7#define MIMICPP_EXPECTATION_BUILDER_HPP
20 typename SequenceConfig,
22 typename FinalizePolicy,
23 expectation_policy_for<Signature>... Policies>
33 template <
typename FinalizePolicyArg,
typename PolicyListArg>
34 requires std::constructible_from<FinalizePolicy, FinalizePolicyArg>
35 && std::constructible_from<PolicyListT, PolicyListArg>
38 std::shared_ptr<StorageT> storage,
39 detail::TimesConfig timesConfig,
40 SequenceConfig sequenceConfig,
41 FinalizePolicyArg&& finalizePolicyArg,
42 PolicyListArg&& policyListArg
44 : m_Storage{std::move(storage)},
45 m_TimesConfig{std::move(timesConfig)},
46 m_SequenceConfig{std::move(sequenceConfig)},
47 m_FinalizePolicy{std::forward<FinalizePolicyArg>(finalizePolicyArg)},
48 m_ExpectationPolicies{std::forward<PolicyListArg>(policyListArg)}
50 assert(m_Storage &&
"Storage is nullptr.");
60 template <
typename Policy>
61 requires std::same_as<expectation_policies::InitFinalize, FinalizePolicy>
62 && (!std::same_as<expectation_policies::InitFinalize, std::remove_cvref_t<Policy>>)
65 constexpr auto operator &&(Policy&& policy) &&
71 std::remove_cvref_t<Policy>,
74 return ExtendedExpectationBuilderT{
76 std::move(m_TimesConfig),
77 std::move(m_SequenceConfig),
78 std::forward<Policy>(policy),
79 std::move(m_ExpectationPolicies)
83 template <
typename Policy>
94 std::remove_cvref_t<Policy>>;
96 return ExtendedExpectationBuilderT{
98 std::move(m_TimesConfig),
99 std::move(m_SequenceConfig),
100 std::move(m_FinalizePolicy),
102 [&](
auto&... policies)
noexcept
104 return std::forward_as_tuple(
105 std::move(policies)...,
106 std::forward<Policy>(policy));
108 m_ExpectationPolicies)
114 requires (!timesConfigured)
124 std::move(m_Storage),
126 std::move(m_SequenceConfig),
127 std::move(m_FinalizePolicy),
128 std::move(m_ExpectationPolicies)
132 template <
typename... Sequences>
134 constexpr auto operator &&(sequence::detail::Config<Sequences...>&& config) &&
136 sequence::detail::Config newConfig = m_SequenceConfig.concat(std::move(config));
145 return ExtendedExpectationBuilderT{
146 std::move(m_Storage),
147 std::move(m_TimesConfig),
148 std::move(newConfig),
149 std::move(m_FinalizePolicy),
150 std::move(m_ExpectationPolicies)
159 "For non-void return types, a finalize policy must be set.");
162 std::move(m_Storage),
164 [&](
auto&... policies)
167 std::move(m_TimesConfig),
168 std::move(m_SequenceConfig)
173 decltype(controlPolicy),
177 return std::make_unique<ExpectationT>(
179 std::move(controlPolicy),
180 std::move(m_FinalizePolicy),
181 std::move(policies)...);
183 m_ExpectationPolicies)
188 std::shared_ptr<StorageT> m_Storage;
189 detail::TimesConfig m_TimesConfig{};
190 SequenceConfig m_SequenceConfig{};
191 FinalizePolicy m_FinalizePolicy{};
196namespace mimicpp::detail
198 template <
typename Param,
typename Arg>
199 requires matcher_for<
200 std::remove_cvref_t<Arg>,
203 constexpr auto make_arg_matcher(Arg&& arg, [[maybe_unused]]
const priority_tag<2>)
205 return std::forward<Arg>(arg);
208 template <
string Param,
string Arg>
210 constexpr auto make_arg_matcher(Arg&& arg, [[maybe_unused]]
const priority_tag<1>)
215 template <
typename Param, std::equality_comparable_with<Param> Arg>
217 constexpr auto make_arg_matcher(Arg&& arg, [[maybe_unused]]
const priority_tag<0>)
222 constexpr priority_tag<2> max_make_arg_matcher_tag{};
224 template <
typename Arg,
typename Target>
225 concept requirement_for =
requires
228 detail::make_arg_matcher<Target, Arg>(
230 max_make_arg_matcher_tag)
231 } -> matcher_for<Target>;
240 requires requirement_for<Arg, Param>
241 constexpr auto make_arg_policy(Arg&& arg)
244 detail::make_arg_matcher<Param, Arg>(
245 std::forward<Arg>(arg),
246 max_make_arg_matcher_tag));
249 template <
typename Signature,
typename Builder, std::size_t... indices,
typename... Args>
251 constexpr auto extend_builder_with_arg_policies(
253 const std::index_sequence<indices...>,
258 std::forward<Builder>(builder)
260 && detail::make_arg_policy<Signature, indices>(
261 std::forward<Args>(args)));
264 template <
typename Signature,
typename... Args>
265 constexpr auto make_expectation_builder(
266 std::shared_ptr<ExpectationCollection<Signature>> expectations,
270 using BaseBuilderT = BasicExpectationBuilder<
272 sequence::detail::Config<>,
274 expectation_policies::InitFinalize
277 return detail::extend_builder_with_arg_policies<Signature>(
279 std::move(expectations),
281 sequence::detail::Config<>{},
282 expectation_policies::InitFinalize{},
285 std::index_sequence_for<Args...>{},
286 std::forward<Args>(args)...);
290#define MIMICPP_DETAIL_UNIQUE_NAME(prefix, counter) prefix##counter
291#define MIMICPP_DETAIL_SCOPED_EXPECTATION_IMPL(counter) \
293 const ::mimicpp::ScopedExpectation MIMICPP_DETAIL_UNIQUE_NAME(_mimicpp_expectation_, counter) =
299#define MIMICPP_SCOPED_EXPECTATION MIMICPP_DETAIL_SCOPED_EXPECTATION_IMPL(__COUNTER__)
301#ifndef MIMICPP_CONFIG_ONLY_PREFIXED_MACROS
307 #define SCOPED_EXP MIMICPP_SCOPED_EXPECTATION
Definition ExpectationBuilder.hpp:25
ScopedExpectation finalize(const std::source_location &sourceLocation) &&
Definition ExpectationBuilder.hpp:155
BasicExpectationBuilder(BasicExpectationBuilder &&)=default
std::tuple< Policies... > PolicyListT
Definition ExpectationBuilder.hpp:28
BasicExpectationBuilder & operator=(const BasicExpectationBuilder &)=delete
typename Expectation< Signature >::ReturnT ReturnT
Definition ExpectationBuilder.hpp:29
BasicExpectationBuilder(const BasicExpectationBuilder &)=delete
~BasicExpectationBuilder()=default
constexpr BasicExpectationBuilder(std::shared_ptr< StorageT > storage, detail::TimesConfig timesConfig, SequenceConfig sequenceConfig, FinalizePolicyArg &&finalizePolicyArg, PolicyListArg &&policyListArg) noexcept
Definition ExpectationBuilder.hpp:37
constexpr auto operator&&(Policy &&policy) &&
Definition ExpectationBuilder.hpp:65
The actual expectation template.
Definition Expectation.hpp:415
Definition ControlPolicy.hpp:165
Collects all expectations for a specific (decayed) signature.
Definition Fwd.hpp:176
signature_return_type_t< Signature > ReturnT
The return type.
Definition Expectation.hpp:117
Takes the ownership of an expectation and check whether it's satisfied during destruction.
Definition Expectation.hpp:568
Determines, whether the given type satisfies the requirements of an expectation-policy for the given ...
Definition Expectation.hpp:363
Determines, whether the given type satisfies the requirements of a finalize-policy for the given sign...
Definition Expectation.hpp:378
constexpr auto eq(T &&value)
Tests, whether the target compares equal to the expected value.
Definition Matcher.hpp:350
constexpr auto eq(Pattern &&pattern)
Tests, whether the target string compares equal to the expected string.
Definition Matcher.hpp:594
constexpr auto arg(Matcher &&matcher, Projection projection={}) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Matcher >, Matcher > &&std::is_nothrow_move_constructible_v< Projection >)
Checks, whether the selected argument matches the given matcher.
Definition ExpectationPolicies.hpp:405
typename signature_param_type< index, Signature >::type signature_param_type_t
Convenience alias, exposing the type member alias of the actual type-trait.
Definition Fwd.hpp:100
Definition BoostTest.hpp:20