UnitTest.h File Reference

Back to the index.

Classes | Macros
UnitTest.h File Reference
#include "misc.h"
#include <exception>
#include <iostream>

Go to the source code of this file.

Classes

class  UnitTestFailedException
 An exception thrown by unit test cases that fail. More...
 
class  UnitTestable
 Base class for unit testable classes. More...
 
class  UnitTest
 A collection of helper functions, for writing simple unit tests. More...
 

Macros

#define UNITTESTS(class)   void class::RunUnitTests(int& nSucceeded, int& nFailures)
 Helper for unit test case execution. More...
 
#define UNITTEST(functionname)
 Helper for unit test case execution. More...
 

Macro Definition Documentation

◆ UNITTEST

#define UNITTEST (   functionname)
Value:
try { \
std::cout << "### " #functionname "\n"; \
(functionname)(); \
++ (nSucceeded); \
} catch (UnitTestFailedException& ex) { \
std::cout.flush(); \
std::cerr << "\n### " #functionname " (" __FILE__ " line " \
<< __LINE__ << ") failed!\n" \
" > " << ex.GetMessage() << "\n"; \
std::cerr.flush(); \
++ (nFailures); \
}
const string & GetMessage() const
Retrieves the error message associated with the exception.
Definition: UnitTest.h:57
An exception thrown by unit test cases that fail.
Definition: UnitTest.h:39

Helper for unit test case execution.

For each test case that throws a UnitTestFailedException, the number of failures is increased. For test cases that don't fail, the number of successful test cases is increased instead.

Usage: (usually at the end of a class implementation file)

     #ifdef WITHUNITTESTS
     static void MyClass::Test_MyClass_SomeTest()
     {
        UnitTest::Assert("expected blah blah", bool_condition);
        ... more asserts here ...
     }
     ...
     UNITTESTS(MyClass)
     {
        UNITTEST(Test_MyClass_SomeTest);
        UNITTEST(Test_MyClass_AnotherTest);
        ... more test cases here ...
     }
     #endif // WITHUNITTESTS

Note that MyClass (in the example above) should inherit from the UnitTestable class.

Definition at line 217 of file UnitTest.h.

Referenced by RootComponent::CheckVariableWrite(), EscapedString::Decode(), DYNTRANS_INSTR(), ComponentFactory::GetAllComponentNames(), DummyComponent::GetAttribute(), MachineComponent::GetAttribute(), CommandInterpreter::GetCurrentCommandBuffer(), QuitCommand::GetLongDescription(), ContinueBackwardsCommand::GetLongDescription(), VersionCommand::GetLongDescription(), CopyComponentCommand::GetLongDescription(), MoveComponentCommand::GetLongDescription(), PauseCommand::GetLongDescription(), ContinueCommand::GetLongDescription(), ResetCommand::GetLongDescription(), BackwardStepCommand::GetLongDescription(), StepCommand::GetLongDescription(), FileLoader::Load(), FileLoader_raw::LoadIntoComponent(), SymbolRegistry::LookupAddress(), Checksum::operator!=(), StateVariable::SetValue(), StringHelper::SplitStringIntoVector(), MainbusComponent::WriteData(), CPUComponent::WriteData(), CacheComponent::WriteData(), RAMComponent::WriteData(), and Command::~Command().

◆ UNITTESTS

#define UNITTESTS (   class)    void class::RunUnitTests(int& nSucceeded, int& nFailures)

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