Ocean
Loading...
Searching...
No Matches
Ocean::Test::TestResult Class Reference

This class implements a simple test result accumulator. More...

#include <TestResult.h>

Public Member Functions

 TestResult ()=default
 Default constructor.
 
 TestResult (const std::string &testName)
 Constructor with test name.
 
 ~TestResult ()
 Destructs this test result object.
 
TestResultoperator= (bool value)
 Assignment operator for bool values.
 
bool succeeded () const
 Returns whether this test result has succeeded.
 
bool succeededSoFar () const
 Returns whether this test result has succeeded so far without marking it as checked.
 
bool anyTestExecuted () const
 Returns whether any test was executed.
 
const std::string & testName () const
 Returns the name of the test.
 

Protected Member Functions

 TestResult (const TestResult &)=delete
 Disabled copy constructor.
 
 TestResult (TestResult &&)=delete
 Disabled move constructor.
 
TestResultoperator= (const TestResult &)=delete
 Disabled copy assignment operator.
 
TestResultoperator= (TestResult &&)=delete
 Disabled move assignment operator.
 

Protected Attributes

std::string testName_
 The name of the test.
 
bool succeeded_ = true
 True if the test has succeeded; false if any test has failed.
 
bool anyTestExecuted_ = false
 True if at least one test was executed.
 
bool succeededChecked_ = false
 True if the success state of this result has been checked via succeeded().
 

Detailed Description

This class implements a simple test result accumulator.

The test result starts as succeeded (true) and can only be set to failed (false), never back to succeeded. This is useful for accumulating multiple test results where any failure marks the entire test as failed. Additionally, at least one test must be executed for the result to succeed.

Usage example:

bool testFunction()
{
TestResult testResult("My test");
testResult = testSubFunction1(); // If false, testResult becomes false
testResult = testSubFunction2(); // If false, testResult becomes false
testResult = testSubFunction3(); // If false, testResult becomes false
Log::info() << testResult; // Outputs "My test: succeeded." or "My test: FAILED!"
return testResult.succeeded(); // Must be called before destruction
}
static MessageObject info()
Returns the message for information messages.
Definition Messenger.h:1085
This class implements a simple test result accumulator.
Definition TestResult.h:47
See also
Validation

Constructor & Destructor Documentation

◆ TestResult() [1/4]

Ocean::Test::TestResult::TestResult ( )
default

Default constructor.

◆ TestResult() [2/4]

Ocean::Test::TestResult::TestResult ( const std::string &  testName)
inlineexplicit

Constructor with test name.

Parameters
testNameThe name of the test, used for logging output

◆ ~TestResult()

Ocean::Test::TestResult::~TestResult ( )
inline

Destructs this test result object.

◆ TestResult() [3/4]

Ocean::Test::TestResult::TestResult ( const TestResult )
protecteddelete

Disabled copy constructor.

◆ TestResult() [4/4]

Ocean::Test::TestResult::TestResult ( TestResult &&  )
protecteddelete

Disabled move constructor.

Member Function Documentation

◆ anyTestExecuted()

bool Ocean::Test::TestResult::anyTestExecuted ( ) const
inline

Returns whether any test was executed.

Returns
True if at least one test result was assigned; false otherwise

◆ operator=() [1/3]

TestResult & Ocean::Test::TestResult::operator= ( bool  value)
inline

Assignment operator for bool values.

Only accepts false values; true values are ignored to prevent accidental resetting of a failed state. Marks that a test was executed.

Parameters
valueThe boolean value to assign; only false will change the state
Returns
Reference to this object

◆ operator=() [2/3]

TestResult & Ocean::Test::TestResult::operator= ( const TestResult )
protecteddelete

Disabled copy assignment operator.

◆ operator=() [3/3]

TestResult & Ocean::Test::TestResult::operator= ( TestResult &&  )
protecteddelete

Disabled move assignment operator.

◆ succeeded()

bool Ocean::Test::TestResult::succeeded ( ) const
inline

Returns whether this test result has succeeded.

This function must be called before the object is destroyed (checked in debug mode).

Returns
True if all assigned values were true and at least one test was executed; false otherwise

◆ succeededSoFar()

bool Ocean::Test::TestResult::succeededSoFar ( ) const
inline

Returns whether this test result has succeeded so far without marking it as checked.

Returns
True if all assigned values were true and at least one test was executed; false otherwise

◆ testName()

const std::string & Ocean::Test::TestResult::testName ( ) const
inline

Returns the name of the test.

Returns
The test name, or empty string if no name was provided

Field Documentation

◆ anyTestExecuted_

bool Ocean::Test::TestResult::anyTestExecuted_ = false
protected

True if at least one test was executed.

◆ succeeded_

bool Ocean::Test::TestResult::succeeded_ = true
protected

True if the test has succeeded; false if any test has failed.

◆ succeededChecked_

bool Ocean::Test::TestResult::succeededChecked_ = false
mutableprotected

True if the success state of this result has been checked via succeeded().

◆ testName_

std::string Ocean::Test::TestResult::testName_
protected

The name of the test.


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