NBEngine/engine/NBCore/tests/testErrors.cpp

47 lines
1.0 KiB
C++

#define CODE_ERROR_LOCATIONS
#include <gtest/gtest.h>
#include "Errors.hpp"
#include <iostream>
#include <string>
#include "TypeTraits.hpp"
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));
nb::stream(std::cout,
"len string: ", err.what_str().length(), "\n",
"len wstring: ", err.what_str<std::wstring>().length(), "\n"
);
nb::stream(std::wcout,
err.what_str<std::wstring>(), L"\n"
);
}