44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#pragma once
|
|
|
|
/**
|
|
* \file Test.h
|
|
* \brief File containing unit testing utilities
|
|
*/
|
|
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
|
|
/**
|
|
* \def TEST_SUCCESSFUL
|
|
* \brief Used in tests to indicate that a test was successful
|
|
*/
|
|
#define TEST_SUCCESSFUL 0
|
|
|
|
/**
|
|
* \def TEST_FAILED
|
|
* \brief Used in tests to indicate that a test failed
|
|
*/
|
|
#define TEST_FAILED 1
|
|
|
|
#ifndef __FUNCTION_NAME__
|
|
#ifdef _WIN32
|
|
#define __FUNCTION_NAME__ __FUNCTION__
|
|
#else
|
|
#define __FUNCTION_NAME__ __PRETTY_FUNCTION__
|
|
#endif
|
|
#endif
|
|
|
|
/**
|
|
* \def test_assert
|
|
* \param ... The expression to evaluate
|
|
* \brief Evaluates the expression and exits the program if not valid.
|
|
* \note It works like a basic assert() but also in release mode
|
|
*/
|
|
#define test_assert(...) \
|
|
if (!static_cast<bool>(__VA_ARGS__)) { \
|
|
std::cout << __FILE__ << ":" << __LINE__ << ": " << __FUNCTION_NAME__ << ": Assertion failed !\n"; \
|
|
std::cout << " " << __LINE__ << " |\t" << #__VA_ARGS__ << std::endl; \
|
|
std::exit(TEST_FAILED); \
|
|
}
|
|
|