diff options
Diffstat (limited to 'tests/auto/gui/text')
-rw-r--r-- | tests/auto/gui/text/qfont/tst_qfont.cpp | 124 | ||||
-rw-r--r-- | tests/auto/gui/text/qrawfont/tst_qrawfont.cpp | 39 |
2 files changed, 126 insertions, 37 deletions
diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index 4c88212c72..6f75a1f8bb 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -76,7 +76,8 @@ private slots: void isCopyOf(); void italicOblique(); void insertAndRemoveSubstitutions(); - void serializeSpacing(); + void serialize_data(); + void serialize(); void lastResortFont(); void styleName(); void defaultFamily_data(); @@ -534,7 +535,6 @@ void tst_QFont::insertAndRemoveSubstitutions() QVERIFY(QFont::substitutes("bogusfontfamily").isEmpty()); } - static QFont copyFont(const QFont &font1) // copy using a QDataStream { QBuffer buffer; @@ -549,29 +549,115 @@ static QFont copyFont(const QFont &font1) // copy using a QDataStream return font2; } -void tst_QFont::serializeSpacing() +Q_DECLARE_METATYPE(QDataStream::Version) + +void tst_QFont::serialize_data() { - QFont font; - QCOMPARE(font.letterSpacing(), 0.); - QCOMPARE(font.wordSpacing(), 0.); + QTest::addColumn<QFont>("font"); + // The version in which the tested feature was added. + QTest::addColumn<QDataStream::Version>("minimumStreamVersion"); + + QFont basicFont; + // Versions <= Qt 2.1 had broken point size serialization, + // so we set an integer point size. + basicFont.setPointSize(9); + + QFont font = basicFont; + QTest::newRow("defaultConstructed") << font << QDataStream::Qt_1_0; font.setLetterSpacing(QFont::AbsoluteSpacing, 105); - QCOMPARE(font.letterSpacing(), 105.); - QCOMPARE(font.letterSpacingType(), QFont::AbsoluteSpacing); - QCOMPARE(font.wordSpacing(), 0.); - QFont font2 = copyFont(font); - QCOMPARE(font2.letterSpacing(), 105.); - QCOMPARE(font2.letterSpacingType(), QFont::AbsoluteSpacing); - QCOMPARE(font2.wordSpacing(), 0.); + QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5; + font = basicFont; font.setWordSpacing(50.0); - QCOMPARE(font.letterSpacing(), 105.); - QCOMPARE(font.wordSpacing(), 50.); + QTest::newRow("wordSpacing") << font << QDataStream::Qt_4_5; + + font = basicFont; + font.setPointSize(20); + QTest::newRow("pointSize") << font << QDataStream::Qt_1_0; + + font = basicFont; + font.setPixelSize(32); + QTest::newRow("pixelSize") << font << QDataStream::Qt_3_0; + + font = basicFont; + font.setStyleHint(QFont::Monospace); + QTest::newRow("styleHint") << font << QDataStream::Qt_1_0; + + font = basicFont; + font.setStretch(4000); + QTest::newRow("stretch") << font << QDataStream::Qt_4_3; + + font = basicFont; + font.setWeight(99); + QTest::newRow("weight") << font << QDataStream::Qt_1_0; + + font = basicFont; + font.setUnderline(true); + QTest::newRow("underline") << font << QDataStream::Qt_1_0; + + font = basicFont; + font.setStrikeOut(true); + QTest::newRow("strikeOut") << font << QDataStream::Qt_1_0; + + font = basicFont; + font.setFixedPitch(true); + // This fails for versions less than this, as ignorePitch is set to false + // whenever setFixedPitch() is called, but ignorePitch is considered an + // extended bit, which were apparently not available until 4.4. + QTest::newRow("fixedPitch") << font << QDataStream::Qt_4_4; + + font = basicFont; + font.setLetterSpacing(QFont::AbsoluteSpacing, 10); + // Fails for 4.4 because letterSpacing wasn't read until 4.5. + QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5; + + font = basicFont; + font.setRawMode(true); + QTest::newRow("rawMode") << font << QDataStream::Qt_1_0; + + font = basicFont; + font.setKerning(false); + QTest::newRow("kerning") << font << QDataStream::Qt_4_0; + + font = basicFont; + font.setStyleStrategy(QFont::NoFontMerging); + // This wasn't read properly until 5.4. + QTest::newRow("styleStrategy") << font << QDataStream::Qt_5_4; + + font = basicFont; + font.setHintingPreference(QFont::PreferFullHinting); + // This wasn't read until 5.4. + QTest::newRow("hintingPreference") << font << QDataStream::Qt_5_4; + + font = basicFont; + font.setStyleName("Regular Black Condensed"); + // This wasn't read until 5.4. + QTest::newRow("styleName") << font << QDataStream::Qt_5_4; +} - QFont font3 = copyFont(font); - QCOMPARE(font3.letterSpacing(), 105.); - QCOMPARE(font3.letterSpacingType(), QFont::AbsoluteSpacing); - QCOMPARE(font3.wordSpacing(), 50.); +void tst_QFont::serialize() +{ + QFETCH(QFont, font); + QFETCH(QDataStream::Version, minimumStreamVersion); + + QDataStream stream; + const int thisVersion = stream.version(); + + for (int version = minimumStreamVersion; version <= thisVersion; ++version) { + QBuffer buffer; + buffer.open(QIODevice::WriteOnly); + stream.setDevice(&buffer); + stream.setVersion(version); + stream << font; + buffer.close(); + + buffer.open(QIODevice::ReadOnly); + QFont readFont; + stream >> readFont; + QVERIFY2(readFont == font, qPrintable(QString::fromLatin1("Fonts do not compare equal for QDataStream version ") + + QString::fromLatin1("%1:\nactual: %2\nexpected: %3").arg(version).arg(readFont.toString()).arg(font.toString()))); + } } // QFont::lastResortFont() may abort with qFatal() on QWS/QPA diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp index ae6e450301..08c7148342 100644 --- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp +++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp @@ -312,16 +312,24 @@ void tst_QRawFont::advances() bool supportsSubPixelPositions = font_d->fontEngine->supportsSubPixelPositions(); QVector<QPointF> advances = font.advancesForGlyphIndexes(glyphIndices); - for (int i=0; i<glyphIndices.size(); ++i) { -#ifdef Q_OS_WIN - // In Windows, freetype engine returns advance of 9 when full hinting is used (default) for - // some of the glyphs. - if (font_d->fontEngine->type() == QFontEngine::Freetype - && (hintingPreference == QFont::PreferFullHinting || hintingPreference == QFont::PreferDefaultHinting) - && (i == 0 || i == 5)) { - QEXPECT_FAIL("", "Advance for some glyphs is not the expected with Windows Freetype engine (9 instead of 8)", Continue); - } + + // On Windows and QNX, freetype engine returns advance of 9 for some of the glyphs + // when full hinting is used (default on Windows). + bool mayFail = false; +#if defined (Q_OS_WIN) + mayFail = font_d->fontEngine->type() == QFontEngine::Freetype + && (hintingPreference == QFont::PreferFullHinting + || hintingPreference == QFont::PreferDefaultHinting); +#elif defined(Q_OS_QNX) + mayFail = font_d->fontEngine->type() == QFontEngine::Freetype + && hintingPreference == QFont::PreferFullHinting; #endif + + for (int i = 0; i < glyphIndices.size(); ++i) { + if (mayFail && (i == 0 || i == 5)) { + QEXPECT_FAIL("", "FreeType engine reports unexpected advance " + "for some glyphs (9 instead of 8)", Continue); + } QVERIFY(qFuzzyCompare(qRound(advances.at(i).x()), 8.0)); if (supportsSubPixelPositions) QVERIFY(advances.at(i).x() > 8.0); @@ -339,16 +347,11 @@ void tst_QRawFont::advances() QVERIFY(font.advancesForGlyphIndexes(glyphIndices.constData(), advances.data(), numGlyphs)); - for (int i=0; i<glyphIndices.size(); ++i) { -#ifdef Q_OS_WIN - // In Windows, freetype engine returns advance of 9 when full hinting is used (default) for - // some of the glyphs. - if (font_d->fontEngine->type() == QFontEngine::Freetype - && (hintingPreference == QFont::PreferFullHinting || hintingPreference == QFont::PreferDefaultHinting) - && (i == 0 || i == 5)) { - QEXPECT_FAIL("", "Advance for some glyphs is not the expected with Windows Freetype engine (9 instead of 8)", Continue); + for (int i = 0; i < glyphIndices.size(); ++i) { + if (mayFail && (i == 0 || i == 5)) { + QEXPECT_FAIL("", "FreeType engine reports unexpected advance " + "for some glyphs (9 instead of 8)", Continue); } -#endif QVERIFY(qFuzzyCompare(qRound(advances.at(i).x()), 8.0)); if (supportsSubPixelPositions) QVERIFY(advances.at(i).x() > 8.0); |