From 6555c626300a69faff87b9df21788ece545b2f58 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 19 Oct 2024 10:23:55 +0200 Subject: [PATCH] tst_QChar: add comprehensive conversion tests As usual, when making a change, we find out that test coverage was poor. Add such tests for QChar ctors. Amends (should have been a prequel commit of) 9ef4c123c39c642357c9e8530d59f32f220a7824. Conflict resolution for 6.8: - adjusted static_asserts to old QChar ctor overload set Pick-to: 6.5 6.2 5.15 Change-Id: Idcd9ab816ef815ce4a85dba1f7e37201b64c2203 Reviewed-by: Thiago Macieira Reviewed-by: Ahmad Samir (cherry picked from commit 69190a370d1e9f60c78f3096df62a61b6a5d1384) --- tests/auto/corelib/text/qchar/tst_qchar.cpp | 55 +++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/auto/corelib/text/qchar/tst_qchar.cpp b/tests/auto/corelib/text/qchar/tst_qchar.cpp index fae507f4c6d..3428988f858 100644 --- a/tests/auto/corelib/text/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/text/qchar/tst_qchar.cpp @@ -6,6 +6,61 @@ #include #include +#include + +template +constexpr inline bool implicitly = std::is_convertible_v; +template +constexpr inline bool explicitly = std::is_constructible_v; +template +constexpr inline bool disabled = !explicitly; + +// +// Conversion from character types +// +static_assert(implicitly); +#ifdef __cpp_char8_t +static_assert(explicitly); // via integer promotion +#endif +static_assert(implicitly); +#ifdef Q_OS_WIN +static_assert(implicitly); +#else +static_assert(explicitly); +#endif +static_assert(explicitly); + +// +// Conversion from others +// +static_assert(explicitly); +static_assert(implicitly); +static_assert(implicitly); +static_assert(explicitly); +static_assert(explicitly); + +// +// Disabled conversions (from Qt 6.9) +// +static_assert(explicitly); // via integer promotion +static_assert(disabled); +static_assert(explicitly); // via integer promotion +static_assert(disabled); +static_assert(disabled); +static_assert(disabled); +static_assert(disabled); +static_assert(explicitly); // via promotion to underlying_type_t +enum E1 {}; +static_assert(explicitly); // ditto +enum class E2 {}; +static_assert(disabled); +#ifndef Q_OS_QNX // ¯\_(ツ)_/¯ +enum E1C : char16_t {}; +static_assert(explicitly); +#endif +enum class E2C : char16_t {}; +static_assert(disabled); + class tst_QChar : public QObject { Q_OBJECT