Advanced Multi-Physics (AMP)
On-Line Documentation
UnitTest.h
Go to the documentation of this file.
1#ifndef included_AMP_AMPUnitTest
2#define included_AMP_AMPUnitTest
3
4#include "AMP/utils/UtilityMacros.h"
5
6#include <stdarg.h>
7#include <string>
8#include <vector>
9
10
11namespace AMP {
12
13
48class UnitTest final
49{
50public:
52 UnitTest() = default;
53
56
57 // Copy constructor
58 UnitTest( const UnitTest & ) = delete;
59
60 // Assignment operator
61 UnitTest &operator=( const UnitTest & ) = delete;
62
64 void passes( std::string in );
65
67 void failure( std::string in );
68
70 void expected_failure( std::string in );
71
73 void pass_fail( bool pass, std::string in );
74
76 inline size_t NumPassLocal() const { return d_pass.size(); }
77
79 inline size_t NumFailLocal() const { return d_fail.size(); }
80
82 inline size_t NumExpectedFailLocal() const { return d_expected.size(); }
83
85 size_t NumPassGlobal() const;
86
88 size_t NumFailGlobal() const;
89
91 size_t NumExpectedFailGlobal() const;
92
94 inline const auto &getPass() const { return d_pass; }
95
97 inline const auto &getFail() const { return d_fail; }
98
100 inline const auto &getExpected() const { return d_expected; }
101
120 void report( const int level = 1, bool removeDuplicates = true ) const;
121
123 void reset();
124
125
126public: // printf like interfaces
127 inline void passes( const char *format, ... )
128 {
129 va_list ap;
130 va_start( ap, format );
131 char tmp[4096];
132 int n = vsnprintf( tmp, sizeof tmp, format, ap );
133 va_end( ap );
134 AMP_INSIST( n >= 0, "Error using stringf: encoding error" );
135 AMP_INSIST( n < (int) sizeof tmp, "Error using stringf: internal buffer size" );
136 passes( std::string( tmp ) );
137 }
138
139 inline void failure( const char *format, ... )
140 {
141 va_list ap;
142 va_start( ap, format );
143 char tmp[4096];
144 int n = vsnprintf( tmp, sizeof tmp, format, ap );
145 va_end( ap );
146 AMP_INSIST( n >= 0, "Error using stringf: encoding error" );
147 AMP_INSIST( n < (int) sizeof tmp, "Error using stringf: internal buffer size" );
148 failure( std::string( tmp ) );
149 }
150
151 inline void expected_failure( const char *format, ... )
152 {
153 va_list ap;
154 va_start( ap, format );
155 char tmp[4096];
156 int n = vsnprintf( tmp, sizeof tmp, format, ap );
157 va_end( ap );
158 AMP_INSIST( n >= 0, "Error using stringf: encoding error" );
159 AMP_INSIST( n < (int) sizeof tmp, "Error using stringf: internal buffer size" );
160 expected_failure( std::string( tmp ) );
161 }
162
163 inline void pass_fail( bool pass, const char *format, ... )
164 {
165 va_list ap;
166 va_start( ap, format );
167 char tmp[4096];
168 int n = vsnprintf( tmp, sizeof tmp, format, ap );
169 va_end( ap );
170 AMP_INSIST( n >= 0, "Error using stringf: encoding error" );
171 AMP_INSIST( n < (int) sizeof tmp, "Error using stringf: internal buffer size" );
172 pass_fail( pass, std::string( tmp ) );
173 }
174
175
176private:
177 std::vector<std::string> d_pass;
178 std::vector<std::string> d_fail;
179 std::vector<std::string> d_expected;
180};
181
182
183} // namespace AMP
184
185#endif
Class UnitTest is simple utility for running unit tests. It provides basic routines for tracing succe...
Definition UnitTest.h:49
size_t NumFailLocal() const
Return the number of failed tests locally.
Definition UnitTest.h:79
void passes(const char *format,...)
Definition UnitTest.h:127
size_t NumFailGlobal() const
Return the number of failed tests locally.
void pass_fail(bool pass, std::string in)
Indicate a pass/fail test.
void pass_fail(bool pass, const char *format,...)
Definition UnitTest.h:163
UnitTest()=default
Default constructor.
std::vector< std::string > d_expected
Definition UnitTest.h:179
size_t NumPassGlobal() const
Return the number of passed tests locally.
UnitTest & operator=(const UnitTest &)=delete
const auto & getFail() const
Return the number of failed tests locally.
Definition UnitTest.h:97
~UnitTest()
Destructor.
void failure(std::string in)
Indicate a failed test (thread-safe)
void expected_failure(std::string in)
Indicate an expected failed test (thread-safe)
void failure(const char *format,...)
Definition UnitTest.h:139
const auto & getPass() const
Return the tests passed locally.
Definition UnitTest.h:94
void report(const int level=1, bool removeDuplicates=true) const
std::vector< std::string > d_pass
Definition UnitTest.h:177
void passes(std::string in)
Indicate a passed test (thread-safe)
std::vector< std::string > d_fail
Definition UnitTest.h:178
size_t NumExpectedFailGlobal() const
Return the number of expected failed tests locally.
const auto & getExpected() const
Return the number of expected failed tests locally.
Definition UnitTest.h:100
void expected_failure(const char *format,...)
Definition UnitTest.h:151
void reset()
Clear the messages.
UnitTest(const UnitTest &)=delete
size_t NumPassLocal() const
Return the number of passed tests locally.
Definition UnitTest.h:76
size_t NumExpectedFailLocal() const
Return the number of expected failed tests locally.
Definition UnitTest.h:82
#define AMP_INSIST(EXP, MSG)
Insist error.



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page