A single group of tests, suitable for being all the tests of a small subsystem or single class. More...
#include <testdata.h>
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 UnitTestGroup & | operator+= (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 |
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.
UnitTestGroup::UnitTestGroup | ( | const UnitTestGroup & | OtherGroup | ) |
Copy constructor.
OtherGroup | A 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.
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
CurrentTest | The New test results and name |
Behavior | An 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
TestName | The name of the Test |
TResult | The actual TestResult |
Behavior | An 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.
Node | A pugi::xml_node referencing a UnitTestGroup |
Definition at line 301 of file testdata.cpp.
|
virtual |
Print the results or save them to a file.
Output | the stream to send the results to. |
Error | A stream to send errors to. |
Summary | Print Statistics at the end, not needed when sending results between processes. Defaults to true/enabled. |
FullOutput | Sometimes the user does not want to see each test results and just wants a little blurb. Defaults to true/enabled. |
HeaderOutput | Makes 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
Definition at line 348 of file testdata.cpp.
|
virtual |
Used only to report skipped tests.
Definition at line 203 of file testdata.cpp.
|
virtual |
Used only to report skipped tests.
Definition at line 210 of file testdata.cpp.
|
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.
Definition at line 217 of file testdata.cpp.
Tests should use this to launch things that need sheltering from segfaults and similar faults.
Argument | A string combined with the command to be run, this must be sanitized before being called, do not pass untrusted data. |
Definition at line 198 of file testdata.cpp.
|
virtual |
Get Name of this 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.
rhs | The item on the right hand side of the +=. |
Definition at line 290 of file testdata.cpp.
|
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();
Arg | An argument from the calling test. |
Definition at line 215 of file testdata.cpp.
|
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.
|
virtual |
Interpret Boolean value as a test result. Also Prepends the name of the current test, as returned by Name() + "::", to ease test scoping.
TestCondition | The test itself or the results of it. |
TestName | The comple name of the test, used to track results. |
IfFalse | Defaults to Testing::Failed but can be whatever Testing::TestResult you want if a false passed as the TestCondition. |
IfTrue | Defaults to Testing::Success but can be whatever Testing::TestResult you want if a true passed as the TestCondition. |
FuncName | The function the test was called from, if blank |
File | To make tracking down failures easier the file name of the test can be passed in, if not set an empty string is used |
Line | To 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.