#include "test/UnitTest/TestLogger.h" #include "src/__support/CPP/string.h" #include "src/__support/CPP/string_view.h" #include "src/__support/OSUtil/io.h" // write_to_stderr #include "src/__support/big_int.h" // is_big_int #include "src/__support/macros/config.h" #include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 #include "src/__support/uint128.h" #include namespace LIBC_NAMESPACE_DECL { namespace testing { // cpp::string_view specialization template <> TestLogger &TestLogger::operator<< (cpp::string_view str) { LIBC_NAMESPACE::write_to_stderr(str); return *this; } // cpp::string specialization template <> TestLogger &TestLogger::operator<< (cpp::string str) { return *this << static_cast(str); } // const char* specialization template <> TestLogger &TestLogger::operator<< (const char *str) { return *this << cpp::string_view(str); } // char* specialization template <> TestLogger &TestLogger::operator<< (char *str) { return *this << cpp::string_view(str); } // char specialization template <> TestLogger &TestLogger::operator<<(char ch) { return *this << cpp::string_view(&ch, 1); } // bool specialization template <> TestLogger &TestLogger::operator<<(bool cond) { return *this << (cond ? "true" : "false"); } // void * specialization template <> TestLogger &TestLogger::operator<<(void *addr) { return *this << "0x" << cpp::to_string(reinterpret_cast(addr)); } template TestLogger &TestLogger::operator<<(T t) { if constexpr (is_big_int_v || (cpp::is_integral_v && cpp::is_unsigned_v && (sizeof(T) > sizeof(uint64_t)))) { static_assert(sizeof(T) % 8 == 0, "Unsupported size of UInt"); const IntegerToString buffer(t); return *this << buffer.view(); } else { return *this << cpp::to_string(t); } } // is_integral specializations // char is already specialized to handle character template TestLogger &TestLogger::operator<< (short); template TestLogger &TestLogger::operator<< (int); template TestLogger &TestLogger::operator<< (long); template TestLogger &TestLogger::operator<< (long long); template TestLogger &TestLogger::operator<< (unsigned char); template TestLogger &TestLogger::operator<< (unsigned short); template TestLogger &TestLogger::operator<< (unsigned int); template TestLogger &TestLogger::operator<< (unsigned long); template TestLogger & TestLogger::operator<< (unsigned long long); #ifdef LIBC_TYPES_HAS_INT128 template TestLogger &TestLogger::operator<< <__uint128_t>(__uint128_t); #endif // LIBC_TYPES_HAS_INT128 template TestLogger &TestLogger::operator<< >(UInt<128>); template TestLogger &TestLogger::operator<< >(UInt<192>); template TestLogger &TestLogger::operator<< >(UInt<256>); template TestLogger &TestLogger::operator<< >(UInt<320>); // TODO: Add floating point formatting once it's supported by StringStream. TestLogger tlog; } // namespace testing } // namespace LIBC_NAMESPACE_DECL