summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
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/gui/kernel/qguimetatype/tst_qguimetatype.cpp
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/gui/kernel/qguimetatype/tst_qguimetatype.cpp')
-rw-r--r--tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
index cca0e95c29..b2572188b9 100644
--- a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
+++ b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
@@ -49,6 +49,8 @@ private slots:
void construct();
void constructCopy_data();
void constructCopy();
+ void saveAndLoadBuiltin_data();
+ void saveAndLoadBuiltin();
};
#define FOR_EACH_GUI_METATYPE_BASE(F) \
@@ -442,5 +444,49 @@ FOR_EACH_GUI_METATYPE(RETURN_CONSTRUCT_COPY_FUNCTION)
TypeTestFunctionGetter::get(type)();
}
+template <typename T>
+struct StreamingTraits
+{
+ // Streamable by default, as currently all gui built-in types are streamable
+ enum { isStreamable = 1 };
+};
+
+void tst_QGuiMetaType::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_GUI_CLASS(ADD_METATYPE_TEST_ROW)
+#undef ADD_METATYPE_TEST_ROW
+}
+
+void tst_QGuiMetaType::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_QGuiMetaType)
#include "tst_qguimetatype.moc"