Spinning Topp Logo BlackTopp Studios
inc
Classes | Typedefs | Enumerations | Functions
Mezzanine::Testing Namespace Reference

This contains all the items (except the tests themselves) that make the unit tests work. More...

Classes

class  OutputCaptureManager
 Used to aplly RAII to Stdout and STDERR buffers/streams. More...
 
struct  TestData
 The information about a test and how to easily find it in the filesystem. More...
 
class  TimedTest
 An easy way to get the time something took to execute. More...
 
class  UnitTestGroup
 A single group of tests, suitable for being all the tests of a small subsystem or single class. More...
 

Typedefs

typedef std::map< Mezzanine::String, UnitTestGroup * > CoreTestGroup
 A group of testnames and the Actual test that implement those test(s).
 
typedef std::set< TestDataTestDataStorage
 Just a map to store the content of TestData, incidentally it will lexographically sort the list of tests.
 

Enumerations

enum  ExitCodes { ExitSuccess = 0, ExitInvalidArguments = 1, ExitFailure = 2 }
 Possible ways to exit the UnitTestGroup Program. More...
 
enum  OverWriteResults { OverWriteIfLessSuccessful, OverWriteIfMoreSuccessful, OverWrite, DoNotOverWrite }
 This is used to control the behavior of the function UnitTestGroup::AddTestResult() More...
 
enum  TestResult {
  Success = 0, Warning = 1, Skipped = 2, Cancelled = 3,
  Inconclusive = 4, Failed = 5, Unknown = 6, NotApplicable = 7
}
 Return values from tests. More...
 

Functions

char * AllLower (char *StringToConvert)
 Makes a c style stron all lowercase with respect to the current locale. More...
 
String AllLower (String StringToConvert)
 
Mezzanine::String BoolToString (bool i)
 Get a String Corresponding to a passed bool. More...
 
const Mezzanine::String CancelledString ("Cancelled")
 Corresponds to TestResult::Cancelled.
 
template<typename T >
bool CompareEqualityWithEpsilon (const T &Left, const T &Right, size_t EpsilonFactor=1)
 Calculate if an assumption is close enough to be considered equal. More...
 
const Mezzanine::String FailedString ("Failed")
 Corresponds to TestResult::Failed.
 
String GetCommandResults (String Command)
 Execute a command in a process, piping its standard output to a file. More...
 
TestResult GetTestAnswerFromStdin (Mezzanine::String Question, Boole FailStatusOnIncorrect=true)
 Asked the user a question on the std output and get a TestResult as an answer. More...
 
const Mezzanine::String InconclusiveString ("Inconclusive")
 Corresponds to TestResult::Inconclusive.
 
String MakePadding (Mezzanine::String Leader, unsigned int Column)
 Creates some blank spaces, useful for controlling the vertical location of console text. More...
 
const Mezzanine::String NotApplicableString ("NotApplicable")
 Corresponds to TestResult::NotApplicable.
 
MaxInt Now ()
 Get a timestamp, in microseconds. This will generally be some multiple of the GetTimeStampResolution return value. More...
 
Whole NowResolution ()
 Get the resolution of the timestamp in microseconds. This is the smallest amount of time that the GetTimeStamp can accurately track. More...
 
int PrintList (CoreTestGroup &TestGroups)
 Print all the groups that exist in a given CoreTestGroup. More...
 
String rtrim (const Mezzanine::String &t)
 Take the whitespace off the end of a String. More...
 
const Mezzanine::String SkippedString ("Skipped")
 Corresponds to TestResult::Skipped.
 
void sleep_for (UInt32 MicroSeconds)
 Sleeps the current thread for an amount of microseconds. More...
 
TestData StringToTestData (Mezzanine::String Line)
 Trim the whitespace from a line of text and try to interpret the remains as TestResults and a testname. More...
 
TestResult StringToTestResult (Mezzanine::String Text)
 Roughly convert a String to a TestResult. More...
 
const Mezzanine::String SuccessString ("Success")
 Corresponds to TestResult::Success.
 
Mezzanine::String TestResultToString (TestResult Convertable)
 This converts A test result enum value into a String matching the identifier name. More...
 
const Mezzanine::String UnknownString ("Unknown")
 Corresponds to TestResult::Unknown.
 
int Usage (Mezzanine::String ThisName, CoreTestGroup &TestGroups)
 Print a message for the user onf the standard output that briefly describes hwo to use this. More...
 
const Mezzanine::String WarningString ("Warning")
 Corresponds to TestResult::Warning.
 

Detailed Description

This contains all the items (except the tests themselves) that make the unit tests work.

Enumeration Type Documentation

Possible ways to exit the UnitTestGroup Program.

Enumerator
ExitSuccess 

Normal exit all tests skipped or better.

ExitInvalidArguments 

At least some invalid args were passed on the command line.

ExitFailure 

At least one test return worse then skipped.

Definition at line 53 of file testenumerations.h.

This is used to control the behavior of the function UnitTestGroup::AddTestResult()

This can optionally be passedto prioritize whether newer vs older or successful vs failing results are more important

Enumerator
OverWriteIfLessSuccessful 

This is the default behavior, because it is presumed failures should be visible so they can be fixed.

OverWriteIfMoreSuccessful 

Overwrite only if the result is better than the old result.

OverWrite 

Just Overwrite, useful if the test was defaulted to a low value.

DoNotOverWrite 

This is a supplementary running a test, if a results already exists, skip writing anything.

Definition at line 107 of file testenumerations.h.

Return values from tests.

These are loosely order from best to worse, in terms of what we want to see from our tests. This takes the midset that knowing about a failure is better than not knowing about it.

Enumerator
Success 

Test was ran and appeared to work.

Warning 

Technically the test passed but there is something that is not quite right.

Skipped 

Test was simply not ran at the behest of the user.

Cancelled 

Was canceled by user, so success is unknown, but user knows test was canceled.

Inconclusive 

If a user answers that with "don't know" in a test that involved interaction, The user knows there is a potential issue.

Failed 

Known failure.

Unknown 

Since we don't know what happened this is the worst kind of failure.

NotApplicable 

This is not even a kind of failure, This is used to when referencing a test, so if this winds up coming out of a test, then something has failed.

Definition at line 64 of file testenumerations.h.

Function Documentation

char * Mezzanine::Testing::AllLower ( char *  StringToConvert)

Makes a c style stron all lowercase with respect to the current locale.

Parameters
StringToConvertThis string is actually changed.
Returns
for convience purposes the string is also returned.

Definition at line 78 of file consolestringmanipulation.cpp.

Mezzanine::String Mezzanine::Testing::BoolToString ( bool  i)

Get a String Corresponding to a passed bool.

Parameters
iA bool
Returns
"True" if true is passed, "False" if false is passed.

Definition at line 98 of file consolestringmanipulation.cpp.

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.

this uses std::numeric_limits<T>::epsilon() to get the amount of round that is acceptable. This all the Epsilon to be included multiple times if required generally once is the right amount to include. However, sometimes an operation can cause rounding multiple times, if this is case, then an EpsilonFactor can be passed and set to the number of times rounding can be expected.

Parameters
LeftOne value to check for equality.
RightThe other value to check.
EpsilonFactorHow many times should the epsilon be included.

Definition at line 80 of file testdatatools.h.

String Mezzanine::Testing::GetCommandResults ( String  Command)

Execute a command in a process, piping its standard output to a file.

Returns
The contents of the file as String

Definition at line 173 of file consolelogic.cpp.

TestResult Mezzanine::Testing::GetTestAnswerFromStdin ( Mezzanine::String  Question,
Boole  FailStatusOnIncorrect = true 
)

Asked the user a question on the std output and get a TestResult as an answer.

Parameters
QuestionThe question to ask the user.
FailStatusOnIncorrectDefaults to true,FailStatusOnIncorrect if true False answers with return Fail Status otherwise they will return Warnings.

The following strings provide the following results.

  • "True", "Yes" as Success
  • "False", "No" as Failed or Warn
  • "Cancel" as "Canceled"
  • "Unsure", "Inconclusive" as Inconclusive
    Returns
    Depends on users input

Definition at line 135 of file consolelogic.cpp.

Mezzanine::String Mezzanine::Testing::MakePadding ( Mezzanine::String  Leader,
unsigned int  Column 
)

Creates some blank spaces, useful for controlling the vertical location of console text.

Parameters
LeaderThe string on the beginning of the line.
ColumnThe desired column that the padding should lead toward
Returns
If "asdf" and 6 are passed this will return " " (Two spaces).

Definition at line 70 of file consolestringmanipulation.cpp.

MaxInt Mezzanine::Testing::Now ( )

Get a timestamp, in microseconds. This will generally be some multiple of the GetTimeStampResolution return value.

Warning
On some platforms this requires a static initialization, an can cause undefined behavior if called before static initializations are complete
Returns
The largest size integer containing a timestamp that can be compared to other timestamps, but hads no guarantees for external value.

Definition at line 99 of file testdatatools.cpp.

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.

Returns
A Whole which returns in millionths of a second the smallest unit of time that GetTimeStamp can measure.

Definition at line 106 of file testdatatools.cpp.

int Mezzanine::Testing::PrintList ( CoreTestGroup TestGroups)

Print all the groups that exist in a given CoreTestGroup.

Parameters
TestGroupsThe group whose constents names with be printed
Returns
ExitSuccess on success.

Definition at line 93 of file testdata.cpp.

Mezzanine::String Mezzanine::Testing::rtrim ( const Mezzanine::String t)

Take the whitespace off the end of a String.

Parameters
tThe Text to clean up.
If" asdf " is passed " asdf" is returned. Also removes carriage returns, newlines and tabs. Does not use the locale.

Definition at line 56 of file consolestringmanipulation.cpp.

void Mezzanine::Testing::sleep_for ( UInt32  MicroSeconds)

Sleeps the current thread for an amount of microseconds.

Blocks the calling thread for a period of time.

Parameters
MicroSecondsthe amount of micro seconds.

Definition at line 181 of file consolelogic.cpp.

TestData Mezzanine::Testing::StringToTestData ( Mezzanine::String  Line)

Trim the whitespace from a line of text and try to interpret the remains as TestResults and a testname.

Parameters
LineA line of Test that starts with whitespace, then a TestResult String, then has a whitesapce delimiter and a ends with the name of test.
Returns
A parsed TestData.

Definition at line 100 of file testdata.cpp.

TestResult Mezzanine::Testing::StringToTestResult ( Mezzanine::String  Text)

Roughly convert a String to a TestResult.

Parameters
TextIf this matches a word like "Success", "Skipped", "Cancelled", "Inconclusive", "Failed", "Unknown" or "N/A" exactly as returned by TestResultToString then a valid result can be returned.
Returns
The TestResult corresponding to the String passed in.
Exceptions
Ifthe string passed in does not match a valid TestResult then this will throw a PARAMETERS_EXCEPTION

Definition at line 81 of file testenumerations.cpp.

Mezzanine::String Mezzanine::Testing::TestResultToString ( TestResult  Convertable)

This converts A test result enum value into a String matching the identifier name.

Parameters
ConvertableA TestResult inclusively between Success and NotApplicable.
Returns
A string like "Success" or "Inconclusive" or similar.
Exceptions
Ifan int not in the valid range of TestResult is passed in then this will throw a PARAMETERS_EXCEPTION

Definition at line 56 of file testenumerations.cpp.

int Mezzanine::Testing::Usage ( Mezzanine::String  ThisName,
CoreTestGroup TestGroups 
)

Print a message for the user onf the standard output that briefly describes hwo to use this.

Parameters
ThisNameThe name of the current executable
TestGroupsThis is searched for the current list of valid test names.
Returns
Always returns ExitInvalidArguments

Definition at line 74 of file consolelogic.cpp.