Vault  4.1
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
VUnit Class Reference

VUnit is a simple abstract base class used to build unit tests for the Vault classes. More...

#include <vunit.h>

Inheritance diagram for VUnit:
VFailureEmitter

List of all members.

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 VStringgetName () 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.

Detailed Description

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.

Definition at line 146 of file vunit.h.


Constructor & Destructor Documentation

VUnit::VUnit ( const VString name,
bool  logOnSuccess,
bool  throwOnError 
)

Constructs a unit test object.

Parameters:
namethe name of the unit test suite
logOnSuccesstrue if you want successful tests to be logged
throwOnErrortrue if you want an exception thrown for failed tests

Definition at line 43 of file vunit.cpp.

VUnit::~VUnit ( ) [virtual]

Destructor.

May log test result totals.

Definition at line 56 of file vunit.cpp.


Member Function Documentation

void VUnit::runUnit ( VUnit unit,
VUnitOutputWriterList *  writers 
) [static]

Runs a single unit's tests.

Parameters:
unitthe unit to run
writerswriters 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]

Re-runs a single unit's tests.

The unit is reset(), then we runUnit().

Parameters:
unitthe unit to re-run
writerswriters to which test output will be collected and written

Definition at line 38 of file vunit.cpp.

References reset(), and runUnit().

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.

Parameters:
writersthe output writers that will record all results

Definition at line 180 of file vunit.h.

References mWriters.

virtual void VUnit::run ( ) [pure virtual]

Executes the unit test.

Must be overridden by concrete class.

Implemented in VFailureEmitter.

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]

Returns the unit's name.

Returns:
c.f.

Definition at line 196 of file vunit.h.

References mName.

bool VUnit::success ( ) [inline]

Returns true if all tests succeeded.

Returns:
c.f.

Definition at line 201 of file vunit.h.

int VUnit::getNumSuccessfulTests ( ) [inline]

Returns the number of tests that succeeded.

Returns:
c.f.

Definition at line 206 of file vunit.h.

int VUnit::getNumFailedTests ( ) [inline]

Returns the number of tests that failed.

Returns:
c.f.

Definition at line 211 of file vunit.h.

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.

Parameters:
successtrue if the test succeeded; false if not
filePaththe source file path (usually via __FILE__) to log for a failed test
lineNumberthe source line number (usually via __LINE__) to log for a failed test
labelSuffixthe label (unit test description) to append as suffix of the output
expectedDescriptionthe 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.

Parameters:
successtrue if the test succeeded; false if not
descriptionthe text to log that describes the test

Definition at line 132 of file vunit.cpp.

References VInstant::snapshot().

void VUnit::test ( const VString a,
const VString b,
const VString description 
) [protected, virtual]

Compares two strings for equality as the test evaluation.

Parameters:
aa string
banother string
descriptionthe text to log that describes the test

Definition at line 143 of file vunit.cpp.

References test().

void VUnit::logStatus ( const VString description) [protected]

Logs an informational message to the unit test log, with a "[status ]" prefix.

This does not affect the test counters.

Parameters:
descriptionthe text to log that describes the status

Definition at line 147 of file vunit.cpp.

References mWriters, and NULL.


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

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.