mimic++
v10.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
Owner.hpp
Go to the documentation of this file.
1
// Copyright Dominic (DNKpp) Koepke 2024-2026.
2
// Distributed under the Boost Software License, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at
4
// https://www.boost.org/LICENSE_1_0.txt)
5
6
#ifndef MIMICPP_EXPECTATION_OWNER_HPP
7
#define MIMICPP_EXPECTATION_OWNER_HPP
8
9
#pragma once
10
11
#include "
mimic++/Fwd.hpp
"
12
#include "
mimic++/config/Config.hpp
"
13
#include "
mimic++/expectation/Expectation.hpp
"
14
#include "
mimic++/expectation/Registry.hpp
"
15
16
#ifndef MIMICPP_DETAIL_IS_MODULE
17
#include <concepts>
18
#include <utility>
19
#endif
20
21
MIMICPP_DETAIL_MODULE_EXPORT
namespace
mimicpp::expectation
22
{
23
namespace
detail
24
{
25
template
<
typename
T>
26
concept
finalizable =
requires
(util::SourceLocation loc) {
27
{ std::declval<T&&>().finalize(loc) } -> std::convertible_to<Owner>;
28
};
29
}
30
41
class
Owner
42
{
43
public
:
47
Owner
(
Owner
const
&) =
delete
;
48
52
Owner
&
operator=
(
Owner
const
&) =
delete
;
53
58
~Owner
() noexcept(false)
59
{
60
if
(m_Registry)
61
{
62
m_Registry->remove(m_Expectation);
63
}
64
}
65
71
[[nodiscard]]
72
explicit
Owner
(
Registry::Ptr
registry,
Expectation
expectation
)
73
: m_Registry{std::move(registry)},
74
m_Expectation{std::move(
expectation
)}
75
{
76
}
77
84
template
<detail::finalizable T>
85
[[nodiscard]]
86
explicit
(
false
)
constexpr
Owner
(T&&
object
,
util::SourceLocation
loc
= {})
87
:
Owner
{std::forward<T>(object).finalize(std::move(
loc
))}
88
{
89
}
90
94
[[nodiscard]]
95
Owner
(
Owner
&&) =
default
;
96
100
Owner
&
operator=
(
Owner
&&) =
default
;
101
106
[[nodiscard]]
107
bool
is_satisfied
()
const
108
{
109
return
m_Expectation.is_satisfied();
110
}
111
116
[[nodiscard]]
117
bool
is_applicable
()
const
118
{
119
return
m_Expectation.is_applicable();
120
}
121
126
[[nodiscard]]
127
util::SourceLocation
const
&
from
() const noexcept
128
{
129
return
m_Expectation.from();
130
}
131
136
[[nodiscard]]
137
StringT
const
&
mock_name
() const noexcept
138
{
139
return
m_Expectation.mock_name();
140
}
141
142
private
:
143
Registry::Ptr
m_Registry;
144
Expectation
m_Expectation;
145
};
146
}
147
148
#endif
Config.hpp
MIMICPP_DETAIL_MODULE_EXPORT
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition
Config.hpp:19
Expectation.hpp
Fwd.hpp
Registry.hpp
mimicpp::expectation::Expectation
The type-erased expectation type with shared ownership.
Definition
Expectation.hpp:70
mimicpp::expectation::Owner
Takes the ownership of an expectation and checks whether it's satisfied during destruction.
Definition
Owner.hpp:42
mimicpp::expectation::Owner::mock_name
StringT const & mock_name() const noexcept
Queries the stored expectation for the name of the related mock.
Definition
Owner.hpp:137
mimicpp::expectation::Owner::operator=
Owner & operator=(Owner &&)=default
Defaulted move-assignment-operator.
mimicpp::expectation::Owner::from
util::SourceLocation const & from() const noexcept
Queries the stored expectation for it's stored source-location.
Definition
Owner.hpp:127
mimicpp::expectation::Owner::~Owner
~Owner() noexcept(false)
Removes the owned expectation from the Registry and checks whether it's satisfied.
Definition
Owner.hpp:58
mimicpp::expectation::Owner::operator=
Owner & operator=(Owner const &)=delete
Deleted copy-assignment-operator.
mimicpp::expectation::Owner::is_applicable
bool is_applicable() const
Queries the stored expectation, whether it's applicable.
Definition
Owner.hpp:117
mimicpp::expectation::Owner::is_satisfied
bool is_satisfied() const
Queries the stored expectation, whether it's satisfied.
Definition
Owner.hpp:107
mimicpp::expectation::Owner::Owner
Owner(Registry::Ptr registry, Expectation expectation)
Constructor, which generates the type-erase storage.
Definition
Owner.hpp:72
mimicpp::expectation::Owner::Owner
Owner(Owner const &)=delete
Deleted copy-constructor.
mimicpp::expectation::Owner::loc
util::SourceLocation loc
Definition
Owner.hpp:86
mimicpp::expectation::Registry::Ptr
std::shared_ptr< Registry > Ptr
Definition
Registry.hpp:38
mimicpp::util::SourceLocation
A thin wrapper around general source-location info.
Definition
SourceLocation.hpp:33
mimicpp::expectation
Definition
Builder.hpp:33
mimicpp::StringT
std::basic_string< CharT, CharTraitsT > StringT
Definition
Fwd.hpp:397
mimic++
expectation
Owner.hpp
Generated on
for mimic++ by
1.18.0