Vault
4.1
|
VUnit is a simple abstract base class used to build unit tests for the Vault classes. More...
#include <vunit.h>
Public Member Functions | |
VUnit (const VString &name, bool logOnSuccess, bool throwOnError) | |
Constructs a unit test object. | |
virtual | ~VUnit () |
Destructor. | |
void | setWriters (VUnitOutputWriterList *writers) |
Before a unit test suite is run, its output writers are set to that its results are recorded via those writers. | |
virtual void | run ()=0 |
Executes the unit test. | |
virtual void | reset () |
Resets all state before a re-run. | |
const VString & | getName () const |
Returns the unit's name. | |
bool | success () |
Returns true if all tests succeeded. | |
int | getNumSuccessfulTests () |
Returns the number of tests that succeeded. | |
int | getNumFailedTests () |
Returns the number of tests that failed. | |
void | logStart () |
void | logNormalEnd () |
void | logExceptionalEnd (const VString &exceptionMessage) |
Static Public Member Functions | |
static void | runUnit (VUnit &unit, VUnitOutputWriterList *writers) |
Runs a single unit's tests. | |
static void | rerunUnit (VUnit &unit, VUnitOutputWriterList *writers) |
Re-runs a single unit's tests. | |
Protected Member Functions | |
void | assertSuccess (const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertFailure (const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertTrue (bool b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (int a, int b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (unsigned int a, unsigned int b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (long a, long b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (bool a, bool b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (const VString &a, const VString &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (const VString &a, const char *b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (const VCodePoint &a, const VCodePoint &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (const char *a, const VString &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (const VChar &a, const VChar &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (const VChar &a, char b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (VDouble a, VDouble b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (const VDuration &a, const VDuration &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (const VInstant &a, const VInstant &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (Vs8 a, Vs8 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (Vu8 a, Vu8 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (Vs16 a, Vs16 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (Vu16 a, Vu16 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (char a, char b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (Vs64 a, Vs64 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (Vu64 a, Vu64 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (size_t a, size_t b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (const VColor &a, const VColor &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertEqual (const VColorPair &a, const VColorPair &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertFalse (bool b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (int a, int b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (unsigned int a, unsigned int b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (long a, long b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (bool a, bool b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (const VString &a, const VString &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (const VString &a, const char *b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (const VCodePoint &a, const VCodePoint &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (const char *a, const VString &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (const VChar &a, const VChar &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (const VChar &a, char b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (VDouble a, VDouble b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (const VDuration &a, const VDuration &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (const VInstant &a, const VInstant &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (Vs8 a, Vs8 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (Vu8 a, Vu8 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (Vs16 a, Vs16 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (Vu16 a, Vu16 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (Vs64 a, Vs64 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (Vu64 a, Vu64 b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (size_t a, size_t b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (const VColor &a, const VColor &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
void | assertNotEqual (const VColorPair &a, const VColorPair &b, const VString &labelSuffix, const VString &filePath, int lineNumber) |
virtual void | testAssertion (bool success, const VString &filePath, int lineNumber, const VString &labelSuffix, const VString &expectedDescription) |
Evaluates a boolean parameter that indicates test success, and logs and/or throws based on success/failure. | |
virtual void | test (bool success, const VString &description) |
Evaluates a boolean parameter that indicates test success, and logs and/or throws based on success/failure. | |
virtual void | test (const VString &a, const VString &b, const VString &description) |
Compares two strings for equality as the test evaluation. | |
void | logStatus (const VString &description) |
Logs an informational message to the unit test log, with a "[status ]" prefix. | |
Protected Attributes | |
VString | mName |
Name for display in log file. | |
bool | mLogOnSuccess |
True if we log successful tests. | |
bool | mThrowOnError |
True if we throw a VException on failed tests. | |
VUnitOutputWriterList * | mWriters |
The output writers to which test results are recorded. |
VUnit is a simple abstract base class used to build unit tests for the Vault classes.
Each unit test class is derived from VUnit and overrides the run() method. That method simply executes a bunch of tests, calling one of the test() functions to verify the results of each test.
The VUnit constructor lets you specify whether you want to log successful tests (you might want to only log the errors) and whether you want to throw an exception on failed tests (you might just want them logged rather than to throw).
The VUnitRunAll source executes every Vault unit test class.
VUnit::VUnit | ( | const VString & | name, |
bool | logOnSuccess, | ||
bool | throwOnError | ||
) |
VUnit::~VUnit | ( | ) | [virtual] |
void VUnit::runUnit | ( | VUnit & | unit, |
VUnitOutputWriterList * | writers | ||
) | [static] |
Runs a single unit's tests.
unit | the unit to run |
writers | writers to which test output will be collected and written |
Definition at line 19 of file vunit.cpp.
References run(), and setWriters().
void VUnit::rerunUnit | ( | VUnit & | unit, |
VUnitOutputWriterList * | writers | ||
) | [static] |
void VUnit::setWriters | ( | VUnitOutputWriterList * | writers | ) | [inline] |
Before a unit test suite is run, its output writers are set to that its results are recorded via those writers.
Had to do this with a setter rather than the constructor to avoid having to change existing code.
writers | the output writers that will record all results |
Definition at line 180 of file vunit.h.
References mWriters.
virtual void VUnit::run | ( | ) | [pure virtual] |
void VUnit::reset | ( | ) | [virtual] |
Resets all state before a re-run.
You can override if you had state in the subclass, in order to reset and then call inherited.
Definition at line 59 of file vunit.cpp.
References VString::EMPTY(), and VInstant::snapshot().
const VString& VUnit::getName | ( | ) | const [inline] |
bool VUnit::success | ( | ) | [inline] |
int VUnit::getNumSuccessfulTests | ( | ) | [inline] |
int VUnit::getNumFailedTests | ( | ) | [inline] |
void VUnit::testAssertion | ( | bool | success, |
const VString & | filePath, | ||
int | lineNumber, | ||
const VString & | labelSuffix, | ||
const VString & | expectedDescription | ||
) | [protected, virtual] |
Evaluates a boolean parameter that indicates test success, and logs and/or throws based on success/failure.
success | true if the test succeeded; false if not |
filePath | the source file path (usually via __FILE__) to log for a failed test |
lineNumber | the source line number (usually via __LINE__) to log for a failed test |
labelSuffix | the label (unit test description) to append as suffix of the output |
expectedDescription | the text describing the failure of expected data, for example "failed equality: 'tea' == 'coffee'" |
Definition at line 117 of file vunit.cpp.
References VString::chars(), VString::getSubstring(), VString::lastIndexOf(), and VInstant::snapshot().
void VUnit::test | ( | bool | success, |
const VString & | description | ||
) | [protected, virtual] |
Evaluates a boolean parameter that indicates test success, and logs and/or throws based on success/failure.
success | true if the test succeeded; false if not |
description | the text to log that describes the test |
Definition at line 132 of file vunit.cpp.
References VInstant::snapshot().
void VUnit::logStatus | ( | const VString & | description | ) | [protected] |