summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-02-07 12:44:03 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-03-10 10:58:03 +0100
commit761197e9d29f233dabb45d8adbed56725870348a (patch)
treeb591391ac15f50e41cca8ac09b700659f21dc229 /tests/auto
parent1ef8470c805faf39e95ee8652cf473c231471eef (diff)
Fix distribution of font properties in QTextFormat
The area reserved for font properties was too small for the properties we needed, and as a result font properties were added outside of the area and special-cased (in the case of FontLetterSpacingType) or ignored (in the case of FontStretch) by conditions that check if the property is within the designated area. We reorganize the enum values now that we can, and allocate some more space for the font properties area. Fixes: QTBUG-65345 Change-Id: I8121ff7f72102d8022c6a6d2f8ed9c35dcdbb321 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/gui/text/qtextformat/tst_qtextformat.cpp128
1 files changed, 128 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
index 4ab80bdcfe..4e5ef7c555 100644
--- a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
+++ b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
@@ -40,6 +40,10 @@
#include <qtextlayout.h>
#include <qabstracttextdocumentlayout.h>
+#ifndef QT_NO_DATASTREAM
+# include <qdatastream.h>
+#endif
+
class tst_QTextFormat : public QObject
{
Q_OBJECT
@@ -61,6 +65,10 @@ private slots:
void setFont_collection_data();
void setFont_collection();
void clearCollection();
+
+#ifndef QT_NO_DATASTREAM
+ void dataStreamCompatibility();
+#endif
};
/*! \internal
@@ -677,5 +685,125 @@ void tst_QTextFormat::clearCollection()
QCOMPARE(collection.defaultFont(), f); // kept, QTextDocument::clear or setPlainText should not reset the font set by setDefaultFont
}
+#ifndef QT_NO_DATASTREAM
+void tst_QTextFormat::dataStreamCompatibility()
+{
+ // Make sure that we are still compatible with the old values of QTextFormat::FontLetterSpacingType
+ // and QTextFormat::FontStretch, when used with earlier QDataStream versions
+ QTextCharFormat format;
+ format.setFontStretch(42);
+ format.setFontLetterSpacingType(QFont::AbsoluteSpacing);
+
+ // Sanity check
+ {
+ QMap<int, QVariant> properties = format.properties();
+ QVERIFY(properties.contains(QTextFormat::FontLetterSpacingType));
+ QVERIFY(properties.contains(QTextFormat::FontStretch));
+ QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType));
+ QVERIFY(!properties.contains(QTextFormat::OldFontStretch));
+ }
+
+ QByteArray memory;
+
+ // Current stream version
+ {
+ {
+ QBuffer buffer(&memory);
+ buffer.open(QIODevice::WriteOnly);
+
+ QDataStream stream(&buffer);
+ stream << format;
+ }
+
+ {
+ QBuffer buffer(&memory);
+ buffer.open(QIODevice::ReadOnly);
+
+ QDataStream stream(&buffer);
+
+ QTextFormat other;
+ stream >> other;
+
+ {
+ QMap<int, QVariant> properties = other.properties();
+ QVERIFY(properties.contains(QTextFormat::FontLetterSpacingType));
+ QVERIFY(properties.contains(QTextFormat::FontStretch));
+ QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType));
+ QVERIFY(!properties.contains(QTextFormat::OldFontStretch));
+ }
+ }
+
+ {
+ QBuffer buffer(&memory);
+ buffer.open(QIODevice::ReadOnly);
+
+ QDataStream stream(&buffer);
+
+ quint32 type;
+ stream >> type;
+
+ QMap<qint32, QVariant> properties;
+ stream >> properties;
+ QVERIFY(properties.contains(QTextFormat::FontLetterSpacingType));
+ QVERIFY(properties.contains(QTextFormat::FontStretch));
+ QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType));
+ QVERIFY(!properties.contains(QTextFormat::OldFontStretch));
+ }
+ }
+
+ // Qt 5.15 stream version
+ memory.clear();
+ {
+ {
+ QBuffer buffer(&memory);
+ buffer.open(QIODevice::WriteOnly);
+
+ QDataStream stream(&buffer);
+ stream.setVersion(QDataStream::Qt_5_15);
+ stream << format;
+ }
+
+ {
+ QBuffer buffer(&memory);
+ buffer.open(QIODevice::ReadOnly);
+
+ QDataStream stream(&buffer);
+ stream.setVersion(QDataStream::Qt_5_15);
+
+ QTextFormat other;
+ stream >> other;
+
+ {
+ QMap<int, QVariant> properties = other.properties();
+ QVERIFY(properties.contains(QTextFormat::FontLetterSpacingType));
+ QVERIFY(properties.contains(QTextFormat::FontStretch));
+ QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType));
+ QVERIFY(!properties.contains(QTextFormat::OldFontStretch));
+ }
+ }
+
+ {
+ QBuffer buffer(&memory);
+ buffer.open(QIODevice::ReadOnly);
+
+ QDataStream stream(&buffer);
+ stream.setVersion(QDataStream::Qt_5_15);
+
+ quint32 type;
+ stream >> type;
+
+ // Verify that old data stream still has the compatibility values
+ QMap<qint32, QVariant> properties;
+ stream >> properties;
+ QVERIFY(!properties.contains(QTextFormat::FontLetterSpacingType));
+ QVERIFY(!properties.contains(QTextFormat::FontStretch));
+ QVERIFY(properties.contains(QTextFormat::OldFontLetterSpacingType));
+ QVERIFY(properties.contains(QTextFormat::OldFontStretch));
+ }
+ }
+
+}
+#endif // QT_NO_DATASTREAM
+
QTEST_MAIN(tst_QTextFormat)
#include "tst_qtextformat.moc"