6#ifndef MIMICPP_MOCK_HPP
7#define MIMICPP_MOCK_HPP
16namespace mimicpp::detail
19 class BasicMockFrontend
22 using ExpectationCollectionT = ExpectationCollection<Return(Params...)>;
25 explicit BasicMockFrontend(
26 std::shared_ptr<ExpectationCollectionT> collection
28 : m_Expectations{std::move(collection)}
33 constexpr Return handle_call(
34 std::tuple<std::reference_wrapper<std::remove_reference_t<Params>>...> params,
35 const std::source_location& from
38 using CallInfoT = call::Info<Return, Params...>;
40 return m_Expectations->handle_call(
42 .args = std::move(params),
43 .fromCategory = category,
44 .fromConstness = constness,
45 .fromSourceLocation = from
49 template <
typename... Args>
50 requires (... && requirement_for<Args, Params>)
52 constexpr auto make_expectation_builder(Args&&... args)
const
54 return detail::make_expectation_builder(
56 std::forward<Args>(args)...)
57 && expectation_policies::Category<category>{}
58 && expectation_policies::Constness<constness>{};
62 std::shared_ptr<ExpectationCollectionT> m_Expectations;
65 template <
typename Signature>
68 template <
typename Return,
typename... Params>
69 class MockFrontend<Return(Params...)>
70 :
protected BasicMockFrontend<
76 using SuperT = BasicMockFrontend<
83 using SignatureT = Return(Params...);
85 constexpr Return operator ()(Params... params,
const std::source_location& from = std::source_location::current())
87 return SuperT::handle_call(
88 std::tuple{std::ref(params)...},
92 template <
typename... Args>
93 requires (... && requirement_for<Args, Params>)
95 constexpr auto expect_call(Args&&... args)
97 return SuperT::make_expectation_builder(
98 std::forward<Args>(args)...);
102 using SuperT::SuperT;
105 template <
typename Return,
typename... Params>
106 class MockFrontend<Return(Params...) const>
107 :
protected BasicMockFrontend<
113 using SuperT = BasicMockFrontend<
120 using SignatureT = Return(Params...)
const;
122 constexpr Return operator ()(Params... params,
const std::source_location& from = std::source_location::current())
const
124 return SuperT::handle_call(
125 std::tuple{std::ref(params)...},
129 template <
typename... Args>
130 requires (... && requirement_for<Args, Params>)
132 constexpr auto expect_call(Args&&... args)
const
134 return SuperT::make_expectation_builder(
135 std::forward<Args>(args)...);
139 using SuperT::SuperT;
142 template <
typename Return,
typename... Params>
143 class MockFrontend<Return(Params...) &>
144 :
protected BasicMockFrontend<
150 using SuperT = BasicMockFrontend<
157 using SignatureT = Return(Params...) &;
159 constexpr Return operator ()(Params... params,
const std::source_location& from = std::source_location::current()) &
161 return SuperT::handle_call(
162 std::tuple{std::ref(params)...},
166 template <
typename... Args>
167 requires (... && requirement_for<Args, Params>)
169 constexpr auto expect_call(Args&&... args) &
171 return SuperT::make_expectation_builder(
172 std::forward<Args>(args)...);
176 using SuperT::SuperT;
179 template <
typename Return,
typename... Params>
180 class MockFrontend<Return(Params...) const &>
181 :
protected BasicMockFrontend<
187 using SuperT = BasicMockFrontend<
194 using SignatureT = Return(Params...) const &;
196 constexpr Return operator ()(Params... params, const std::source_location& from = std::source_location::current()) const &
198 return SuperT::handle_call(
199 std::tuple{std::ref(params)...},
203 template <
typename... Args>
204 requires (... && requirement_for<Args, Params>)
206 constexpr auto expect_call(Args&&... args)
const &
208 return SuperT::make_expectation_builder(
209 std::forward<Args>(args)...);
213 using SuperT::SuperT;
216 template <
typename Return,
typename... Params>
217 class MockFrontend<Return(Params...) &&>
218 :
protected BasicMockFrontend<
224 using SuperT = BasicMockFrontend<
231 using SignatureT = Return(Params...) &&;
233 constexpr Return operator ()(Params... params,
const std::source_location& from = std::source_location::current()) &&
235 return SuperT::handle_call(
236 std::tuple{std::ref(params)...},
240 template <
typename... Args>
241 requires (... && requirement_for<Args, Params>)
243 constexpr auto expect_call(Args&&... args) &&
245 return SuperT::make_expectation_builder(
246 std::forward<Args>(args)...);
250 using SuperT::SuperT;
253 template <
typename Return,
typename... Params>
254 class MockFrontend<Return(Params...) const &&>
255 :
protected BasicMockFrontend<
261 using SuperT = BasicMockFrontend<
268 using SignatureT = Return(Params...) const &&;
270 constexpr Return operator ()(Params... params, const std::source_location& from = std::source_location::current()) const &&
272 return SuperT::handle_call(
273 std::tuple{std::ref(params)...},
277 template <
typename... Args>
278 requires (... && requirement_for<Args, Params>)
280 constexpr auto expect_call(Args&&... args)
const &&
282 return SuperT::make_expectation_builder(
283 std::forward<Args>(args)...);
287 using SuperT::SuperT;
290 template <
typename Return,
typename... Params>
291 class MockFrontend<Return(Params...) noexcept>
292 :
protected BasicMockFrontend<
294 Constness::non_const,
298 using SuperT = BasicMockFrontend<
305 using SignatureT = Return(Params...) noexcept;
307 constexpr Return operator ()(Params... params, const std::source_location& from = std::source_location::current()) noexcept
309 return SuperT::handle_call(
310 std::tuple{std::ref(params)...},
314 template <
typename... Args>
315 requires (... && requirement_for<Args, Params>)
317 constexpr auto expect_call(Args&&... args)
319 return SuperT::make_expectation_builder(
320 std::forward<Args>(args)...);
324 using SuperT::SuperT;
327 template <
typename Return,
typename... Params>
328 class MockFrontend<Return(Params...) const noexcept>
329 :
protected BasicMockFrontend<
335 using SuperT = BasicMockFrontend<
342 using SignatureT = Return(Params...) const noexcept;
344 constexpr Return operator ()(
346 const std::source_location& from = std::source_location::current()
349 return SuperT::handle_call(
350 std::tuple{std::ref(params)...},
354 template <
typename... Args>
355 requires (... && requirement_for<Args, Params>)
357 constexpr auto expect_call(Args&&... args)
const
359 return SuperT::make_expectation_builder(
360 std::forward<Args>(args)...);
364 using SuperT::SuperT;
367 template <
typename Return,
typename... Params>
368 class MockFrontend<Return(Params...) &
noexcept>
369 :
protected BasicMockFrontend<
375 using SuperT = BasicMockFrontend<
382 using SignatureT = Return(Params...) &
noexcept;
384 constexpr Return operator ()(Params... params,
const std::source_location& from = std::source_location::current()) &
noexcept
386 return SuperT::handle_call(
387 std::tuple{std::ref(params)...},
391 template <
typename... Args>
392 requires (... && requirement_for<Args, Params>)
394 constexpr auto expect_call(Args&&... args) &
396 return SuperT::make_expectation_builder(
397 std::forward<Args>(args)...);
401 using SuperT::SuperT;
404 template <
typename Return,
typename... Params>
405 class MockFrontend<Return(Params...) const &
noexcept>
406 :
protected BasicMockFrontend<
412 using SuperT = BasicMockFrontend<
419 using SignatureT = Return(Params...) const & noexcept;
421 constexpr Return operator ()(
423 const std::source_location& from = std::source_location::current()
426 return SuperT::handle_call(
427 std::tuple{std::ref(params)...},
431 template <
typename... Args>
432 requires (... && requirement_for<Args, Params>)
434 constexpr auto expect_call(Args&&... args)
const &
436 return SuperT::make_expectation_builder(
437 std::forward<Args>(args)...);
441 using SuperT::SuperT;
444 template <
typename Return,
typename... Params>
445 class MockFrontend<Return(Params...) &&
noexcept>
446 :
protected BasicMockFrontend<
452 using SuperT = BasicMockFrontend<
459 using SignatureT = Return(Params...) &&
noexcept;
461 constexpr Return operator ()(Params... params,
const std::source_location& from = std::source_location::current()) &&
noexcept
463 return SuperT::handle_call(
464 std::tuple{std::ref(params)...},
468 template <
typename... Args>
469 requires (... && requirement_for<Args, Params>)
471 constexpr auto expect_call(Args&&... args) &&
473 return SuperT::make_expectation_builder(
474 std::forward<Args>(args)...);
478 using SuperT::SuperT;
481 template <
typename Return,
typename... Params>
482 class MockFrontend<Return(Params...) const &&
noexcept>
483 :
protected BasicMockFrontend<
489 using SuperT = BasicMockFrontend<
496 using SignatureT = Return(Params...) const && noexcept;
498 constexpr Return operator ()(
500 const std::source_location& from = std::source_location::current()
503 return SuperT::handle_call(
504 std::tuple{std::ref(params)...},
508 template <
typename... Args>
509 requires (... && requirement_for<Args, Params>)
511 constexpr auto expect_call(Args&&... args)
const &&
513 return SuperT::make_expectation_builder(
514 std::forward<Args>(args)...);
518 using SuperT::SuperT;
521 template <
typename List>
522 struct expectation_collection_factory;
524 template <
typename... UniqueSignatures>
525 struct expectation_collection_factory<std::tuple<UniqueSignatures...>>
531 std::make_shared<ExpectationCollection<UniqueSignatures>>()...
595 template <
typename FirstSignature,
typename... OtherSignatures>
598 :
public detail::MockFrontend<FirstSignature>,
599 public detail::MockFrontend<OtherSignatures>...
602 using detail::MockFrontend<FirstSignature>::operator();
603 using detail::MockFrontend<FirstSignature>::expect_call;
604 using detail::MockFrontend<OtherSignatures>::operator()...;
605 using detail::MockFrontend<OtherSignatures>::expect_call...;
618 detail::expectation_collection_factory<
619 detail::unique_list_t<
648 template <
typename... Collections>
649 explicit Mock(std::tuple<Collections...> collections)
650 : detail::MockFrontend<FirstSignature>{
651 std::get<std::shared_ptr<ExpectationCollection<signature_decay_t<FirstSignature>>>>(collections)
653 detail::MockFrontend<OtherSignatures>{
654 std::get<std::shared_ptr<ExpectationCollection<signature_decay_t<OtherSignatures>>>>(collections)
A Mock type, which fully supports overload sets.
Definition Mock.hpp:600
~Mock()=default
Defaulted destructor.
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:616
constexpr bool is_overload_set_v
Convenience constant, exposing the value member of the actual type-trait.
Definition Fwd.hpp:146
typename signature_decay< Signature >::type signature_decay_t
Convenience alias, exposing the type member alias of the actual type-trait.
Definition Fwd.hpp:68
Definition BoostTest.hpp:20
ValueCategory
Definition Fwd.hpp:195
Constness
Definition Fwd.hpp:188