summaryrefslogtreecommitdiff
path: root/tests/auto
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-03-23 07:02:42 -1000
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-03-24 10:55:31 +0000
commit298657409ce576d2f6979a8966dc8c5f71b39bc1 (patch)
treeab1d0d2f08774db533f10e79d7f3de6e84827923 /tests/auto
parent7db137e8e996d5bafe079f10a1a2114707c61927 (diff)
downloadqtbase-298657409ce576d2f6979a8966dc8c5f71b39bc1.tar.gz
QVariant: ensure the type custom is registered on construction
I must have broken this in the 6.5 work I did for QMetaType and QVariant, but I haven't searched which commit exactly did it. Our QVariant tests are old and thus only checked the type ID, which meant that they caused the registration by the act of asking for the ID in the first place; this commit adds a couple of explicit checks for the type registered by name before the ID. Fixes: QTBUG-112205 Change-Id: Idd5e1bb52be047d7b4fffffd174f1b14d90fd7a3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 8570e86fff183ffa4c1dff577c7fa14e3342daee) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index 5ea8a06769..28eb45660e 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -1995,6 +1995,8 @@ void tst_QVariant::userType()
QVariant userVar;
userVar.setValue(data);
+ QVERIFY(QMetaType::fromName("MyType").isValid());
+ QCOMPARE(QMetaType::fromName("MyType"), QMetaType::fromType<MyType>());
QVERIFY(userVar.typeId() > QMetaType::User);
QCOMPARE(userVar.userType(), qMetaTypeId<MyType>());
QCOMPARE(userVar.typeName(), "MyType");
@@ -2118,7 +2120,15 @@ void tst_QVariant::podUserType()
pod.a = 10;
pod.b = 20;
+ // one of these two must register the type
+ // (QVariant::fromValue calls QMetaType::fromType)
QVariant pod_as_variant = QVariant::fromValue(pod);
+ QMetaType mt = QMetaType::fromType<MyTypePOD>();
+ QCOMPARE(pod_as_variant.metaType(), mt);
+ QCOMPARE(pod_as_variant.metaType().name(), mt.name());
+ QCOMPARE(QMetaType::fromName(mt.name()), mt);
+ QCOMPARE_NE(pod_as_variant.typeId(), 0);
+
MyTypePOD pod2 = qvariant_cast<MyTypePOD>(pod_as_variant);
QCOMPARE(pod.a, pod2.a);