Spinning Topp Logo BlackTopp Studios
inc
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Mezzanine::Testing::UnitTestGroup Class Reference

A single group of tests, suitable for being all the tests of a small subsystem or single class. More...

#include <testdata.h>

+ Inheritance diagram for Mezzanine::Testing::UnitTestGroup:
+ Collaboration diagram for Mezzanine::Testing::UnitTestGroup:

Public Member Functions

 UnitTestGroup ()
 Default constructor.
 
 UnitTestGroup (const UnitTestGroup &OtherGroup)
 Copy constructor. More...
 
void AddTestResult (TestData CurrentTest, OverWriteResults Behavior=OverWriteIfLessSuccessful)
 Its expected that tests will be inserted using this. More...
 
void AddTestResult (const Mezzanine::String TestName, TestResult TResult, OverWriteResults Behavior=OverWriteIfLessSuccessful)
 Add a test results without having to to construct a TestData first. More...
 
void AddTestsFromXML (pugi::xml_node Node)
 Create and add all the tests in a given piece of parsed xml. More...
 
virtual void DisplayResults (std::ostream &Output=std::cout, std::ostream &Error=std::cerr, bool Summary=true, bool FullOutput=true, bool HeaderOutput=true)
 Print the results or save them to a file. More...
 
String GetAsXML () const
 Get the Whole UnitTestGroup as a valid XML document. More...
 
virtual bool HasAutomaticTests () const
 Used only to report skipped tests. More...
 
virtual bool HasInteractiveTests () const
 Used only to report skipped tests. More...
 
virtual bool HasSubprocessTest () const
 If this returns false then the test suite treats it like any other test, if true then it enables some features for launching subprocess tests. More...
 
virtual Mezzanine::String Name ()
 Get Name of this UnitTestGroup. More...
 
const UnitTestGroupoperator+= (const UnitTestGroup &rhs)
 Add all the items in another UnitTestGroup to this one. More...
 
virtual void RunAutomaticTests ()
 This should be overloaded to run all tests that do require not user interaction.
 
virtual void RunInteractiveTests ()
 This should be overloaded to run all tests require user interaction.
 
virtual void RunSubprocessTest (const Mezzanine::String &Arg)
 Does nothing by default, tests which need to run code in a subprocess should override this. More...
 
virtual void RunTests ()
 This will call RunAutomaticTests based on the values passed. More...
 
virtual void ShouldRunAutomaticTests ()
 Sets a flag that indicatesz that is the process that should run this subprocess.
 
virtual void ShouldRunInteractiveTests ()
 Sets a flag that indicatesz that is the process that should run this subprocess.
 
virtual void ShouldRunSubProcessTests ()
 Sets a flag that indicatesz that is the process that should run this subprocess.
 
virtual void Test (bool TestCondition, const String &TestName, TestResult IfFalse=Testing::Failed, TestResult IfTrue=Testing::Success, const String &FuncName="", const String &File="", Mezzanine::Whole Line=0)
 Interpret Boolean value as a test result. Also Prepends the name of the current test, as returned by Name() + "::", to ease test scoping. More...
 

Protected Member Functions

void CaptureOutputBuffers ()
 This will direct any output that would have gone to an external process via cout to TestOutput Instead.
 
void LaunchAutomaticTest ()
 This launches all the automated tests on the derived class if the flag is set to run them otherwise it checks if tests exist via HasAutomaticTests() and marks them as skipped if they do.
 
void LaunchInteractiveTest ()
 This launches all the interactice tests on the derived class if the flag is set to run them otherwise it checks if tests exist via HasAutomaticTests() and marksthem as skipped if they do.
 
String LaunchSubProcessTest (const String &Argument=String(""))
 Tests should use this to launch things that need sheltering from segfaults and similar faults. More...
 
void RestoreOutputBuffers ()
 This will direct any error messages that would have gone to an external process via cerr to TestOutput Instead.
 

Protected Attributes

std::streambuf * CerrStreamBuf
 Used to store the buffer connected to the stderr while it is being redirected.
 
Int32 Completed
 Used while running a test to see if.
 
std::streambuf * CoutStreamBuf
 Used to store the buffer connected to the stdout while it is being redirected.
 
bool DoAutomaticTest
 Set the flag to run automatic tests.
 
bool DoInteractiveTest
 Sets the flag to run interactive tests.
 
bool DoSubProcessTest
 Set to false if subprocess tests should not be executed. True if they should.
 
unsigned int LongestNameLength
 Some basic variable for tracking simple statistics.
 
std::stringstream TestError
 A destination for errors.
 
std::stringstream TestOutput
 A destination for all normal ouput in the tests.
 

Friends

class OutputCaptureManager
 

Detailed Description

A single group of tests, suitable for being all the tests of a small subsystem or single class.

Definition at line 125 of file testdata.h.

Constructor & Destructor Documentation

UnitTestGroup::UnitTestGroup ( const UnitTestGroup OtherGroup)

Copy constructor.

Parameters
OtherGroupA UnitTestGroup to copy into this one. The contents of any log streams are copied and the streams themselves.

Definition at line 135 of file testdata.cpp.

Member Function Documentation

void UnitTestGroup::AddTestResult ( TestData  CurrentTest,
OverWriteResults  Behavior = OverWriteIfLessSuccessful 
)

Its expected that tests will be inserted using this.

This will automate tracking of the most and least successful tests

Parameters
CurrentTestThe New test results and name
BehaviorAn OverWriteResults that defines the overwrite behavior of this function, defaults to OverWriteIfLessSuccessful

Definition at line 225 of file testdata.cpp.

void UnitTestGroup::AddTestResult ( const Mezzanine::String  TestName,
TestResult  TResult,
OverWriteResults  Behavior = OverWriteIfLessSuccessful 
)

Add a test results without having to to construct a TestData first.

This prepends the name of this UnitTestGroup and "::" to the

Warning
The name of the test can have no spaces in it. An exception will be thrown if found.
Parameters
TestNameThe name of the Test
TResultThe actual TestResult
BehaviorAn OverWriteResults that defines the overwirte behavior of this function, defaults to OverWriteIfLessSuccessful

Definition at line 284 of file testdata.cpp.

void UnitTestGroup::AddTestsFromXML ( pugi::xml_node  Node)

Create and add all the tests in a given piece of parsed xml.

Parameters
NodeA pugi::xml_node referencing a UnitTestGroup

Definition at line 301 of file testdata.cpp.

void UnitTestGroup::DisplayResults ( std::ostream &  Output = std::cout,
std::ostream &  Error = std::cerr,
bool  Summary = true,
bool  FullOutput = true,
bool  HeaderOutput = true 
)
virtual

Print the results or save them to a file.

Parameters
Outputthe stream to send the results to.
ErrorA stream to send errors to.
SummaryPrint Statistics at the end, not needed when sending results between processes. Defaults to true/enabled.
FullOutputSometimes the user does not want to see each test results and just wants a little blurb. Defaults to true/enabled.
HeaderOutputMakes the output a little more understandable it is short or needs to be copied into a spreadsheet. Defaults to true/enabled.

Definition at line 363 of file testdata.cpp.

String UnitTestGroup::GetAsXML ( ) const

Get the Whole UnitTestGroup as a valid XML document.

The root element of the XMl document is named UnitTestGroup and it will contain the XML from each TestData this contains

Returns
A String containing some XML

Definition at line 348 of file testdata.cpp.

bool UnitTestGroup::HasAutomaticTests ( ) const
virtual

Used only to report skipped tests.

Returns
Defaults to returning false, but should be overloaded to return true if RunAutomaticTests() implements any tests.

Definition at line 203 of file testdata.cpp.

bool UnitTestGroup::HasInteractiveTests ( ) const
virtual

Used only to report skipped tests.

Returns
Defaults to returning false, but should be overloaded to return true if RunInteractiveTests() implements any tests.

Definition at line 210 of file testdata.cpp.

bool UnitTestGroup::HasSubprocessTest ( ) const
virtual

If this returns false then the test suite treats it like any other test, if true then it enables some features for launching subprocess tests.

This will cause an extra command line option to be created (as "debug" + testname). The function SubprocessTest() will be executed in the process that the new option is passed into. This allows for subprocess debugging. This will automatically be passed to the test process that will executed the sub-process tests.

Returns
This returns false by default, any test which wants to execute a subtest will need to implement this to return true.

Definition at line 217 of file testdata.cpp.

String UnitTestGroup::LaunchSubProcessTest ( const String Argument = String(""))
protected

Tests should use this to launch things that need sheltering from segfaults and similar faults.

Parameters
ArgumentA string combined with the command to be run, this must be sanitized before being called, do not pass untrusted data.
Returns
The output to stdout from the subprocess.

Definition at line 198 of file testdata.cpp.

Mezzanine::String UnitTestGroup::Name ( )
virtual

Get Name of this UnitTestGroup.

Returns
The string that must be type at the command line to run this testgroup, should be all lowercase.
Note
One of two methods that must be implmented on a UnitTestGroup

Definition at line 222 of file testdata.cpp.

const UnitTestGroup & UnitTestGroup::operator+= ( const UnitTestGroup rhs)

Add all the items in another UnitTestGroup to this one.

Parameters
rhsThe item on the right hand side of the +=.
Returns
A reference to this is returned allowiong operator chaining.

Definition at line 290 of file testdata.cpp.

void UnitTestGroup::RunSubprocessTest ( const Mezzanine::String Arg)
virtual

Does nothing by default, tests which need to run code in a subprocess should override this.

This will be executed in a subprocess before HasAutomaticTests() and RunInteractiveTests();

Parameters
ArgAn argument from the calling test.
Returns
Whatever was sent to stdout via C++ streams will be captured and sent here instead.

Definition at line 215 of file testdata.cpp.

void UnitTestGroup::RunTests ( )
virtual

This will call RunAutomaticTests based on the values passed.

All test results should be inserted using AddTestResult to allow the returning of results.

This can be overloaded to enable better detection of skipped tests. This niavely reports only "TestName::Interactive" and "TestName::Automatic" as skipped, and even then only if HasAutomaticTests or HasInteractiveTests return true.

Definition at line 148 of file testdata.cpp.

void UnitTestGroup::Test ( bool  TestCondition,
const String TestName,
TestResult  IfFalse = Testing::Failed,
TestResult  IfTrue = Testing::Success,
const String FuncName = "",
const String File = "",
Mezzanine::Whole  Line = 0 
)
virtual

Interpret Boolean value as a test result. Also Prepends the name of the current test, as returned by Name() + "::", to ease test scoping.

Warning
IfFalse comes first in the argument list, This is because the common test cases have IfTrue = Testing::Success while IfFalse makes sense as other things
Parameters
TestConditionThe test itself or the results of it.
TestNameThe comple name of the test, used to track results.
IfFalseDefaults to Testing::Failed but can be whatever Testing::TestResult you want if a false passed as the TestCondition.
IfTrueDefaults to Testing::Success but can be whatever Testing::TestResult you want if a true passed as the TestCondition.
FuncNameThe function the test was called from, if blank
FileTo make tracking down failures easier the file name of the test can be passed in, if not set an empty string is used
LineTo make tracking down failures easier the line number of the test can be passed in, if not set an empty string is used

Definition at line 424 of file testdata.cpp.


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