API Documentation
Public Member Functions | List of all members
nkDebug::TestClass Class Reference

The test enabling class, allowing registration within the UnitTester. More...

Inheritance diagram for nkDebug::TestClass:
nkDebug::RegisteredTestClass< T, T_NAME >

Public Member Functions

 TestClass () noexcept
 
 TestClass (nkMemory::StringView name) noexcept
 
virtual ~TestClass ()
 
FunctionSetgetFunctionSet ()
 
const FunctionSetgetFunctionSet () const
 
std::function< bool()> getClassInitFunction () const
 
std::function< void()> getClassShutdownFunction () const
 
std::function< bool()> getFunctionInitFunction () const
 
std::function< void()> getFunctionShutdownFunction () const
 
nkMemory::StringView getName () const
 
bool setClassInitFunction (std::function< bool()> func)
 
bool setClassShutdownFunction (std::function< void()> func)
 
bool setTestFunctionInitFunction (std::function< bool()> func)
 
bool setTestFunctionShutdownFunction (std::function< void()> func)
 
void setName (nkMemory::StringView value)
 
void execute (const TestRunParameters &parameters) const
 

Detailed Description

The test enabling class, allowing registration within the UnitTester.

Implementing this class enables registering within the UnitTester for a run sequence. Utilities are provided within the class to ease the process.

An example of usage would be :

NK_TEST_CLASS(MyTestClass)
{
  NK_TEST_CLASS_INIT
  {
    // Code before the whole class is ran
  }

  NK_TEST_CLASS_SHUTDOWN
  {
    // Code after the whole class is ran
  }

  NK_TEST_FUNCTION_INIT
  {
    // Code before each function
  }

  NK_TEST_FUNCTION_SHUTDOWN
  {
    // Code after each function
  }

  NK_TEST_FUNCTION(myFirstFunction)
  {
    // First test function
  }

  NK_TEST_FUNCTION(mySecondFunction)
  {
    // Second test function
  }
}

To avoid name conflicts, you can use the NS variant of the macros to register classes and their namespaces. However, in the case of using the NS variant, do not forget to close it using the corresponding macro, like so :

NK_TEST_CLASS_NS(nkDebug::MyTests, MyTestClass)
{
  ...
}
NK_TEST_CLASS_NS_END

Constructor & Destructor Documentation

◆ TestClass() [1/2]

nkDebug::TestClass::TestClass ( )
noexcept

Default constructor.

◆ TestClass() [2/2]

nkDebug::TestClass::TestClass ( nkMemory::StringView  name)
noexcept

Named constructor.

Parameters
nameThe name to attach to the class.

◆ ~TestClass()

virtual nkDebug::TestClass::~TestClass ( )
virtual

Destructor.

Member Function Documentation

◆ getFunctionSet() [1/2]

FunctionSet& nkDebug::TestClass::getFunctionSet ( )

Non-const variant of the getter.

Returns
The registered functions set contained in the class.

◆ getFunctionSet() [2/2]

const FunctionSet& nkDebug::TestClass::getFunctionSet ( ) const

Const variant of the getter.

Returns
The registered functions set contained in the class.

◆ getClassInitFunction()

std::function<bool ()> nkDebug::TestClass::getClassInitFunction ( ) const
Returns
The function used before the test class is run.

◆ getClassShutdownFunction()

std::function<void ()> nkDebug::TestClass::getClassShutdownFunction ( ) const
Returns
The function used after the test class has been run.

◆ getFunctionInitFunction()

std::function<bool ()> nkDebug::TestClass::getFunctionInitFunction ( ) const
Returns
The function used before a test function is run.

◆ getFunctionShutdownFunction()

std::function<void ()> nkDebug::TestClass::getFunctionShutdownFunction ( ) const
Returns
The function used after a test function has been run.

◆ getName()

nkMemory::StringView nkDebug::TestClass::getName ( ) const
Returns
The name attached to the class.

◆ setClassInitFunction()

bool nkDebug::TestClass::setClassInitFunction ( std::function< bool()>  func)

Sets the callback called before the class runs all of its functions in a run.

Parameters
funcThe function to call.
Returns
A registration witness.
Remarks
The function registered returns a boolean as it has the power to prevent the class from being run by returning false. In such case, the class is then bypassed. To let the class run, the callback has to return true.

◆ setClassShutdownFunction()

bool nkDebug::TestClass::setClassShutdownFunction ( std::function< void()>  func)

Sets the callback called after all functions from the class have been run.

Parameters
funcThe function to call.
Returns
A registration witness.

◆ setTestFunctionInitFunction()

bool nkDebug::TestClass::setTestFunctionInitFunction ( std::function< bool()>  func)

Sets the callback called before each function run.

Parameters
funcThe function to call.
Returns
A registration witness.
Remarks
The function registered returns a boolean as it has the power to prevent the function from being run by returning false. In such case, the function is then bypassed. To let the function run, the callback has to return true.

◆ setTestFunctionShutdownFunction()

bool nkDebug::TestClass::setTestFunctionShutdownFunction ( std::function< void()>  func)

Sets the callback called after each function run.

Parameters
funcThe function to call.
Returns
A registration witness.

◆ setName()

void nkDebug::TestClass::setName ( nkMemory::StringView  value)

Sets the name attached to the class.

Parameters
valueThe name to attach.

◆ execute()

void nkDebug::TestClass::execute ( const TestRunParameters parameters) const

Requests the class to run all of its registered functions.

Parameters
parametersThe run parameters.

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