6#ifndef MIMICPP_MOCK_HPP
7#define MIMICPP_MOCK_HPP
17namespace mimicpp::detail
19 template <
typename Derived,
typename Signature>
20 using call_interface_t =
typename call_convention_traits<
23 template <
typename Derived,
typename Signature,
typename... Params>
24 class DefaultCallInterface<
34 const std::source_location& from = std::source_location::current()) noexcept(
signature_is_noexcept_v<Signature>)
36 return static_cast<const Derived&
>(*this)
37 .handle_call(std::tuple{std::ref(params)...}, from);
41 template <
typename Derived,
typename Signature,
typename... Params>
42 class DefaultCallInterface<
52 const std::source_location& from = std::source_location::current()) const noexcept(
signature_is_noexcept_v<Signature>)
54 return static_cast<const Derived&
>(*this)
55 .handle_call(std::tuple{std::ref(params)...}, from);
59 template <
typename Derived,
typename Signature,
typename... Params>
60 class DefaultCallInterface<
72 return static_cast<const Derived&
>(*this)
73 .handle_call(std::tuple{std::ref(params)...}, from);
77 template <
typename Derived,
typename Signature,
typename... Params>
78 class DefaultCallInterface<
88 const std::source_location& from = std::source_location::current()) const& noexcept(
signature_is_noexcept_v<Signature>)
90 return static_cast<const Derived&
>(*this)
91 .handle_call(std::tuple{std::ref(params)...}, from);
95 template <
typename Derived,
typename Signature,
typename... Params>
96 class DefaultCallInterface<
101 type_list<Params...>>
108 return static_cast<const Derived&
>(*this)
109 .handle_call(std::tuple{std::ref(params)...}, from);
113 template <
typename Derived,
typename Signature,
typename... Params>
114 class DefaultCallInterface<
119 type_list<Params...>>
124 const std::source_location& from = std::source_location::current()) const&& noexcept(
signature_is_noexcept_v<Signature>)
126 return static_cast<const Derived&
>(*this)
127 .handle_call(std::tuple{std::ref(params)...}, from);
139 template <
typename Derived,
typename Signature,
typename... Params>
145 type_list<Params...>>
148 template <
typename... Args>
149 requires(... && requirement_for<Args, Params>)
151 constexpr auto expect_call(Args&&... args)
153 return static_cast<const Derived&
>(*this)
154 .make_expectation_builder(std::forward<Args>(args)...);
158 template <
typename Derived,
typename Signature,
typename... Params>
164 type_list<Params...>>
167 template <
typename... Args>
168 requires(... && requirement_for<Args, Params>)
170 constexpr auto expect_call(Args&&... args)
const
172 return static_cast<const Derived&
>(*this)
173 .make_expectation_builder(std::forward<Args>(args)...);
177 template <
typename Derived,
typename Signature,
typename... Params>
183 type_list<Params...>>
186 template <
typename... Args>
187 requires(... && requirement_for<Args, Params>)
189 constexpr auto expect_call(Args&&... args) &
191 return static_cast<const Derived&
>(*this)
192 .make_expectation_builder(std::forward<Args>(args)...);
196 template <
typename Derived,
typename Signature,
typename... Params>
202 type_list<Params...>>
205 template <
typename... Args>
206 requires(... && requirement_for<Args, Params>)
208 constexpr auto expect_call(Args&&... args)
const&
210 return static_cast<const Derived&
>(*this)
211 .make_expectation_builder(std::forward<Args>(args)...);
215 template <
typename Derived,
typename Signature,
typename... Params>
221 type_list<Params...>>
224 template <
typename... Args>
225 requires(... && requirement_for<Args, Params>)
227 constexpr auto expect_call(Args&&... args) &&
229 return static_cast<const Derived&
>(*this)
230 .make_expectation_builder(std::forward<Args>(args)...);
234 template <
typename Derived,
typename Signature,
typename... Params>
240 type_list<Params...>>
243 template <
typename... Args>
244 requires(... && requirement_for<Args, Params>)
246 constexpr auto expect_call(Args&&... args)
const&&
248 return static_cast<const Derived&
>(*this)
249 .make_expectation_builder(std::forward<Args>(args)...);
253 template <
typename Signature>
254 using expectation_collection_ptr_for = std::shared_ptr<ExpectationCollection<signature_decay_t<Signature>>>;
256 template <
typename Signature,
typename ParamList = signature_param_list_t<Signature>>
259 template <
typename Signature,
typename... Params>
260 class BasicMock<Signature, type_list<Params...>>
261 :
public MockFrontend<
263 BasicMock<Signature, type_list<Params...>>,
264 signature_remove_call_convention_t<Signature>>,
265 public call_interface_t<
266 BasicMock<Signature, type_list<Params...>>,
271 friend class MockFrontend<BasicMock, SignatureT>;
272 friend call_interface_t<BasicMock, Signature>;
278 using ExpectationCollectionPtrT = expectation_collection_ptr_for<SignatureT>;
281 explicit BasicMock(ExpectationCollectionPtrT collection) noexcept
282 : m_Expectations{std::move(collection)}
287 ExpectationCollectionPtrT m_Expectations;
291 std::tuple<std::reference_wrapper<std::remove_reference_t<Params>>...>&& params,
292 const std::source_location& from)
const
294 return m_Expectations->handle_call(
296 .args = std::move(params),
297 .fromCategory = refQualification,
298 .fromConstness = constQualification,
299 .fromSourceLocation = from});
302 template <
typename... Args>
304 constexpr auto make_expectation_builder(Args&&... args)
const
306 return detail::make_expectation_builder(m_Expectations, std::forward<Args>(args)...)
307 && expectation_policies::Category<refQualification>{}
308 && expectation_policies::Constness<constQualification>{};
312 template <
typename List>
313 struct expectation_collection_factory;
315 template <
typename... UniqueSignatures>
316 struct expectation_collection_factory<type_list<UniqueSignatures...>>
322 std::make_shared<ExpectationCollection<UniqueSignatures>>()...};
385 template <
typename FirstSignature,
typename... OtherSignatures>
388 :
public detail::BasicMock<FirstSignature>,
389 public detail::BasicMock<OtherSignatures>...
392 using detail::BasicMock<FirstSignature>::operator();
393 using detail::BasicMock<FirstSignature>::expect_call;
394 using detail::BasicMock<OtherSignatures>::operator()...;
395 using detail::BasicMock<OtherSignatures>::expect_call...;
408 detail::expectation_collection_factory<
409 detail::unique_list_t<
437 template <
typename... Collections>
438 explicit Mock(std::tuple<Collections...> collections) noexcept
439 : detail::BasicMock<FirstSignature>{std::get<detail::expectation_collection_ptr_for<FirstSignature>>(collections)},
440 detail::BasicMock<OtherSignatures>{std::get<detail::expectation_collection_ptr_for<OtherSignatures>>(collections)}...
A Mock type, which fully supports overload sets.
Definition Mock.hpp:390
~Mock()=default
Defaulted destructor.
Mock & operator=(Mock &&)=default
Defaulted move assignment operator.
Mock(Mock &&)=default
Defaulted move constructor.
Mock(const Mock &)=delete
Deleted copy constructor.
Mock & operator=(const Mock &)=delete
Deleted copy assignment operator.
Mock()
Default constructor.
Definition Mock.hpp:406
constexpr bool is_overload_set_v
Convenience constant, exposing the value member of the actual type-trait.
Definition Fwd.hpp:287
typename signature_call_convention< Signature >::type signature_call_convention_t
Convenience alias, exposing the type member alias of the actual type-trait.
Definition Fwd.hpp:75
constexpr Constness signature_const_qualification_v
Convenience constant, exposing the value member of the actual type-trait.
Definition Fwd.hpp:187
typename signature_decay< Signature >::type signature_decay_t
Convenience alias, exposing the type member alias of the actual type-trait.
Definition Fwd.hpp:155
constexpr bool signature_is_noexcept_v
Convenience constant, exposing the value member of the actual type-trait.
Definition Fwd.hpp:219
typename signature_param_list< Signature >::type signature_param_list_t
Convenience alias, exposing the type member alias of the actual type-trait.
Definition Fwd.hpp:251
constexpr ValueCategory signature_ref_qualification_v
Convenience constant, exposing the value member of the actual type-trait.
Definition Fwd.hpp:203
typename signature_remove_call_convention< Signature >::type signature_remove_call_convention_t
Convenience alias, exposing the type member alias of the actual type-trait.
Definition Fwd.hpp:91
typename signature_return_type< Signature >::type signature_return_type_t
Convenience alias, exposing the type member alias of the actual type-trait.
Definition Fwd.hpp:171
typename info_for_signature< Signature >::type info_for_signature_t
Definition Call.hpp:69
Definition BoostTest.hpp:20
ValueCategory
Definition Fwd.hpp:30
Constness
Definition Fwd.hpp:23