Advanced Multi-Physics (AMP)
On-Line Documentation
Public Member Functions | Private Attributes | List of all members
AMP::UnitTest Class Referencefinal

Class UnitTest is simple utility for running unit tests. It provides basic routines for tracing success or failure of tests, and reporting the results. More...

#include <UnitTest.h>

Public Member Functions

void expected_failure (const char *format,...)
 
void expected_failure (std::string in)
 Indicate an expected failed test (thread-safe)
 
void failure (const char *format,...)
 
void failure (std::string in)
 Indicate a failed test (thread-safe)
 
const auto & getExpected () const
 Return the number of expected failed tests locally.
 
const auto & getFail () const
 Return the number of failed tests locally.
 
const auto & getPass () const
 Return the tests passed locally.
 
size_t NumExpectedFailGlobal () const
 Return the number of expected failed tests locally.
 
size_t NumExpectedFailLocal () const
 Return the number of expected failed tests locally.
 
size_t NumFailGlobal () const
 Return the number of failed tests locally.
 
size_t NumFailLocal () const
 Return the number of failed tests locally.
 
size_t NumPassGlobal () const
 Return the number of passed tests locally.
 
size_t NumPassLocal () const
 Return the number of passed tests locally.
 
UnitTestoperator= (const UnitTest &)=delete
 
void pass_fail (bool pass, const char *format,...)
 
void pass_fail (bool pass, std::string in)
 Indicate a pass/fail test.
 
void passes (const char *format,...)
 
void passes (std::string in)
 Indicate a passed test (thread-safe)
 
void report (const int level=1, bool removeDuplicates=true) const
 
void reset ()
 Clear the messages.
 
 UnitTest ()=default
 Default constructor.
 
 UnitTest (const UnitTest &)=delete
 
 ~UnitTest ()
 Destructor.
 

Private Attributes

std::vector< std::string > d_expected
 
std::vector< std::string > d_fail
 
std::vector< std::string > d_pass
 

Detailed Description

Class UnitTest is simple utility for running unit tests. It provides basic routines for tracing success or failure of tests, and reporting the results.

Code Sample:
int main(int argc, char *argv[])
{
try {
std::cout << "Testing tstOne" << std::endl;
tstOne(&ut);
ut.passes("Test XXX passed");
} catch( ... ) {
ut.failure("An unknown exception was thrown");
}
ut.report();
return ut.NumFail();
}
void tstOne(AMP::UnitTest *ut)
{
// Run the test code
if ( problem1 ) {
ut.failure("Problem 1 detected");
return
}
// Finished running test
ut.passes("Test XXX passed");
}
static void startup(int &argc, char *argv[], const AMPManagerProperties &properties=AMPManagerProperties())
Class UnitTest is simple utility for running unit tests. It provides basic routines for tracing succe...
Definition UnitTest.h:49
void failure(std::string in)
Indicate a failed test (thread-safe)
void report(const int level=1, bool removeDuplicates=true) const
void passes(std::string in)
Indicate a passed test (thread-safe)

Definition at line 48 of file UnitTest.h.

Constructor & Destructor Documentation

◆ UnitTest() [1/2]

AMP::UnitTest::UnitTest ( )
default

Default constructor.

◆ ~UnitTest()

AMP::UnitTest::~UnitTest ( )

Destructor.

◆ UnitTest() [2/2]

AMP::UnitTest::UnitTest ( const UnitTest )
delete

Member Function Documentation

◆ expected_failure() [1/2]

void AMP::UnitTest::expected_failure ( const char *  format,
  ... 
)
inline

Definition at line 151 of file UnitTest.h.

References AMP_INSIST, and expected_failure().

◆ expected_failure() [2/2]

void AMP::UnitTest::expected_failure ( std::string  in)

Indicate an expected failed test (thread-safe)

Referenced by expected_failure().

◆ failure() [1/2]

void AMP::UnitTest::failure ( const char *  format,
  ... 
)
inline

Definition at line 139 of file UnitTest.h.

References AMP_INSIST, and failure().

◆ failure() [2/2]

void AMP::UnitTest::failure ( std::string  in)

Indicate a failed test (thread-safe)

Referenced by failure().

◆ getExpected()

const auto & AMP::UnitTest::getExpected ( ) const
inline

Return the number of expected failed tests locally.

Definition at line 100 of file UnitTest.h.

References d_expected.

◆ getFail()

const auto & AMP::UnitTest::getFail ( ) const
inline

Return the number of failed tests locally.

Definition at line 97 of file UnitTest.h.

References d_fail.

◆ getPass()

const auto & AMP::UnitTest::getPass ( ) const
inline

Return the tests passed locally.

Definition at line 94 of file UnitTest.h.

References d_pass.

◆ NumExpectedFailGlobal()

size_t AMP::UnitTest::NumExpectedFailGlobal ( ) const

Return the number of expected failed tests locally.

◆ NumExpectedFailLocal()

size_t AMP::UnitTest::NumExpectedFailLocal ( ) const
inline

Return the number of expected failed tests locally.

Definition at line 82 of file UnitTest.h.

References d_expected.

◆ NumFailGlobal()

size_t AMP::UnitTest::NumFailGlobal ( ) const

Return the number of failed tests locally.

◆ NumFailLocal()

size_t AMP::UnitTest::NumFailLocal ( ) const
inline

Return the number of failed tests locally.

Definition at line 79 of file UnitTest.h.

References d_fail.

◆ NumPassGlobal()

size_t AMP::UnitTest::NumPassGlobal ( ) const

Return the number of passed tests locally.

◆ NumPassLocal()

size_t AMP::UnitTest::NumPassLocal ( ) const
inline

Return the number of passed tests locally.

Definition at line 76 of file UnitTest.h.

References d_pass.

◆ operator=()

UnitTest & AMP::UnitTest::operator= ( const UnitTest )
delete

◆ pass_fail() [1/2]

void AMP::UnitTest::pass_fail ( bool  pass,
const char *  format,
  ... 
)
inline

Definition at line 163 of file UnitTest.h.

References AMP_INSIST, and pass_fail().

◆ pass_fail() [2/2]

void AMP::UnitTest::pass_fail ( bool  pass,
std::string  in 
)

Indicate a pass/fail test.

Referenced by pass_fail().

◆ passes() [1/2]

void AMP::UnitTest::passes ( const char *  format,
  ... 
)
inline

Definition at line 127 of file UnitTest.h.

References AMP_INSIST, and passes().

◆ passes() [2/2]

void AMP::UnitTest::passes ( std::string  in)

Indicate a passed test (thread-safe)

Referenced by passes().

◆ report()

void AMP::UnitTest::report ( const int  level = 1,
bool  removeDuplicates = true 
) const

Print a report of the passed and failed tests. Note: This is a blocking call that all processors must execute together. Note: Only rank 0 will print the messages (this is necessary as other ranks may not be able to print correctly).

Parameters
levelOptional integer specifying the level of reporting (default: 1) 0: Report the number of tests passed, failed, and expected failures. 1: Report the passed tests (if <=20) or number passed, Report all failures, Report the expected failed tests (if <=50) or the number passed. 2: Report the passed tests (if <=50) Report all failures, Report all expected 3: Report all passed, failed, and expected failed tests.
removeDuplicatesRemove duplicate messages. If set, the total number of message will be unchanged but if printed duplicate messages will be removed

◆ reset()

void AMP::UnitTest::reset ( )

Clear the messages.

Member Data Documentation

◆ d_expected

std::vector<std::string> AMP::UnitTest::d_expected
private

Definition at line 179 of file UnitTest.h.

Referenced by getExpected(), and NumExpectedFailLocal().

◆ d_fail

std::vector<std::string> AMP::UnitTest::d_fail
private

Definition at line 178 of file UnitTest.h.

Referenced by getFail(), and NumFailLocal().

◆ d_pass

std::vector<std::string> AMP::UnitTest::d_pass
private

Definition at line 177 of file UnitTest.h.

Referenced by getPass(), and NumPassLocal().


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



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:42.
Comments on this page