mimic++ v10.0.1
Loading...
Searching...
No Matches
mimicpp::expectation::Collector Class Reference

Collects scoped expectations and verifies them during destruction. More...

#include <Collector.hpp>

Public Member Functions

 Collector (Collector const &)=delete
 Deleted copy-constructor.
Collector & operator= (Collector const &)=delete
 Deleted copy-assignment operator.
 ~Collector () noexcept(false)
 Possibly throwing destructor, checking the owned expectations in order of construction.
 Collector ()=default
 Defaulted default-constructor.
 Collector (Collector &&)=default
 Defaulted move-constructor.
Collector & operator= (Collector &&)=default
 Defaulted move-assignment operator.
Collector & attach (ScopedExpectation &&builder) &
 Attaches a newly constructed expectation.
Collector & operator+= (ScopedExpectation &&builder) &
 Attaches a newly constructed expectation.
constexpr std::deque< ScopedExpectation > const & expectations () const noexcept
 Retrieves the collection of explicitly owned expectations.

Detailed Description

Collects scoped expectations and verifies them during destruction.

A Collector owns the attached expectations and keeps them alive until it is destroyed. When destruction happens, all owned expectations are checked in order of construction.

{
mimicpp::Mock<void()> outer{};
collector += outer.expect_call();
{
mimicpp::Mock<void()> inner{};
collector += inner.expect_call();
inner();
}
outer();
} // All expectations are checked here.

Constructor & Destructor Documentation

◆ Collector() [1/3]

mimicpp::expectation::Collector::Collector ( Collector const & )
delete

Deleted copy-constructor.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~Collector()

mimicpp::expectation::Collector::~Collector ( )
inline

Possibly throwing destructor, checking the owned expectations in order of construction.

Here is the call graph for this function:

◆ Collector() [2/3]

mimicpp::expectation::Collector::Collector ( )
nodiscarddefault

Defaulted default-constructor.

◆ Collector() [3/3]

mimicpp::expectation::Collector::Collector ( Collector && )
nodiscarddefault

Defaulted move-constructor.

Here is the call graph for this function:

Member Function Documentation

◆ attach()

Collector & mimicpp::expectation::Collector::attach ( ScopedExpectation && builder) &
inline

Attaches a newly constructed expectation.

Parameters
builderThe expectation-builder that will be finalized.
Returns
A mutable reference to the current instance.

This collector becomes the owner of the created expectation and attaches it to the internal expectation-collection. Even though this function formally requires a ScopedExpectation as an argument, it's expected that users pass an expectation-builder. Doing so will then correctly deduce the source-location.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expectations()

std::deque< ScopedExpectation > const & mimicpp::expectation::Collector::expectations ( ) const
inlinenodiscardconstexprnoexcept

Retrieves the collection of explicitly owned expectations.

Returns
A constant reference to the collection of attached expectations.
Here is the caller graph for this function:

◆ operator+=()

Collector & mimicpp::expectation::Collector::operator+= ( ScopedExpectation && builder) &
inline

Attaches a newly constructed expectation.

Parameters
builderThe expectation-builder that will be finalized.
Returns
A mutable reference to the current instance.

This collector becomes the owner of the created expectation and attaches it to the internal expectation-collection. Even though this function formally requires a ScopedExpectation as an argument, it's expected that users pass an expectation-builder. Doing so will then correctly deduce the source-location.

Note
In CLion, expressions with this operator may incorrectly report that the variable is never used after being assigned. This is a known bug that unfortunately cannot be worked around on the framework level. If you find yourself stuck to the Resharper DFA, you can use Collector::attach instead.
See also
https://youtrack.jetbrains.com/issue/CPP-49527/
https://youtrack.jetbrains.com/issue/CPP-38216
Here is the call graph for this function:

◆ operator=() [1/2]

Collector & mimicpp::expectation::Collector::operator= ( Collector && )
default

Defaulted move-assignment operator.

Returns
A mutable reference to the current instance.
Here is the call graph for this function:

◆ operator=() [2/2]

Collector & mimicpp::expectation::Collector::operator= ( Collector const & )
delete

Deleted copy-assignment operator.

Here is the call graph for this function:

The documentation for this class was generated from the following file: