mimic++ v5
Loading...
Searching...
No Matches
mimicpp::RelocationWatcher Class Reference

A watcher type, which reports it's move-constructor and -assignment calls. More...

#include <ObjectWatcher.hpp>

Public Member Functions

 ~RelocationWatcher ()=default
 Defaulted destructor.
 
 RelocationWatcher ()=default
 Defaulted default constructor.
 
 RelocationWatcher (const RelocationWatcher &other)
 Copy-constructor.
 
RelocationWatcheroperator= (const RelocationWatcher &other)
 Copy-assignment-operator.
 
 RelocationWatcher (RelocationWatcher &&other) noexcept(false)
 Move-constructor, which reports a relocation.
 
RelocationWatcheroperator= (RelocationWatcher &&other) noexcept(false)
 Move-assignment-operator, which reports a relocation.
 
auto expect_relocate ()
 Begins a relocation-expectation construction.
 

Detailed Description

A watcher type, which reports it's move-constructor and -assignment calls.

This watcher is designed to track, whether a move has been performed. During a move, it reports the relocation to the framework, which can be tracked by a previously created relocation-expectation.

namespace expect = mimicpp::expect;
namespace then = mimicpp::then;
mimicpp::Mock<void()>,
watched{};
SCOPED_EXP watched.expect_destruct();
int relocationCounter{};
and then::invoke([&] { ++relocationCounter; })
and expect::at_least(1);
std::optional wrapped{std::move(watched)}; // satisfies one relocate-expectation
std::optional other{std::move(wrapped)}; // satisfies a second relocate-expectation
wrapped.reset(); // won't require a destruct-expectation, as moved-from objects are considered dead
other.reset(); // fulfills the destruct-expectation
REQUIRE(2 == relocationCounter); // let's see, how often the instance has been relocated

Moving

This watcher can be freely moved around, but any relocation events must match with a previously created relocation-expectation.

Copying

This watcher is copyable, but with very special behaviour.

As this watcher is generally designed to be part of a bigger object, it would be very limiting not supporting copy-operations at all. The question is, how should a copy look like?

In general a copy should be a logical duplicate of its source and the general expectation is: if B is a copy of A, then A == B should yield true.

Note
This doesn't say, that if B is not a copy of A, then A == B has to yield false!

This won't be the case for RelocationWatchers, as active relocation-expectations won't be copied over to the target. In general, if a RelocationWatcher is used, we want to be very precise with our move, thus an implicit expectation copy would be against the purpose of this helper. Due to this, each RelocationWatcher will be created as a fresh instance, when copy-construction is used. The same logic also applies to copy-assignment.

Constructor & Destructor Documentation

◆ ~RelocationWatcher()

mimicpp::RelocationWatcher::~RelocationWatcher ( )
default

Defaulted destructor.

◆ RelocationWatcher() [1/3]

mimicpp::RelocationWatcher::RelocationWatcher ( )
nodiscarddefault

Defaulted default constructor.

◆ RelocationWatcher() [2/3]

mimicpp::RelocationWatcher::RelocationWatcher ( const RelocationWatcher & other)
inlinenodiscard

Copy-constructor.

Parameters
otherThe other object.

This copy-constructor's purpose is to provide syntactically correct copy operations, but semantically this does not copy anything. In fact, it simply default-constructs the new instance, without even touching the other.

◆ RelocationWatcher() [3/3]

mimicpp::RelocationWatcher::RelocationWatcher ( RelocationWatcher && other)
inlinenodiscard

Move-constructor, which reports a relocation.

Note
A no-match error may occur, if no relocation-expectation has been defined.
Parameters
otherThe other object.

Member Function Documentation

◆ expect_relocate()

auto mimicpp::RelocationWatcher::expect_relocate ( )
inlinenodiscard

Begins a relocation-expectation construction.

Returns
A newly created expectation-builder-instance.
Note
This function creates a new expectation-builder-instance, which isn't an expectation yet. User must convert this to an actual expectation, by handing it over to a new ScopedExpectation instance. This can either be done manually or via MIMICPP_SCOPED_EXPECTATION (or the shorthand version SCOPED_EXP).

◆ operator=() [1/2]

RelocationWatcher & mimicpp::RelocationWatcher::operator= ( const RelocationWatcher & other)
inline

Copy-assignment-operator.

Parameters
otherThe other object.

This copy-assignment-operator's purpose is to provide syntactically correct copy operations, but semantically this does not copy anything. In fact, it simply overrides its internals with a fresh instance, without even touching the other.

◆ operator=() [2/2]

RelocationWatcher & mimicpp::RelocationWatcher::operator= ( RelocationWatcher && other)
inline

Move-assignment-operator, which reports a relocation.

Note
A no-match error may occur, if no relocation-expectation has been defined.
Parameters
otherThe other object.

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