TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Core::UnitTest::TestCaseInterface Class Referenceabstract
Inheritance diagram for TurtleBrains::Core::UnitTest::TestCaseInterface:
TurtleBrains::Core::Noncopyable

Public Member Functions

 TestCaseInterface (const std::string &testName)
 
const std::string & GetTestName (void) const
 
const std::string & GetMessageBuffer (void) const
 
bool IsWeakTest (void) const
 
bool RunTest (void)
 

Protected Member Functions

void DisableTest (void)
 
void SetWeakTest (void)
 
void StartSubTest (const String &subTestName)
 
template<typename Type >
bool ExpectedValue (const Type &value, const Type &expectedValue, const char *const formattedMessage,...)
 
template<typename Type >
bool ExpectedNotValue (const Type &value, const Type &expectedValue, const char *const formattedMessage,...)
 
void FailTestIf (bool testResult, const char *const formattedMessage,...)
 
bool ExpectedValue (float value, float expectedValue, const char *const formattedMessage,...)
 
bool ExpectedNotValue (float value, float expectedValue, const char *const formattedMessage,...)
 
bool ExpectedValueWithin (float value, float expectedValue, float epsilon, const char *const formattedMessage,...)
 
bool ExpectedValue (double value, double expectedValue, const char *const formattedMessage,...)
 
bool ExpectedNotValue (double value, double expectedValue, const char *const formattedMessage,...)
 
bool ExpectedValueWithin (double value, double expectedValue, double epsilon, const char *const formattedMessage,...)
 
bool ExpectedValues (size_t numberOfValues, const float *values, const float *expectedValues, const char *const formattedMessage,...)
 
bool ExpectedValuesWithin (size_t numberOfValues, const float *values, const float *expectedValues, float epsilon, const char *const formattedMessage,...)
 
bool ExpectedValues (size_t numberOfValues, const double *values, const double *expectedValues, const char *const formattedMessage,...)
 
bool ExpectedValuesWithin (size_t numberOfValues, const double *values, const double *expectedValues, double epsilon, const char *const formattedMessage,...)
 
bool ExpectedException (std::function< void(void)> testCode, const char *const formattedMessage,...)
 
virtual bool OnRunTest (void)=0
 
virtual void OnCompleteTest (bool testResult)
 
void FailedExpectation (String formattedMessage, va_list argumentList)
 
template<typename Type >
void FailedExpectedValues (const Type &value, const Type &expectedValue, const String formattedMessage, va_list argumentList)
 
void FailedExpectedValues (const bool value, const bool expectedValue, const String formattedMessage, va_list argumentList)
 

Static Protected Member Functions

static float DefaultEpsilonF (void)
 
static double DefaultEpsilon (void)
 

Friends

bool RunAllTests (const String &testMessageHeader, const String &testResultFile)
 
bool RunMatchingTests (const String &testMessageHeader, const String &testName, const String &testResultFile)
 

Member Function Documentation

◆ DisableTest()

void TurtleBrains::Core::UnitTest::TestCaseInterface::DisableTest ( void  )
inlineprotected

Sets a flag to disable the test. The disabled test will show up in the list of tests but will show [DISABLED] instead of the pass/fail state and the test will be skipped. This seems like a better idea than just silently removing tests you wish to disable for a period of time.

◆ ExpectedException()

bool TurtleBrains::Core::UnitTest::TestCaseInterface::ExpectedException ( std::function< void(void)>  testCode,
const char *const  formattedMessage,
  ... 
)
protected

Fail expectations if an error condition is not triggered by throwing an exception.

Note
This does NOT check that a specific error condition occurred.

◆ SetWeakTest()

void TurtleBrains::Core::UnitTest::TestCaseInterface::SetWeakTest ( void  )
inlineprotected

This sets a flag to make the test as a weak test, that is a test that is known not to really push the limits and boundaries, but just weakly tests the object.

Friends And Related Function Documentation

◆ RunAllTests

bool RunAllTests ( const String &  testMessageHeader,
const String &  testResultFile 
)
friend

Iterates over all the registered tests to run each test, printing the results as it goes. If all tests passed this will return true. If even one test failed, the rest of the tests will continue to run/be tested but false will be returned.

Parameters
testMessageHeaderA string that will get logged prior to starting the tests to help label them.
testResultFileThe filepath to write all the test results to.

◆ RunMatchingTests

bool RunMatchingTests ( const String &  testMessageHeader,
const String &  testName,
const String &  testResultFile 
)
friend

Iterates over all the registered tests and runs the tests that have a name containing the substring. If all the matching tests passed this will return true. If even one test failed, the rest of the matching tests will continue to run/be tested but false will be returned.

Parameters
testMessageHeaderA string that will get logged prior to starting the tests to help label them.
testNameThe substring to search each registered test for a match of.
testResultFileThe filepath to write all the test results to.