NBEngine/engine/NBCore/tests/testErrors.cpp

39 lines
936 B
C++

#define CODE_ERROR_LOCATIONS
#include <gtest/gtest.h>
#include "Errors.hpp"
#include <string>
using namespace nb;
class TestError : public Error<TestError> {
using Base = Error<TestError>;
public:
using Base::Base;
using Base::what;
using Base::code;
using Base::msg;
using Base::trace;
enum Codes : unsigned int {
A, B, C, D
};
static const std::string type;
static const nb::ErrorCodeMap ErrorMessages;
};
const std::string TestError::type="TestError";
const ErrorCodeMap TestError::ErrorMessages{
{TestError::Codes::A, "Hey!"},
{TestError::Codes::B, "How"},
{TestError::Codes::C, "You"},
{TestError::Codes::D, "Doin"}
};
TEST(ErrorTest, Test) {
auto err = TestError(0, TestError(1, TestError(2, TestError(3, TestError(2)))));
ASSERT_STREQ(err.what().c_str(), "Hey!\n Trace: How\n Trace: You\n Trace: Doin\n Trace: You");
}