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 <thiago.macieira@intel.com> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> (cherry picked from commit 69190a370d1e9f60c78f3096df62a61b6a5d1384)
This commit is contained in:
parent
99448bb5f4
commit
6555c62630
@ -6,6 +6,61 @@
|
||||
#include <qfile.h>
|
||||
#include <qstringlist.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
template <typename C>
|
||||
constexpr inline bool implicitly = std::is_convertible_v<C, QChar>;
|
||||
template <typename C>
|
||||
constexpr inline bool explicitly = std::is_constructible_v<QChar, C>;
|
||||
template <typename C>
|
||||
constexpr inline bool disabled = !explicitly<C>;
|
||||
|
||||
//
|
||||
// Conversion from character types
|
||||
//
|
||||
static_assert(implicitly<char>);
|
||||
#ifdef __cpp_char8_t
|
||||
static_assert(explicitly<char8_t>); // via integer promotion
|
||||
#endif
|
||||
static_assert(implicitly<char16_t>);
|
||||
#ifdef Q_OS_WIN
|
||||
static_assert(implicitly<wchar_t>);
|
||||
#else
|
||||
static_assert(explicitly<wchar_t>);
|
||||
#endif
|
||||
static_assert(explicitly<char32_t>);
|
||||
|
||||
//
|
||||
// Conversion from others
|
||||
//
|
||||
static_assert(explicitly<uchar>);
|
||||
static_assert(implicitly<short>);
|
||||
static_assert(implicitly<ushort>);
|
||||
static_assert(explicitly<int>);
|
||||
static_assert(explicitly<uint>);
|
||||
|
||||
//
|
||||
// Disabled conversions (from Qt 6.9)
|
||||
//
|
||||
static_assert(explicitly<bool>); // via integer promotion
|
||||
static_assert(disabled<std::byte>);
|
||||
static_assert(explicitly<signed char>); // via integer promotion
|
||||
static_assert(disabled<long>);
|
||||
static_assert(disabled<long long>);
|
||||
static_assert(disabled<unsigned long>);
|
||||
static_assert(disabled<unsigned long long>);
|
||||
static_assert(explicitly<Qt::Key>); // via promotion to underlying_type_t
|
||||
enum E1 {};
|
||||
static_assert(explicitly<E1>); // ditto
|
||||
enum class E2 {};
|
||||
static_assert(disabled<E2>);
|
||||
#ifndef Q_OS_QNX // ¯\_(ツ)_/¯
|
||||
enum E1C : char16_t {};
|
||||
static_assert(explicitly<E1C>);
|
||||
#endif
|
||||
enum class E2C : char16_t {};
|
||||
static_assert(disabled<E2C>);
|
||||
|
||||
class tst_QChar : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
Loading…
x
Reference in New Issue
Block a user