OTest2
A C++ testing framework
include
otest2
assertions.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2019 Ondrej Starek
3
*
4
* This file is part of OTest2.
5
*
6
* OTest2 is free software: you can redistribute it and/or modify it under
7
* the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License,
9
* or (at your option) any later version.
10
*
11
* OTest2 is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14
* License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
21
#ifndef OTest2__INCLUDE_OTEST2_ASSERTIONS_H_
22
#define OTest2__INCLUDE_OTEST2_ASSERTIONS_H_
23
24
#include <functional>
25
26
#include <
otest2/assertbean.h
>
27
#include <
otest2/assertcontext.h
>
28
#include <
otest2/assertionannotation.h
>
29
#include <
otest2/comparisons.h
>
30
#include <
otest2/const.h
>
31
32
namespace
OTest2
{
33
56
class
GenericAssertion
:
public
AssertContext
{
57
public
:
58
/* -- avoid copying */
59
GenericAssertion
(
60
const
GenericAssertion
&) =
delete
;
61
GenericAssertion
&
operator =
(
62
const
GenericAssertion
&) =
delete
;
63
64
/* -- inherit the constructor - the parent constructor is invoked
65
* from the test suite generated code. */
66
using
AssertContext::AssertContext
;
67
68
/* -- the assertion implementation */
69
bool
testAssert
(
70
bool
condition_);
71
bool
testAssert
(
72
const
AssertBean
& bean_);
73
74
template
<
typename
Compare_,
typename
A_,
typename
B_>
75
bool
reportAssertion
(
76
Compare_&& cmp_,
77
A_&& a_,
78
B_&& b_,
79
bool
condition_);
80
template
<
template
<
typename
,
typename
>
class
Compare_,
typename
A_,
typename
B_>
81
bool
testAssertCompare
(
82
A_&& a_,
83
B_&& b_);
84
template
<
template
<
typename
,
typename
,
typename
>
class
Compare_,
typename
A_,
typename
B_,
typename
Precision_ =
long
double
>
85
bool
testAssertCompareFP
(
86
A_ a_,
87
B_ b_,
88
Precision_ precision_ =
DEFAULT_FLOAT_PRECISION
);
89
90
/* -- exception assertion - it's never used as an assertion as
91
* it's always generated. */
92
bool
testException
(
93
std::function<
bool
()> ftor_);
94
};
95
96
namespace
Assertions {
97
103
bool
testAssert(
104
bool
condition_)
TEST_ASSERTION_MARK
(::
OTest2::GenericAssertion
, testAssert);
105
112
bool
testAssert(
113
const
AssertBean
& bean_)
TEST_ASSERTION_MARK
(::
OTest2::GenericAssertion
, testAssert);
114
129
bool
testAssertExpr(
130
bool
expression_)
TEST_ASSERTION_EXPR_MARK
(
"::OTest2::GenericAssertion"
,
"testAssert"
,
"testAssertCompare< ::$1 >"
);
131
140
template
<
template
<
typename
,
typename
>
class
Compare_,
typename
A_,
typename
B_>
141
bool
testAssertCmp(
142
A_ a_,
143
B_ b_)
144
TEST_ASSERTION_MARK_TMPL
(
"::OTest2::GenericAssertion"
,
"testAssertCompare< ::$1 >"
);
145
155
template
<
template
<
typename
,
typename
,
typename
>
class
Compare_,
typename
A_,
typename
B_,
typename
P_ =
long
double
>
156
bool
testAssertCmpFP(
157
A_ a_,
158
B_ b_,
159
P_ precision_ =
DEFAULT_FLOAT_PRECISION
)
160
TEST_ASSERTION_MARK_TMPL
(
"::OTest2::GenericAssertion"
,
"testAssertCompareFP< ::$1 >"
);
161
169
template
<
typename
A_,
typename
B_>
170
bool
testAssertEqual(
171
A_ a_,
172
B_ b_)
TEST_ASSERTION_MARK_TMPL
(
"::OTest2::GenericAssertion"
,
"testAssertCompare< ::OTest2::Equal >"
);
173
182
template
<
typename
A_,
typename
B_,
typename
P_ =
long
double
>
183
bool
testAssertEqualFP(
184
A_ a_,
185
B_ b_,
186
P_ precision_ =
DEFAULT_FLOAT_PRECISION
)
187
TEST_ASSERTION_MARK_TMPL
(
"::OTest2::GenericAssertion"
,
"testAssertCompareFP< ::OTest2::EqualFP >"
);
188
196
template
<
typename
A_,
typename
B_>
197
bool
testAssertNotEqual(
198
A_ a_,
199
B_ b_)
TEST_ASSERTION_MARK_TMPL
(
"::OTest2::GenericAssertion"
,
"testAssertCompare< ::OTest2::NotEqual >"
);
200
209
template
<
typename
A_,
typename
B_,
typename
P_ =
long
double
>
210
bool
testAssertNotEqualFP(
211
A_ a_,
212
B_ b_,
213
P_ precision_ =
DEFAULT_FLOAT_PRECISION
)
214
TEST_ASSERTION_MARK_TMPL
(
"::OTest2::GenericAssertion"
,
"testAssertCompareFP< ::OTest2::NotEqualFP >"
);
215
223
template
<
typename
A_,
typename
B_>
224
bool
testAssertLess(
225
A_ a_,
226
B_ b_)
TEST_ASSERTION_MARK_TMPL
(
"::OTest2::GenericAssertion"
,
"testAssertCompare< ::OTest2::Less >"
);
227
235
template
<
typename
A_,
typename
B_>
236
bool
testAssertLessOrEqual(
237
A_ a_,
238
B_ b_)
TEST_ASSERTION_MARK_TMPL
(
"::OTest2::GenericAssertion"
,
"testAssertCompare< ::OTest2::LessOrEqual >"
);
239
247
template
<
typename
A_,
typename
B_>
248
bool
testAssertGreater(
249
A_ a_,
250
B_ b_)
TEST_ASSERTION_MARK_TMPL
(
"::OTest2::GenericAssertion"
,
"testAssertCompare< ::OTest2::Greater >"
);
251
259
template
<
typename
A_,
typename
B_>
260
bool
testAssertGreaterOrEqual(
261
A_ a_,
262
B_ b_)
TEST_ASSERTION_MARK_TMPL
(
"::OTest2::GenericAssertion"
,
"testAssertCompare< ::OTest2::GreaterOrEqual >"
);
263
264
}
/* -- namespace Assertions */
265
266
}
/* -- namespace OTest2 */
267
268
#endif
/* OTest2__INCLUDE_OTEST2_ASSERTIONS_H_ */
OTest2::AssertContext::AssertContext
AssertContext(const AssertContext &)=delete
OTest2::GenericAssertion::reportAssertion
bool reportAssertion(Compare_ &&cmp_, A_ &&a_, B_ &&b_, bool condition_)
Definition:
assertionsimpl.h:35
TEST_ASSERTION_EXPR_MARK
#define TEST_ASSERTION_EXPR_MARK(class_, generic_method_, comparison_method_)
Definition:
assertionannotation.h:27
assertcontext.h
TEST_ASSERTION_MARK
#define TEST_ASSERTION_MARK(class_, method_)
Definition:
assertionannotation.h:25
OTest2::AssertBean
A helper class packing assertion condition and an assertion message together.
Definition:
assertbean.h:31
OTest2::AssertContext
Assertion context.
Definition:
assertcontext.h:37
TEST_ASSERTION_MARK_TMPL
#define TEST_ASSERTION_MARK_TMPL(class_, method_)
Definition:
assertionannotation.h:26
OTest2::GenericAssertion::testException
bool testException(std::function< bool()> ftor_)
Definition:
assertions.cpp:46
const.h
OTest2
Definition:
assertbean.h:25
comparisons.h
OTest2::DEFAULT_FLOAT_PRECISION
constexpr long double DEFAULT_FLOAT_PRECISION(1.0e-12)
Default precision for floating point comparisons.
OTest2::GenericAssertion::testAssert
bool testAssert(bool condition_)
Definition:
assertions.cpp:30
OTest2::GenericAssertion::operator=
GenericAssertion & operator=(const GenericAssertion &)=delete
OTest2::GenericAssertion
Implementation class of the generic assertions.
Definition:
assertions.h:56
assertionannotation.h
OTest2::GenericAssertion::GenericAssertion
GenericAssertion(const GenericAssertion &)=delete
assertbean.h
OTest2::GenericAssertion::testAssertCompareFP
bool testAssertCompareFP(A_ a_, B_ b_, Precision_ precision_=DEFAULT_FLOAT_PRECISION)
Definition:
assertionsimpl.h:88
OTest2::GenericAssertion::testAssertCompare
bool testAssertCompare(A_ &&a_, B_ &&b_)
Definition:
assertionsimpl.h:74
Generated by
1.8.17