diff options
| -rw-r--r-- | tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index eeb665cea50..e98bdacd44a 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -14,7 +14,37 @@ #include <cmath> #include <limits> -#include <type_traits> +#include <QtCore/qxptype_traits.h> + +template <typename T> +using AdlSwappableTest = decltype(swap(std::declval<T&>(), std::declval<T&>())); + +template <typename T> +constexpr bool q_is_adl_swappable_v = qxp::is_detected_v<AdlSwappableTest, T>; + +QT_BEGIN_NAMESPACE + +// +// Check Q_DECLARE_SHARED +// +#define MAKE_CLASS(C) \ + struct C \ + { \ + std::string s; \ + explicit C(std::string s = {}) : s{std::move(s)} {} \ + void swap(C &other) noexcept { std::swap(s, other.s); } \ + } \ + /* end */ + +MAKE_CLASS(NotQDeclareShared); +static_assert(!q_is_adl_swappable_v<NotQDeclareShared>); + +MAKE_CLASS(Terry); // R.I.P. +Q_DECLARE_SHARED(Terry) + +#undef MAKE_CLASS + +QT_END_NAMESPACE class tst_QGlobal: public QObject { @@ -31,6 +61,8 @@ private slots: void qConstructorFunction(); void qCoreAppStartupFunction(); void qCoreAppStartupFunctionRestart(); + void qDeclareSharedMarksTheTypeRelocatable(); + void qDeclareSharedMakesTheTypeAdlSwappable(); void integerForSize(); void int128Literals(); void buildAbiEndianness(); @@ -396,6 +428,32 @@ void tst_QGlobal::qCoreAppStartupFunctionRestart() qCoreAppStartupFunction(); } +void tst_QGlobal::qDeclareSharedMarksTheTypeRelocatable() +{ + static_assert(!QTypeInfo<QT_PREPEND_NAMESPACE(NotQDeclareShared)>::isRelocatable); + static_assert( QTypeInfo<QT_PREPEND_NAMESPACE(Terry)>::isRelocatable); +} + +void tst_QGlobal::qDeclareSharedMakesTheTypeAdlSwappable() +{ + static_assert(!q_is_adl_swappable_v<QT_PREPEND_NAMESPACE(NotQDeclareShared)>); + static_assert( q_is_adl_swappable_v<QT_PREPEND_NAMESPACE(Terry)>); + + #define CHECK(Class) do { \ + using C = QT_PREPEND_NAMESPACE(Class); \ + C lhs("lhs"); \ + C rhs("rhs"); \ + QCOMPARE_EQ(lhs.s, "lhs"); \ + QCOMPARE_EQ(rhs.s, "rhs"); \ + /* no using std::swap - we're checking whether the ADL swap works */ \ + swap(lhs, rhs); \ + QCOMPARE_EQ(lhs.s, "rhs"); \ + QCOMPARE_EQ(rhs.s, "lhs"); \ + } while (false) + CHECK(Terry); + #undef CHECK +} + struct isEnum_A { int n_; }; |
