Spinning Topp Logo BlackTopp Studios
inc
Classes | Namespaces | Macros | Functions
testdatatools.h File Reference

TestData, TestDataStorage and UnitTestGroup class definitions. More...

#include "datatypes.h"
#include "testdata.h"
#include <limits>
+ Include dependency graph for testdatatools.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Mezzanine::Testing::TimedTest
 An easy way to get the time something took to execute. More...
 

Namespaces

 Mezzanine
 The bulk of the engine components go in this namspace.
 
 Mezzanine::Testing
 This contains all the items (except the tests themselves) that make the unit tests work.
 

Macros

#define TEST(Cond, Name)   Test( (Cond), (Name), Testing::Failed, Testing::Success, __func__, __FILE__, __LINE__ );
 The easiest way to add a test to the currently running UnitTestGroup. This captures test location meta data and should be considered the default way to record tests. More...
 
#define TEST_EQUAL_EPSILON(LeftValue, RightValue, Name)   Test( CompareEqualityWithEpsilon(LeftValue, RightValue), (Name), Testing::Failed, Testing::Success, __func__, __FILE__, __LINE__ );
 Compare types that might. More...
 
#define TEST_EQUAL_MULTI_EPSILON(LeftValue, RightValue, Name, EpsilonFactor)   Test( CompareEqualityWithEpsilon(LeftValue, RightValue, EpsilonFactor), (Name), Testing::Failed, Testing::Success, __func__, __FILE__, __LINE__ );
 
#define TEST_NO_THROW(CodeThatMightThrow, Name)
 
#define TEST_RESULT(ExistingResult, Name)   AddTestResult( TestData( (Name), (ExistingResult), __func__, __FILE__, __LINE__)) ;
 An easy way to add a test and associated data to the currently running UnitTestGroup This captures test location meta data and should be considered a good way to record tests that do not easily break down to a single conditional. More...
 
#define TEST_THROW(ExpectThrown, CodeThatThrows, Name)
 An easy way to add a test whether or not a function/code snippet throws exceptions (or whatever) the way planned. More...
 
#define TEST_TIMED(CodeToTime, ExpectedTime, Variance, Name)
 An easy way to add a test whether or not a function/code snippet takes the expected amount of time. More...
 
#define TEST_WARN(Cond, Name)   Test( (Cond), (Name), Testing::Warning, Testing::Success, __func__, __FILE__, __LINE__ );
 Just like TEST but if the test fails only a warning is added. This captures test location meta data and should be considered the default way to record tests that warn instead of fail. More...
 

Functions

template<typename T >
bool Mezzanine::Testing::CompareEqualityWithEpsilon (const T &Left, const T &Right, size_t EpsilonFactor=1)
 Calculate if an assumption is close enough to be considered equal. More...
 
MaxInt Mezzanine::Testing::Now ()
 Get a timestamp, in microseconds. This will generally be some multiple of the GetTimeStampResolution return value. More...
 
Whole Mezzanine::Testing::NowResolution ()
 Get the resolution of the timestamp in microseconds. This is the smallest amount of time that the GetTimeStamp can accurately track. More...
 

Detailed Description

TestData, TestDataStorage and UnitTestGroup class definitions.

Definition in file testdatatools.h.

Macro Definition Documentation

#define TEST (   Cond,
  Name 
)    Test( (Cond), (Name), Testing::Failed, Testing::Success, __func__, __FILE__, __LINE__ );

The easiest way to add a test to the currently running UnitTestGroup. This captures test location meta data and should be considered the default way to record tests.

Note
This calls a member function on the UnitTestGroup class, so it can only be used in UnitTestGroup Functions like UnitTestGroup::RunInteractiveTests or UnitTestGroup::RunAutomaticTests
Parameters
CondA boolean operand of some kind
NameThe name of the current test

Definition at line 67 of file testdatatools.h.

#define TEST_EQUAL_EPSILON (   LeftValue,
  RightValue,
  Name 
)    Test( CompareEqualityWithEpsilon(LeftValue, RightValue), (Name), Testing::Failed, Testing::Success, __func__, __FILE__, __LINE__ );

Compare types that might.

Parameters
LeftValueOne value to compare
RightValueOne value to compare
NameThe name of the current test

Definition at line 97 of file testdatatools.h.

#define TEST_EQUAL_MULTI_EPSILON (   LeftValue,
  RightValue,
  Name,
  EpsilonFactor 
)    Test( CompareEqualityWithEpsilon(LeftValue, RightValue, EpsilonFactor), (Name), Testing::Failed, Testing::Success, __func__, __FILE__, __LINE__ );

This is only rarely required. TEST_EQUAL_EPSILON should be prefferred as this can spuriously pass.

Parameters
LeftValueOne value to compare
RightValueOne value to compare
EpsilonFactorHow many times rounding could occur that could round to the epsilon, so that it can be accounted for?
NameThe name of the current test

Definition at line 111 of file testdatatools.h.

#define TEST_NO_THROW (   CodeThatMightThrow,
  Name 
)
Value:
try { \
CodeThatMightThrow; \
AddTestResult( TestData( (Name), Testing::Success, __func__, __FILE__, __LINE__)) ; \
} catch (...) { \
AddTestResult( TestData( (Name), Testing::Failed, __func__, __FILE__, __LINE__)) ; \
}
Indicates an abnormal termination of a Workunit or other failure, Likely the whole application will n...
Test was ran and appeared to work.

Definition at line 195 of file testdatatools.h.

#define TEST_RESULT (   ExistingResult,
  Name 
)    AddTestResult( TestData( (Name), (ExistingResult), __func__, __FILE__, __LINE__)) ;

An easy way to add a test and associated data to the currently running UnitTestGroup This captures test location meta data and should be considered a good way to record tests that do not easily break down to a single conditional.

Note
This calls a member function on the UnitTestGroup class, so it can only be used in UnitTestGroup Functions like UnitTestGroup::RunInteractiveTests or UnitTestGroup::RunAutomaticTests
Parameters
ExistingResultA TestResult To be added directy
NameThe name of the current test

Definition at line 141 of file testdatatools.h.

#define TEST_THROW (   ExpectThrown,
  CodeThatThrows,
  Name 
)
Value:
try { \
CodeThatThrows; \
AddTestResult( TestData( (Name), Testing::Failed, __func__, __FILE__, __LINE__)) ; \
} catch (ExpectThrown) { \
AddTestResult( TestData( (Name), Testing::Success, __func__, __FILE__, __LINE__)) ; \
} catch (...) { \
AddTestResult( TestData( (Name), Testing::Failed, __func__, __FILE__, __LINE__)) ; \
}
Indicates an abnormal termination of a Workunit or other failure, Likely the whole application will n...
Test was ran and appeared to work.

An easy way to add a test whether or not a function/code snippet throws exceptions (or whatever) the way planned.

This captures test location meta data and should be considered the default way to capture exception tests.

Note
This calls a member function on the UnitTestGroup class, so it can only be used in UnitTestGroup Functions like UnitTestGroup::RunInteractiveTests or UnitTestGroup::RunAutomaticTests
Parameters
ExpectThrownThe type of the thing that should be thrown
CodeThatThrowsA snippet of code that throws an exception
NameThe name of the current test

This captures test location meta data and should be considered the default way to capture exception tests

Note
This calls a member function on the UnitTestGroup class, so it can only be used in UnitTestGroup Functions like UnitTestGroup::RunInteractiveTests or UnitTestGroup::RunAutomaticTests
Parameters
CodeThatMightThrowThe type of the thing that should be thrown
NameThe name of the current test
#define TEST_TIMED (   CodeToTime,
  ExpectedTime,
  Variance,
  Name 
)
Value:
{ \
TimedTest TESTDuration; \
CodeToTime; \
MaxInt TESTLength = TESTDuration.GetLength(); \
MaxInt TESTTargetTime = ExpectedTime; \
MaxInt TESTVariance = Variance * double(ExpectedTime); \
if( MaxInt(TESTTargetTime-TESTVariance) < TESTLength && \
TESTLength < MaxInt(TESTTargetTime+TESTVariance)) \
{ AddTestResult( TestData( (Name), Testing::Success, __func__, __FILE__, __LINE__) ); } \
else \
{ AddTestResult( TestData( (Name), Testing::Failed, __func__, __FILE__, __LINE__) ); } \
}
Indicates an abnormal termination of a Workunit or other failure, Likely the whole application will n...
long long MaxInt
A large integer type suitable for compile time math and long term microsecond time keeping...
Definition: datatypes.h:190
Test was ran and appeared to work.

An easy way to add a test whether or not a function/code snippet takes the expected amount of time.

This starts a timer just before the CodeToTime is execute and stops that time right after it finishes

Note
This calls a member function on the UnitTestGroup class, so it can only be used in UnitTestGroup Functions like UnitTestGroup::RunInteractiveTests or UnitTestGroup::RunAutomaticTests
Parameters
CodeToTimeThe code to time
ExpectedTimeThe Expected amount if time in microseconds.
VarianceA fraction 0.00 of how far off, long or short, the execution time can be and still pass. For example .02 is 2%
NameThe name of the current test

Definition at line 256 of file testdatatools.h.

#define TEST_WARN (   Cond,
  Name 
)    Test( (Cond), (Name), Testing::Warning, Testing::Success, __func__, __FILE__, __LINE__ );

Just like TEST but if the test fails only a warning is added. This captures test location meta data and should be considered the default way to record tests that warn instead of fail.

Note
This calls a member function on the UnitTestGroup class, so it can only be used in UnitTestGroup Functions like UnitTestGroup::RunInteractiveTests or UnitTestGroup::RunAutomaticTests
Parameters
CondA boolean operand of some kind
NameThe name of the current test

Definition at line 126 of file testdatatools.h.