[libc] Add support for enum in EXPECT_EQ

This commit is contained in:
Guillaume Chatelet 2022-06-01 08:41:56 +00:00
parent d3eadbe40d
commit 299baac64d
2 changed files with 18 additions and 2 deletions
libc
src/__support/CPP
utils/UnitTest

View File

@ -15,7 +15,9 @@ namespace __llvm_libc {
namespace cpp {
template <bool B, typename T> struct EnableIf;
template <typename T> struct EnableIf<true, T> { typedef T Type; };
template <typename T> struct EnableIf<true, T> {
typedef T Type;
};
template <bool B, typename T>
using EnableIfType = typename EnableIf<B, T>::Type;
@ -28,7 +30,9 @@ struct FalseValue {
static constexpr bool Value = false;
};
template <typename T> struct TypeIdentity { typedef T Type; };
template <typename T> struct TypeIdentity {
typedef T Type;
};
template <typename T1, typename T2> struct IsSame : public FalseValue {};
template <typename T> struct IsSame<T, T> : public TrueValue {};
@ -59,6 +63,10 @@ template <typename Type> struct IsIntegral {
;
};
template <typename Type> struct IsEnum {
static constexpr bool Value = __is_enum(Type);
};
template <typename T> struct IsPointerTypeNoCV : public FalseValue {};
template <typename T> struct IsPointerTypeNoCV<T *> : public TrueValue {};
template <typename T> struct IsPointerType {

View File

@ -89,6 +89,14 @@ protected:
return internal::test(Ctx, Cond, LHS, RHS, LHSStr, RHSStr, File, Line);
}
template <typename ValType,
cpp::EnableIfType<cpp::IsEnum<ValType>::Value, int> = 0>
bool test(TestCondition Cond, ValType LHS, ValType RHS, const char *LHSStr,
const char *RHSStr, const char *File, unsigned long Line) {
return internal::test(Ctx, Cond, (long long)LHS, (long long)RHS, LHSStr,
RHSStr, File, Line);
}
template <
typename ValType,
cpp::EnableIfType<cpp::IsPointerType<ValType>::Value, ValType> = nullptr>