summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-07-05 13:52:38 -0700
committerThiago Macieira <thiago.macieira@intel.com>2022-07-27 12:35:50 -0700
commit2e6398bd4626c054f18ca9762523dfcb49e31ab8 (patch)
tree1df9696b2cbb51947ca0a5e77b443b48562a53d8 /tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
parentcfdaf9226d5dd15a50cffa38ac39a1e29cb5e2fd (diff)
QMetaType: don't record trivial construction function pointers
We can implement the trivial {default,copy,move} construction outselves inside qmetatype.cpp and qvariant.cpp, simplifying the QMetaType interface object, removing up to three relocations per QMTI. This adds the testing for QMetaType::isXxxConstructible and isDestructible that couldn't be added before. Change-Id: Ic44396b31ba04712aab3fffd16ff0a28f541d507 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp')
-rw-r--r--tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp67
1 files changed, 61 insertions, 6 deletions
diff --git a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
index f4d64567ec..686e2a0e8b 100644
--- a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
+++ b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
@@ -20,6 +20,8 @@ private slots:
void sizeOf();
void flags_data();
void flags();
+ void flags2_data();
+ void flags2();
void construct_data();
void construct();
void constructCopy_data();
@@ -298,15 +300,19 @@ template <typename T> void addFlagsRow(const char *name, int id = qMetaTypeId<T>
QTest::newRow(name)
<< id
<< bool(QTypeInfo<T>::isRelocatable)
- << bool(QTypeInfo<T>::isComplex);
+ << bool(!std::is_trivially_default_constructible_v<T>)
+ << bool(!std::is_trivially_copy_constructible_v<T>)
+ << bool(!std::is_trivially_destructible_v<T>);
}
-
+// tst_QGuiMetaType::flags is nearly identical to tst_QMetaType::flags
void tst_QGuiMetaType::flags_data()
{
QTest::addColumn<int>("type");
QTest::addColumn<bool>("isRelocatable");
- QTest::addColumn<bool>("isComplex");
+ QTest::addColumn<bool>("needsConstruction");
+ QTest::addColumn<bool>("needsCopyConstruction");
+ QTest::addColumn<bool>("needsDestruction");
#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
addFlagsRow<RealType>(#RealType, MetaTypeId);
@@ -318,13 +324,62 @@ void tst_QGuiMetaType::flags()
{
QFETCH(int, type);
QFETCH(bool, isRelocatable);
- QFETCH(bool, isComplex);
+ QFETCH(bool, needsConstruction);
+ QFETCH(bool, needsCopyConstruction);
+ QFETCH(bool, needsDestruction);
- QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsConstruction), isComplex);
- QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsDestruction), isComplex);
+ QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsConstruction), needsConstruction);
+ QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsCopyConstruction), needsCopyConstruction);
+ QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsDestruction), needsDestruction);
QCOMPARE(bool(QMetaType(type).flags() & QMetaType::RelocatableType), isRelocatable);
}
+template <typename T> static void addFlags2Row(QMetaType metaType = QMetaType::fromType<T>())
+{
+ QTest::newRow(metaType.name() ? metaType.name() : "UnknownType")
+ << metaType
+ << std::is_default_constructible_v<T>
+ << std::is_copy_constructible_v<T>
+ << std::is_move_constructible_v<T>
+ << std::is_destructible_v<T>
+ << (QTypeTraits::has_operator_equal<T>::value || QTypeTraits::has_operator_less_than<T>::value)
+ << QTypeTraits::has_operator_less_than<T>::value;
+};
+
+// tst_QGuiMetaType::flags2 is nearly identical to tst_QMetaType::flags2
+void tst_QGuiMetaType::flags2_data()
+{
+ QTest::addColumn<QMetaType>("type");
+ QTest::addColumn<bool>("isDefaultConstructible");
+ QTest::addColumn<bool>("isCopyConstructible");
+ QTest::addColumn<bool>("isMoveConstructible");
+ QTest::addColumn<bool>("isDestructible");
+ QTest::addColumn<bool>("isEqualityComparable");
+ QTest::addColumn<bool>("isOrdered");
+
+#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
+ addFlags2Row<RealType>();
+QT_FOR_EACH_STATIC_GUI_CLASS(ADD_METATYPE_TEST_ROW)
+#undef ADD_METATYPE_TEST_ROW
+}
+
+void tst_QGuiMetaType::flags2()
+{
+ QFETCH(QMetaType, type);
+ QFETCH(bool, isDefaultConstructible);
+ QFETCH(bool, isCopyConstructible);
+ QFETCH(bool, isMoveConstructible);
+ QFETCH(bool, isDestructible);
+ QFETCH(bool, isEqualityComparable);
+ QFETCH(bool, isOrdered);
+
+ QCOMPARE(type.isDefaultConstructible(), isDefaultConstructible);
+ QCOMPARE(type.isCopyConstructible(), isCopyConstructible);
+ QCOMPARE(type.isMoveConstructible(), isMoveConstructible);
+ QCOMPARE(type.isDestructible(), isDestructible);
+ QCOMPARE(type.isEqualityComparable(), isEqualityComparable);
+ QCOMPARE(type.isOrdered(), isOrdered);
+}
void tst_QGuiMetaType::construct_data()
{