Compare commits
2 Commits
126862748e
...
b593b7e083
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b593b7e083 | ||
|
|
a927b96a99 |
@ -1,6 +1,6 @@
|
|||||||
toAbsolutePath(NB_CORE_SOURCE
|
toAbsolutePath(NB_CORE_SOURCE
|
||||||
./src/Errors.cpp
|
./src/Errors.cpp
|
||||||
./src/Logger.cpp
|
# ./src/Logger.cpp
|
||||||
./src/Processes.cpp
|
./src/Processes.cpp
|
||||||
./src/Utils.cpp
|
./src/Utils.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
#ifndef _NB_ERROR
|
#ifndef _NB_ERROR
|
||||||
#define _NB_ERROR
|
#define _NB_ERROR
|
||||||
|
|
||||||
@ -6,10 +7,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include "TypeTraits.hpp"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
|
||||||
#ifndef THROW_WITH_INFO
|
/* #ifndef THROW_WITH_INFO
|
||||||
#ifdef CODE_ERROR_LOCATIONS
|
#ifdef CODE_ERROR_LOCATIONS
|
||||||
#define THROW_WITH_INFO(type, ...) throw type(__VA_ARGS__, __LINE__, __FILE__)
|
#define THROW_WITH_INFO(type, ...) throw type(__VA_ARGS__, __LINE__, __FILE__)
|
||||||
#else
|
#else
|
||||||
@ -23,30 +25,43 @@
|
|||||||
#else
|
#else
|
||||||
#define THROW(...) THROW_WITH_INFO(__VA_ARGS__)
|
#define THROW(...) THROW_WITH_INFO(__VA_ARGS__)
|
||||||
#endif // LOGGING
|
#endif // LOGGING
|
||||||
#endif // THROW
|
#endif // THROW */
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
typedef std::unordered_map<unsigned int, const char*> ErrorCodeMap;
|
typedef std::unordered_map<unsigned int, const char*> ErrorCodeMap;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using has_type = decltype(T::type);
|
||||||
|
|
||||||
|
template<typename StringType, typename ErrorType>
|
||||||
|
struct NBErrorWhatString;
|
||||||
|
|
||||||
|
class ErrorBase_what_str_impl : public std::exception {
|
||||||
|
template <typename T>
|
||||||
|
T what_str() const;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
virtual std::wstring what_str() const;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
virtual std::string what_str() const;
|
||||||
|
};
|
||||||
|
|
||||||
template<class ErrorType>
|
template<class ErrorType>
|
||||||
class ErrorBase : public std::exception {
|
class ErrorBase : public ErrorBase_what_str_impl {
|
||||||
public:
|
public:
|
||||||
ErrorBase(const ErrorBase&) = default;
|
ErrorBase(const ErrorBase&) = default;
|
||||||
ErrorBase& operator=(const ErrorBase&) = delete;
|
ErrorBase& operator=(const ErrorBase&) = delete;
|
||||||
|
|
||||||
|
template<typename StringType = std::string>
|
||||||
|
inline const StringType what_str() const noexcept {
|
||||||
|
return NBErrorWhatString<StringType,ErrorType>::what(*this);
|
||||||
|
}
|
||||||
|
|
||||||
virtual const char* what() const noexcept override final {
|
virtual const char* what() const noexcept override final {
|
||||||
std::string ret = this->msg;
|
const std::string& ret = what_str();
|
||||||
const std::string replace = nb::NEWLINE + "\t";
|
return ret.c_str();
|
||||||
if (trace) {
|
|
||||||
ret += replace + find_and_replace(
|
|
||||||
std::string(trace->what()),
|
|
||||||
nb::NEWLINE,
|
|
||||||
replace
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const std::string& ret_ref = ret;
|
|
||||||
return ret_ref.c_str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::string type;
|
static const std::string type;
|
||||||
@ -54,7 +69,8 @@ public:
|
|||||||
|
|
||||||
const unsigned int code;
|
const unsigned int code;
|
||||||
const std::string msg;
|
const std::string msg;
|
||||||
const std::exception* trace;
|
const std::shared_ptr<const std::exception> trace;
|
||||||
|
const bool traceIsNBError;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ErrorBase() = delete;
|
ErrorBase() = delete;
|
||||||
@ -72,7 +88,8 @@ protected:
|
|||||||
) noexcept :
|
) noexcept :
|
||||||
code(code_),
|
code(code_),
|
||||||
msg(msg_),
|
msg(msg_),
|
||||||
trace{static_cast<std::exception*>(trace_ ? new TraceType(*trace_) : nullptr) }
|
trace{trace_ ? std::make_shared<TraceType>(*trace_) : nullptr},
|
||||||
|
traceIsNBError( trace_ ? is_detected<has_type, TraceType>::value : false)
|
||||||
{
|
{
|
||||||
static_assert(std::is_same<const std::unordered_map<unsigned int, const char*>, decltype(ErrorType::ErrorMessages)>::value,
|
static_assert(std::is_same<const std::unordered_map<unsigned int, const char*>, decltype(ErrorType::ErrorMessages)>::value,
|
||||||
"const std::unordered_map<unsigned int, const char*> ErrorMessages must be "
|
"const std::unordered_map<unsigned int, const char*> ErrorMessages must be "
|
||||||
@ -148,19 +165,58 @@ protected:
|
|||||||
filename_
|
filename_
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
std::string (ErrorBase::*_trace_what_str)();
|
||||||
|
std::wstring (ErrorBase::*_trace_what_wstr)();
|
||||||
};
|
};
|
||||||
template <typename ErrorType>
|
template <typename ErrorType>
|
||||||
const std::string ErrorBase<ErrorType>::type = ErrorType::type;
|
const std::string ErrorBase<ErrorType>::type = ErrorType::type;
|
||||||
template <typename ErrorType>
|
template <typename ErrorType>
|
||||||
const ErrorCodeMap ErrorBase<ErrorType>::ErrorMessages = ErrorType::ErrorMessages;
|
const ErrorCodeMap ErrorBase<ErrorType>::ErrorMessages = ErrorType::ErrorMessages;
|
||||||
|
|
||||||
class DefaultError {DefaultError() = default;};
|
template<typename ErrorType>
|
||||||
|
struct NBErrorWhatString<std::wstring, ErrorType> {
|
||||||
|
inline static const std::wstring what(const ErrorBase<ErrorType>& err) noexcept {
|
||||||
|
std::wstring ret = nb::str_to_wstr(err.msg);
|
||||||
|
const std::wstring replace = nb::WNEWLINE + L"┗-";
|
||||||
|
if (err.trace) {
|
||||||
|
std::wstring trace_msg;
|
||||||
|
if (err.traceIsNBError) {
|
||||||
|
trace_msg = std::static_pointer_cast<ErrorBase_what_str_impl>(err.trace)->template what_str<std::wstring>();
|
||||||
|
} else {
|
||||||
|
trace_msg = nb::str_to_wstr(std::string(err.trace->what()));
|
||||||
|
}
|
||||||
|
trace_msg = find_and_replace<std::wstring>(trace_msg, L"┗", L"-");
|
||||||
|
ret += replace + find_and_replace<std::wstring>(
|
||||||
|
trace_msg,
|
||||||
|
nb::WNEWLINE,
|
||||||
|
replace
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <class ErrorType = DefaultError>
|
template<typename ErrorType>
|
||||||
|
struct NBErrorWhatString<std::string, ErrorType> {
|
||||||
|
inline static const std::string what(const ErrorBase<ErrorType>& err) noexcept {
|
||||||
|
std::string ret = err.msg;
|
||||||
|
const std::string replace = nb::NEWLINE+" ";
|
||||||
|
if (err.trace) {
|
||||||
|
ret += replace + find_and_replace(
|
||||||
|
std::string(err.trace->what()),
|
||||||
|
nb::NEWLINE,
|
||||||
|
replace
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class ErrorType = NoneType>
|
||||||
class Error;
|
class Error;
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
class Error<DefaultError>;
|
class Error<NoneType>;
|
||||||
|
|
||||||
template <class ErrorType>
|
template <class ErrorType>
|
||||||
class Error : public ErrorBase<ErrorType> {
|
class Error : public ErrorBase<ErrorType> {
|
||||||
@ -180,8 +236,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
class Error<DefaultError> : public ErrorBase<Error<DefaultError>> {
|
class Error<NoneType> : public ErrorBase<Error<NoneType>> {
|
||||||
using Base = ErrorBase<Error<DefaultError>>;
|
using Base = ErrorBase<Error<NoneType>>;
|
||||||
public:
|
public:
|
||||||
using Base::Base;
|
using Base::Base;
|
||||||
Error() : Base(0) {}
|
Error() : Base(0) {}
|
||||||
|
|||||||
@ -6,7 +6,43 @@
|
|||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
template<std::size_t N=0, typename Func, typename... Pack>
|
namespace detail {
|
||||||
|
template <
|
||||||
|
class Default,
|
||||||
|
class AlwaysVoid,
|
||||||
|
template <class...> class Op,
|
||||||
|
class... Args
|
||||||
|
>
|
||||||
|
struct detector {
|
||||||
|
using value = std::false_type;
|
||||||
|
using type = Default;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <
|
||||||
|
class Default,
|
||||||
|
template <class...> class Op,
|
||||||
|
class... Args
|
||||||
|
>
|
||||||
|
struct detector<Default, std::void_t<Op<Args...>>, Op, Args...> {
|
||||||
|
using value = std::true_type;
|
||||||
|
using type = Op<Args...>;
|
||||||
|
};
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
struct NoneType{};
|
||||||
|
|
||||||
|
template <
|
||||||
|
template <class...> class Op,
|
||||||
|
class... Args
|
||||||
|
>
|
||||||
|
using is_detected = typename detail::detector<NoneType, void, Op, Args...>::value;
|
||||||
|
|
||||||
|
template <typename Stream, typename... Args>
|
||||||
|
void stream(Stream& s, Args&&... args) {
|
||||||
|
(s << ... << args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*template<std::size_t N=0, typename Func, typename... Pack>
|
||||||
inline typename std::enable_if<N==sizeof...(Pack), void>::type
|
inline typename std::enable_if<N==sizeof...(Pack), void>::type
|
||||||
ForEach(std::tuple<Pack...>&, Func) {}
|
ForEach(std::tuple<Pack...>&, Func) {}
|
||||||
|
|
||||||
@ -68,7 +104,7 @@ struct PackIsSameType<T, PackType> {
|
|||||||
template <typename T, typename FirstPack, typename... Pack>
|
template <typename T, typename FirstPack, typename... Pack>
|
||||||
struct PackIsSameType<T, FirstPack, Pack...> {
|
struct PackIsSameType<T, FirstPack, Pack...> {
|
||||||
const bool value = std::is_base_of<T, FirstPack>::value && PackIsSameType<T, Pack...>::value;
|
const bool value = std::is_base_of<T, FirstPack>::value && PackIsSameType<T, Pack...>::value;
|
||||||
};
|
};*/
|
||||||
|
|
||||||
} // namespace nb
|
} // namespace nb
|
||||||
|
|
||||||
|
|||||||
@ -1,28 +1,68 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <type_traits>
|
||||||
#ifndef _NB_CORE_TYPES
|
#ifndef _NB_CORE_TYPES
|
||||||
#define _NB_CORE_TYPES
|
#define _NB_CORE_TYPES
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <utility>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
#ifdef _NB_TARGET_WINDOWS
|
#ifdef _NB_TARGET_WINDOWS
|
||||||
const std::string NEWLINE("\r\n");
|
const std::string NEWLINE = "\r\n";
|
||||||
|
const std::wstring WNEWLINE = L"\r\n";
|
||||||
#endif // _NB_TARGET_WINDOWS
|
#endif // _NB_TARGET_WINDOWS
|
||||||
#ifdef _NB_TARGET_LINUX
|
#ifdef _NB_TARGET_LINUX
|
||||||
const std::string NEWLINE("\n");
|
const std::string NEWLINE = "\n";
|
||||||
|
const std::wstring WNEWLINE = L"\n";
|
||||||
#endif // _NB_TARGET_LINUX
|
#endif // _NB_TARGET_LINUX
|
||||||
|
|
||||||
template<typename K, typename V, size_t N>
|
template<typename T>
|
||||||
struct ConstexprMap {
|
std::enable_if_t<std::is_convertible_v<const T&, std::string>, std::wstring> str_to_wstr(const T& in) {
|
||||||
template<typename Input>
|
std::string str(in);
|
||||||
constexpr ConstexprMap(Input inp) : _data{inp} {}
|
std::wstring ret(str.begin(), str.end());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
template<typename T>
|
||||||
const std::array<std::pair<K, V>, N> _data;
|
std::enable_if_t<std::is_convertible_v<const T&, std::wstring>, std::string> wstr_to_str(const T& in) {
|
||||||
};
|
std::wstring wstr(in);
|
||||||
|
std::size_t wstrlen = wstr.length();
|
||||||
|
char* c_str= new char[wstrlen];
|
||||||
|
std::wcstombs(c_str, wstr.c_str(), wstrlen);
|
||||||
|
std::string ret(c_str, wstrlen);
|
||||||
|
delete[] c_str;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T = std::string, typename A, typename B, typename C>
|
||||||
|
T find_and_replace(
|
||||||
|
const A& original,
|
||||||
|
const B& find,
|
||||||
|
const C& replace
|
||||||
|
) {
|
||||||
|
const T& original_t = T(original);
|
||||||
|
const T& find_t = T(find);
|
||||||
|
const T& replace_t = T(replace);
|
||||||
|
|
||||||
|
T ret = original_t;
|
||||||
|
|
||||||
|
std::size_t find_len = find_t.length();
|
||||||
|
std::size_t replace_len = replace_t.length();
|
||||||
|
std::size_t currpos = 0;
|
||||||
|
std::size_t lastpos = 0;
|
||||||
|
while(true) {
|
||||||
|
lastpos = currpos;
|
||||||
|
currpos = original_t.find(find_t, lastpos);
|
||||||
|
if (currpos == T::npos) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ret = ret.erase(currpos, find_len);
|
||||||
|
ret = ret.insert(currpos, replace_t);
|
||||||
|
currpos += replace_len;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* template<typename T>
|
/* template<typename T>
|
||||||
T swap_endian(const T& val) {
|
T swap_endian(const T& val) {
|
||||||
@ -37,7 +77,6 @@ T swap_endian(const T& val) {
|
|||||||
return ret;
|
return ret;
|
||||||
} */
|
} */
|
||||||
|
|
||||||
std::string find_and_replace(const std::string& original, const std::string& find, const std::string& replace);
|
|
||||||
|
|
||||||
// using ByteVector = std::vector<uint8_t>;
|
// using ByteVector = std::vector<uint8_t>;
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
#include "Errors.hpp"
|
#include "Errors.hpp"
|
||||||
|
#include "TypeTraits.hpp"
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
const std::string Error<DefaultError>::type = "nb::Error";
|
const std::string Error<nb::NoneType>::type = "nb::Error";
|
||||||
|
|
||||||
const ErrorCodeMap Error<DefaultError>::ErrorMessages = {
|
const ErrorCodeMap Error<nb::NoneType>::ErrorMessages = {
|
||||||
{Error::Codes::GENERAL, "General std::exception."},
|
{Error::Codes::GENERAL, "General std::exception."},
|
||||||
{Error::Codes::UNDEFINED, "Undefined / general error."},
|
{Error::Codes::UNDEFINED, "Undefined / general error."},
|
||||||
{Error::Codes::BADERRORCODE, "Unrecognized error code."}
|
{Error::Codes::BADERRORCODE, "Unrecognized error code."}
|
||||||
|
|||||||
@ -1,23 +1,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
|
||||||
|
template<>
|
||||||
std::string nb::find_and_replace(const std::string& original, const std::string& find, const std::string& replace) {
|
std::wstring nb::str_to_wstr(const std::string& in) {
|
||||||
std::string ret = original;
|
std::wstring ret(in.begin(), in.end());
|
||||||
|
|
||||||
std::size_t find_len = find.length();
|
|
||||||
std::size_t replace_len = replace.length();
|
|
||||||
std::size_t currpos = 0;
|
|
||||||
std::size_t lastpos = 0;
|
|
||||||
while(true) {
|
|
||||||
lastpos = currpos;
|
|
||||||
currpos = original.find(find, lastpos);
|
|
||||||
if (currpos == std::string::npos) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ret = ret.erase(currpos, find_len);
|
|
||||||
ret = ret.insert(currpos, replace);
|
|
||||||
currpos += replace_len;
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
#define CODE_ERROR_LOCATIONS
|
#define CODE_ERROR_LOCATIONS
|
||||||
|
|
||||||
#include "Errors.hpp"
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "Errors.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "TypeTraits.hpp"
|
||||||
|
|
||||||
using namespace nb;
|
using namespace nb;
|
||||||
|
|
||||||
@ -33,5 +36,12 @@ const ErrorCodeMap TestError::ErrorMessages{
|
|||||||
|
|
||||||
|
|
||||||
TEST(ErrorTest, Test) {
|
TEST(ErrorTest, Test) {
|
||||||
std::cout << TestError(0, TestError(1, TestError(2))).what();
|
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"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@ -1,17 +1,21 @@
|
|||||||
|
#include <iterator>
|
||||||
#define CODE_ERROR_LOCATIONS
|
#define CODE_ERROR_LOCATIONS
|
||||||
|
|
||||||
#include "Utils.hpp"
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "TypeTraits.hpp"
|
||||||
|
#include "Utils.hpp"
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
TEST(UtilsTest, Test) {
|
TEST(UtilsTest, TestFindAndReplace) {
|
||||||
ASSERT_STREQ(
|
ASSERT_STREQ(
|
||||||
find_and_replace("Jeff", "e", "efe").c_str(),
|
find_and_replace("Jeff", "e", "efe").c_str(),
|
||||||
"Jefeff"
|
"Jefeff"
|
||||||
);
|
);
|
||||||
|
|
||||||
auto tmp = find_and_replace("Naif", "a", "afa");
|
std::string tmp = find_and_replace("Naif", "a", "afa");
|
||||||
ASSERT_STREQ(
|
ASSERT_STREQ(
|
||||||
find_and_replace(tmp, "i", "ifi").c_str(),
|
find_and_replace(tmp, "i", "ifi").c_str(),
|
||||||
"Nafaifif"
|
"Nafaifif"
|
||||||
@ -38,4 +42,108 @@ TEST(UtilsTest, Test) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(UtilsTest, TestFindAndReplaceWstr) {
|
||||||
|
ASSERT_STREQ(
|
||||||
|
find_and_replace<std::wstring>(L"Jeff", L"e", L"efe").c_str(),
|
||||||
|
L"Jefeff"
|
||||||
|
);
|
||||||
|
|
||||||
|
std::wstring tmp = find_and_replace<std::wstring>(L"Naif", L"a", L"afa");
|
||||||
|
ASSERT_STREQ(
|
||||||
|
find_and_replace<std::wstring>(tmp, L"i", L"ifi").c_str(),
|
||||||
|
L"Nafaifif"
|
||||||
|
);
|
||||||
|
|
||||||
|
tmp = find_and_replace<std::wstring>(L"aeiou", L"a", L"afa");
|
||||||
|
tmp = find_and_replace<std::wstring>(tmp, L"e", L"efe");
|
||||||
|
tmp = find_and_replace<std::wstring>(tmp, L"i", L"ifi");
|
||||||
|
tmp = find_and_replace<std::wstring>(tmp, L"o", L"ofo");
|
||||||
|
tmp = find_and_replace<std::wstring>(tmp, L"u", L"ufu");
|
||||||
|
ASSERT_STREQ(
|
||||||
|
tmp.c_str(),
|
||||||
|
L"afaefeifiofoufu"
|
||||||
|
);
|
||||||
|
|
||||||
|
tmp = find_and_replace<std::wstring>(tmp, L"afa", L"a");
|
||||||
|
tmp = find_and_replace<std::wstring>(tmp, L"efe", L"e");
|
||||||
|
tmp = find_and_replace<std::wstring>(tmp, L"ifi", L"i");
|
||||||
|
tmp = find_and_replace<std::wstring>(tmp, L"ofo", L"o");
|
||||||
|
tmp = find_and_replace<std::wstring>(tmp, L"ufu", L"u");
|
||||||
|
ASSERT_STREQ(
|
||||||
|
tmp.c_str(),
|
||||||
|
L"aeiou"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UtilsTest, TestWstrToStr) {
|
||||||
|
ASSERT_STREQ(
|
||||||
|
nb::wstr_to_str(L"Hi!").c_str(),
|
||||||
|
"Hi!"
|
||||||
|
);
|
||||||
|
ASSERT_STREQ(
|
||||||
|
nb::wstr_to_str(L"Naif").c_str(),
|
||||||
|
"Naif"
|
||||||
|
);
|
||||||
|
ASSERT_STREQ(
|
||||||
|
nb::wstr_to_str(L"\r\r\r\n").c_str(),
|
||||||
|
"\r\r\r\n"
|
||||||
|
);
|
||||||
|
ASSERT_STREQ(
|
||||||
|
nb::wstr_to_str(L"Naif\ttalks\r\ra\t\nlot").c_str(),
|
||||||
|
"Naif\ttalks\r\ra\t\nlot"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UtilsTest, TestStrToWstr) {
|
||||||
|
ASSERT_STREQ(
|
||||||
|
nb::str_to_wstr("Hi!").c_str(),
|
||||||
|
L"Hi!"
|
||||||
|
);
|
||||||
|
ASSERT_STREQ(
|
||||||
|
nb::str_to_wstr("Naif").c_str(),
|
||||||
|
L"Naif"
|
||||||
|
);
|
||||||
|
ASSERT_STREQ(
|
||||||
|
nb::str_to_wstr("\r\r\r\n").c_str(),
|
||||||
|
L"\r\r\r\n"
|
||||||
|
);
|
||||||
|
ASSERT_STREQ(
|
||||||
|
nb::str_to_wstr("Naif\ttalks\r\ra\t\nlot").c_str(),
|
||||||
|
L"Naif\ttalks\r\ra\t\nlot"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A { bool x(); };
|
||||||
|
struct B { bool y(); };
|
||||||
|
struct C { bool x(); bool y; };
|
||||||
|
struct D : C {};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using has_x = decltype(T::x);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using has_y = decltype(T::y);
|
||||||
|
|
||||||
|
TEST(UtilsTest, TestIsDetected) {
|
||||||
|
auto ret = is_detected<has_x, A>::value;
|
||||||
|
ASSERT_TRUE(ret);
|
||||||
|
ret = is_detected<has_y, A>::value;
|
||||||
|
ASSERT_FALSE(ret);
|
||||||
|
|
||||||
|
ret = is_detected<has_y, B>::value;
|
||||||
|
ASSERT_TRUE(ret);
|
||||||
|
ret = is_detected<has_x, B>::value;
|
||||||
|
ASSERT_FALSE(ret);
|
||||||
|
|
||||||
|
ret = is_detected<has_x, C>::value;
|
||||||
|
ASSERT_TRUE(ret);
|
||||||
|
ret = is_detected<has_y, C>::value;
|
||||||
|
ASSERT_TRUE(ret);
|
||||||
|
|
||||||
|
ret = is_detected<has_x, D>::value;
|
||||||
|
ASSERT_TRUE(ret);
|
||||||
|
ret = is_detected<has_y, D>::value;
|
||||||
|
ASSERT_TRUE(ret);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace nb
|
} // namespace nb
|
||||||
Loading…
x
Reference in New Issue
Block a user