Thyra
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
src
support
operator_vector
client_support
Thyra_TestingTools.cpp
1
// @HEADER
2
// *****************************************************************************
3
// Thyra: Interfaces and Support for Abstract Numerical Algorithms
4
//
5
// Copyright 2004 NTESS and the Thyra contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#include "Thyra_TestingTools.hpp"
11
12
13
bool
Thyra::testBoolExpr
(
14
const
std::string &boolExprName,
15
const
bool
&boolExpr,
16
const
bool
&boolExpected,
17
const
Ptr<std::ostream>
&out,
18
const
std::string &li
19
)
20
{
21
const
bool
success = ( boolExpr == boolExpected );
22
if
(nonnull(out)) {
23
*out
24
<< std::endl
25
<< li <<
"Check: "
<< boolExprName <<
" = "
<< boolExpr <<
" == "
<< boolExpected
26
<<
" : "
<<
passfail
(success) << std::endl;
27
}
28
return
success;
29
}
30
31
32
void
Thyra::printTestResults(
33
const
bool
result,
34
const
std::string &test_summary,
35
const
bool
show_all_tests,
36
const
Ptr<bool> &success,
37
const
Ptr<std::ostream> &out
38
)
39
{
40
if
(!result) *success =
false
;
41
if
(nonnull(out)) {
42
if
(!result || show_all_tests) {
43
*out << std::endl << test_summary;
44
}
45
else
{
46
*out <<
"passed!\n"
;
47
}
48
}
49
}
50
51
52
// TestResultsPrinter
53
54
55
namespace
Thyra {
56
57
58
TestResultsPrinter::TestResultsPrinter
(
59
const
RCP<FancyOStream>
&out,
const
bool
show_all_tests)
60
: out_(out.assert_not_null()), show_all_tests_(show_all_tests),
61
printedTestResults_(false)
62
{
63
if
(show_all_tests_) {
64
oss_ = out_;
65
}
66
else
{
67
oss_ = Teuchos::fancyOStream(Teuchos::rcpFromRef(ossStore_));
68
ossStore_.copyfmt(*out_);
69
}
70
}
71
72
73
TestResultsPrinter::~TestResultsPrinter
()
74
{
75
using
Teuchos::inoutArg;
76
if
(!printedTestResults_) {
77
// If we get here, either someone made a mistake in not calling
78
// printTestResults() or an exception was thrown. Either way, we are
79
// going to assume failure and dump everything.
80
try
{
81
bool
dummy_success =
true
;
82
this->
printTestResults
(
false
, inoutArg(dummy_success));
83
}
84
catch
(...) {
85
// Need to eat any exceptions in case an exception is already active
86
// which is calling this destructor.
87
}
88
}
89
printedTestResults_ =
true
;
90
}
91
92
93
RCP<FancyOStream>
94
TestResultsPrinter::replaceOStream
(
const
RCP<FancyOStream>
&out)
95
{
96
const
RCP<FancyOStream>
oldOut = out_;
97
out_ = out;
98
return
oldOut;
99
}
100
101
102
RCP<FancyOStream>
TestResultsPrinter::getTestOStream
()
103
{
104
return
oss_;
105
}
106
107
108
void
TestResultsPrinter::printTestResults
(
const
bool
this_result,
109
const
Ptr<bool>
&success)
110
{
111
if
(!show_all_tests_) {
112
Thyra::printTestResults(this_result, ossStore_.str(),
false
,
113
success, out_.
ptr
());
114
}
115
else
{
116
if
(!this_result) {
117
*success =
false
;
118
}
119
}
120
printedTestResults_ =
true
;
121
}
122
123
124
}
// namespace Thyra
Teuchos::Ptr
Teuchos::Ptr::ptr
const Ptr< T > ptr() const
Teuchos::RCP
Thyra::TestResultsPrinter::getTestOStream
RCP< FancyOStream > getTestOStream()
Return the stream used for testing.
Definition
Thyra_TestingTools.cpp:102
Thyra::TestResultsPrinter::~TestResultsPrinter
~TestResultsPrinter()
Print the test results on destruction if not already printed.
Definition
Thyra_TestingTools.cpp:73
Thyra::TestResultsPrinter::replaceOStream
RCP< FancyOStream > replaceOStream(const RCP< FancyOStream > &out)
Replace the underlying output stream (used for unit testing this class).
Definition
Thyra_TestingTools.cpp:94
Thyra::TestResultsPrinter::TestResultsPrinter
TestResultsPrinter(const RCP< FancyOStream > &out, const bool show_all_tests)
Definition
Thyra_TestingTools.cpp:58
Thyra::TestResultsPrinter::printTestResults
void printTestResults(const bool this_result, const Ptr< bool > &success)
Print the test result.
Definition
Thyra_TestingTools.cpp:108
Thyra::passfail
const std::string passfail(const bool result)
Definition
Thyra_TestingToolsDecl.hpp:24
Thyra::testBoolExpr
bool testBoolExpr(const std::string &boolExprName, const bool &boolExpr, const bool &boolExpected, const Ptr< std::ostream > &out, const std::string &leadingIndent=std::string(""))
Check a boolean result against expected result.
Definition
Thyra_TestingTools.cpp:13
Generated by
1.17.0