summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@qt.io>2018-08-21 15:18:53 +0200
committerJędrzej Nowacki <jedrzej.nowacki@qt.io>2018-10-03 14:48:55 +0000
commit811c2567b6938edecfb8f8fbd9eb2e4946af301c (patch)
treebb8b65c14bb44bcea54312b4b5f24732a851ffd4 /tests/auto/widgets
parentcc24fc04067f23c445c7ca54733b0870e39b7d7d (diff)
Finish qmetatype migration to type switcher
The matatype should not keep manually maintained list of stream operators. The patch adds automatic detection for all builtin types so load and save functions pick the right delegate automatically. This change exposed some existing anomalies: - char is enforced to be signed while it seems that just calling the operator directly does not have that feature. - [unsigned] long type is always upgraded to [unsigned] long long - QCborSimpleType doesn't have the data stream operators while metatype is able to stream it through casting Change-Id: I51178d6acd97d0585a6089e30ddd6acb2a29af54 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp b/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp
index 077e8de328..06522b2bd3 100644
--- a/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp
+++ b/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp
@@ -41,6 +41,8 @@ public:
private slots:
void metaObject();
+ void saveAndLoadBuiltin_data();
+ void saveAndLoadBuiltin();
};
class CustomWidget : public QWidget
@@ -68,5 +70,50 @@ void tst_QWidgetMetaType::metaObject()
QCOMPARE(QMetaType::metaObjectForType(qMetaTypeId<QSizePolicy>()), &QSizePolicy::staticMetaObject);
}
+template <typename T>
+struct StreamingTraits
+{
+ // Streamable by default, as currently all widgets built-in types are streamable
+ enum { isStreamable = 1 };
+};
+
+void tst_QWidgetMetaType::saveAndLoadBuiltin_data()
+{
+ QTest::addColumn<int>("type");
+ QTest::addColumn<bool>("isStreamable");
+
+#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
+ QTest::newRow(#RealType) << MetaTypeId << bool(StreamingTraits<RealType>::isStreamable);
+ QT_FOR_EACH_STATIC_WIDGETS_CLASS(ADD_METATYPE_TEST_ROW)
+#undef ADD_METATYPE_TEST_ROW
+}
+
+void tst_QWidgetMetaType::saveAndLoadBuiltin()
+{
+ QFETCH(int, type);
+ QFETCH(bool, isStreamable);
+
+ void *value = QMetaType::create(type);
+
+ QByteArray ba;
+ QDataStream stream(&ba, QIODevice::ReadWrite);
+ QCOMPARE(QMetaType::save(stream, type, value), isStreamable);
+ QCOMPARE(stream.status(), QDataStream::Ok);
+
+ if (isStreamable)
+ QVERIFY(QMetaType::load(stream, type, value));
+
+ stream.device()->seek(0);
+ stream.resetStatus();
+ QCOMPARE(QMetaType::load(stream, type, value), isStreamable);
+ QCOMPARE(stream.status(), QDataStream::Ok);
+
+ if (isStreamable)
+ QVERIFY(QMetaType::load(stream, type, value));
+
+ QMetaType::destroy(type, value);
+}
+
+
QTEST_MAIN(tst_QWidgetMetaType)
#include "tst_qwidgetmetatype.moc"