2022-05-07 11:21:41 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <exception>
|
|
|
|
#include <iostream>
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
class TestFailedException : public std::exception
|
|
|
|
{
|
2022-05-07 11:21:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Asserts the comparison specified by CMP is true, or fails the current unit test
|
2024-03-20 19:35:52 +01:00
|
|
|
#define UASSERTCMP(CMP, actual, expected) \
|
|
|
|
do { \
|
|
|
|
const auto &a = (actual); \
|
|
|
|
const auto &e = (expected); \
|
|
|
|
if (!CMP(a, e)) { \
|
|
|
|
std::cout \
|
|
|
|
<< "Test assertion failed: " << #actual << " " << #CMP << " " \
|
|
|
|
<< #expected << std::endl \
|
|
|
|
<< " at " << __FILE__ << ":" << __LINE__ << std::endl \
|
|
|
|
<< " actual: " << a << std::endl \
|
|
|
|
<< " expected: " \
|
|
|
|
<< e << std::endl; \
|
|
|
|
throw TestFailedException(); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2022-05-07 11:21:41 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
#define CMPEQ(a, e) (a == e)
|
|
|
|
#define CMPTRUE(a, e) (a)
|
|
|
|
#define CMPNE(a, e) (a != e)
|
2022-05-07 11:21:41 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
#define UASSERTEQ(actual, expected) UASSERTCMP(CMPEQ, actual, expected)
|
2022-05-07 11:21:41 +02:00
|
|
|
#define UASSERTNE(actual, nexpected) UASSERTCMP(CMPNE, actual, nexpected)
|
2024-03-20 19:35:52 +01:00
|
|
|
#define UASSERT(actual) UASSERTCMP(CMPTRUE, actual, true)
|