UnitTest Class Reference

Back to the index.

Static Public Member Functions | List of all members
UnitTest Class Reference

A collection of helper functions, for writing simple unit tests. More...

#include <UnitTest.h>

Static Public Member Functions

static int RunTests ()
 Runs all unit tests in GXemul. More...
 
static void Assert (const string &strFailMessage, bool condition)
 Asserts that a boolean condition is correct. More...
 
static void Assert (const string &strFailMessage, uint64_t actualValue, uint64_t expectedValue)
 Asserts that two uint64_t values are equal. More...
 
static void Assert (const string &strFailMessage, const string &actualValue, const string &expectedValue)
 Asserts that two string values are equal. More...
 
static void Fail (const string &strMessage)
 Fails a unit test unconditionally, by throwing a UnitTestFailedException. More...
 

Detailed Description

A collection of helper functions, for writing simple unit tests.

Definition at line 92 of file UnitTest.h.

Member Function Documentation

◆ Assert() [1/3]

void UnitTest::Assert ( const string &  strFailMessage,
bool  condition 
)
static

◆ Assert() [2/3]

void UnitTest::Assert ( const string &  strFailMessage,
uint64_t  actualValue,
uint64_t  expectedValue 
)
static

Asserts that two uint64_t values are equal.

If the values are not equal, Fail is called with the failure message.

The failure message can be something like "expected xyz", or "the list should be empty at this point".

Parameters
strFailMessageFailure message to print to std::cerr.
actualValueThe actual value.
expectedValueThe expected value.

Definition at line 47 of file UnitTest.cc.

References Fail().

◆ Assert() [3/3]

void UnitTest::Assert ( const string &  strFailMessage,
const string &  actualValue,
const string &  expectedValue 
)
static

Asserts that two string values are equal.

If the values are not equal, Fail is called with the failure message.

The failure message can be something like "expected xyz", or "the list should be empty at this point".

Parameters
strFailMessageFailure message to print to std::cerr.
actualValueThe actual value.
expectedValueThe expected value.

Definition at line 61 of file UnitTest.cc.

References Fail().

◆ Fail()

void UnitTest::Fail ( const string &  strMessage)
static

Fails a unit test unconditionally, by throwing a UnitTestFailedException.

Parameters
strMessagefailure message

Definition at line 80 of file UnitTest.cc.

Referenced by Assert().

◆ RunTests()

int UnitTest::RunTests ( )
static

Runs all unit tests in GXemul.

If WITHUNITTESTS was not defined in config.h, nothing is tested, and zero is returned.

Otherwise, unit tests for all classes that the configure script detected as using UNITTESTS(classname) are executed.

If a test fails, the UNITTEST(testname) macro in the unit testing framework takes care of outputting a line identifying that test to std::cerr.

Returns
zero if no unit tests failed, 1 otherwise.

Definition at line 89 of file UnitTest.cc.

Referenced by internal_w().


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

Generated on Sun Sep 30 2018 16:05:18 for GXemul by doxygen 1.8.13