Skip to content

Commit

Permalink
Fix failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SergiusTheBest committed Oct 12, 2023
1 parent a9ae269 commit 4c2ca08
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
46 changes: 38 additions & 8 deletions include/plog/Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ namespace plog
};

template <class T>
struct isConvertibleToNString : isConvertible<T, util::nstring> {};
struct isConvertibleToString : isConvertible<T, std::string> {};

#if PLOG_ENABLE_WCHAR_INPUT
template <class T>
struct isConvertibleToString : isConvertible<T, std::string> {};
struct isConvertibleToWString : isConvertible<T, std::wstring> {};
#endif

template <class T>
struct isContainer
Expand Down Expand Up @@ -168,18 +170,29 @@ namespace plog

#if defined(__clang__) || !defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__) >= 405 // skip for GCC < 4.5 due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38600
#if !defined(_MSC_VER) || _MSC_VER > 1400 // MSVC 2005 doesn't understand `enableIf`, so drop all `meta`
// Print data that can be casted to `std::basic_string`.
// Print data that can be casted to `std::string`
template<class T>
inline typename meta::enableIf<meta::isConvertibleToString<T>::value, void>::type operator<<(util::nostringstream& stream, const T& data)
{
plog::detail::operator<<(stream, static_cast<std::string>(data));
}

#if PLOG_ENABLE_WCHAR_INPUT
// Print data that can be casted to `std::wstring`
template<class T>
inline typename meta::enableIf<meta::isConvertibleToNString<T>::value, void>::type operator<<(util::nostringstream& stream, const T& data)
inline typename meta::enableIf<meta::isConvertibleToWString<T>::value, void>::type operator<<(util::nostringstream& stream, const T& data)
{
plog::detail::operator<<(stream, static_cast<util::nstring>(data));
plog::detail::operator<<(stream, static_cast<std::wstring>(data));
}
#endif

// Print std containers
template<class T>
inline typename meta::enableIf<meta::isContainer<T>::value &&
!meta::isConvertibleToNString<T>::value &&
!meta::isConvertibleToString<T>::value &&
#if PLOG_ENABLE_WCHAR_INPUT
!meta::isConvertibleToWString<T>::value &&
#endif
!meta::isFilesystemPath<T>::value, void>::type operator<<(util::nostringstream& stream, const T& data)
{
stream << "[";
Expand All @@ -202,14 +215,15 @@ namespace plog
#endif

#ifdef __cplusplus_cli
// Print managed C++ `System::String^`
inline void operator<<(util::nostringstream& stream, System::String^ data)
{
cli::pin_ptr<const System::Char> ptr = PtrToStringChars(data);
plog::detail::operator<<(stream, static_cast<const wchar_t*>(ptr));
}
#endif

#if defined(_WIN32) && (!defined(_MSC_VER) || _MSC_VER > 1400) // MSVC 2005 doesn't understand `enableIf`, so drop all `meta`
#if PLOG_ENABLE_WCHAR_INPUT && (!defined(_MSC_VER) || _MSC_VER > 1400) // MSVC 2005 doesn't understand `enableIf`, so drop all `meta`
namespace meta
{
template<bool Value>
Expand Down Expand Up @@ -244,13 +258,29 @@ namespace plog
# endif //__cpp_char8_t
}

# if PLOG_CHAR_IS_UTF8
// Print types that can be streamed into `std::owstringstream` but not into `std::ostringstream` when we use UTF-8 on Windows
template<class T>
inline typename meta::enableIf<meta::isStreamable<T, std::wostream>::value &&
!meta::isStreamable<T, std::ostream>::value &&
!meta::isConvertibleToWString<T>::value, void>::type operator<<(std::ostringstream& stream, const T& data)
{
std::wostringstream ss;
ss << data;
stream << ss.str();
}
# else
// Print types that can be streamed into `std::ostringstream` but not into `std::owstringstream` when we use `wchar_t` on Windows
template<class T>
inline typename meta::enableIf<meta::isStreamable<T, std::ostream>::value && !meta::isStreamable<T, std::wostream>::value, void>::type operator<<(std::wostringstream& stream, const T& data)
inline typename meta::enableIf<meta::isStreamable<T, std::ostream>::value &&
!meta::isStreamable<T, std::wostream>::value &&
!meta::isConvertibleToString<T>::value, void>::type operator<<(std::wostringstream& stream, const T& data)
{
std::ostringstream ss;
ss << data;
stream << ss.str();
}
# endif
#endif
}

Expand Down
1 change: 1 addition & 0 deletions test/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifdef __cpp_constexpr
# include "doctest/2.4.11/doctest.h" // pre C++11
#else
# define DOCTEST_CONFIG_NO_MULTITHREADING
# include "doctest/1.2.9/doctest.h" // C++11 and higher
#endif

Expand Down
2 changes: 0 additions & 2 deletions test/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

SCENARIO("std::filesystem::path")
{
# if !defined(_WIN32) || !PLOG_CHAR_IS_UTF8 // FIXME: fix this test on Windows UTF-8
GIVEN("logger is initialised")
{
plog::TestAppender testAppender;
Expand All @@ -23,7 +22,6 @@ SCENARIO("std::filesystem::path")
}
}
}
# endif
}

#endif
4 changes: 0 additions & 4 deletions test/StdStreamable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ SCENARIO("cast to string")
}

#if PLOG_ENABLE_WCHAR_INPUT
# ifndef __linux__ // FIXME: fix this test on Linux
# if !defined(_WIN32) || !PLOG_CHAR_IS_UTF8 // FIXME: fix this test on Windows UTF-8
WHEN("type is streamable to std::wostream")
{
StdWStreamable var;
Expand All @@ -66,8 +64,6 @@ SCENARIO("cast to string")
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("StdWStreamable (id: 1, name: water)"));
}
}
# endif
# endif
#endif
}
}
2 changes: 0 additions & 2 deletions test/StringTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ SCENARIO("string types")
}

# ifdef __cpp_lib_string_view
# ifndef __linux__ // FIXME: fix this test on Linux
WHEN("type is std::wstring_view")
{
std::wstring_view var = L"test";
Expand All @@ -192,7 +191,6 @@ SCENARIO("string types")
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("test"));
}
}
# endif
# endif
#endif

Expand Down

0 comments on commit 4c2ca08

Please sign in to comment.