diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2012-10-17 14:31:33 +0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-19 18:04:36 +0200 |
commit | 9690548113e03614c770cec44a527e6c1edce6ab (patch) | |
tree | 98f30932311f463468d5095bd9669843fb794476 /tests/auto/gui | |
parent | bdc115d9698d4f3cf5ce089dbddca75e425d3eeb (diff) |
QFont: Don't invalidate engine unless request has been changed
This makes QFont do a "light" detach when the font attributes data has been changed.
The new test clearly shows that the engine is now shared between
two font instances after changing the kerning attribute.
Change-Id: I59db822f459f02d111686dba7101b98e361fada9
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/text/qfont/qfont.pro | 1 | ||||
-rw-r--r-- | tests/auto/gui/text/qfont/tst_qfont.cpp | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qfont/qfont.pro b/tests/auto/gui/text/qfont/qfont.pro index 86178f3fa6..562294dd66 100644 --- a/tests/auto/gui/text/qfont/qfont.pro +++ b/tests/auto/gui/text/qfont/qfont.pro @@ -2,6 +2,7 @@ CONFIG += testcase CONFIG += parallel_test TARGET = tst_qfont QT += testlib +QT += core-private gui-private !contains(QT_CONFIG, no-widgets): QT += widgets SOURCES += tst_qfont.cpp diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index 287fd728ff..3fe23bf1ff 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -44,6 +44,7 @@ #include <qfont.h> +#include <private/qfont_p.h> #include <qfontdatabase.h> #include <qfontinfo.h> #include <qstringlist.h> @@ -81,6 +82,8 @@ private slots: void styleName(); void defaultFamily_data(); void defaultFamily(); + + void sharing(); }; // Testing get/set functions @@ -685,5 +688,45 @@ void tst_QFont::defaultFamily() QVERIFY2(isAcceptable, msgNotAcceptableFont(familyForHint, acceptableFamilies)); } +void tst_QFont::sharing() +{ + QFont f; + f.setStyleHint(QFont::Serif); + f.exactMatch(); // loads engine + QCOMPARE(QFontPrivate::get(f)->ref.load(), 1); + QVERIFY(QFontPrivate::get(f)->engineData); + QCOMPARE(QFontPrivate::get(f)->engineData->ref.load(), 1); + + QFont f2(f); + QVERIFY(QFontPrivate::get(f2) == QFontPrivate::get(f)); + QCOMPARE(QFontPrivate::get(f2)->ref.load(), 2); + QVERIFY(QFontPrivate::get(f2)->engineData); + QVERIFY(QFontPrivate::get(f2)->engineData == QFontPrivate::get(f)->engineData); + QCOMPARE(QFontPrivate::get(f2)->engineData->ref.load(), 1); + + f2.setKerning(!f.kerning()); + QVERIFY(QFontPrivate::get(f2) != QFontPrivate::get(f)); + QCOMPARE(QFontPrivate::get(f2)->ref.load(), 1); + QVERIFY(QFontPrivate::get(f2)->engineData); + QVERIFY(QFontPrivate::get(f2)->engineData == QFontPrivate::get(f)->engineData); + QCOMPARE(QFontPrivate::get(f2)->engineData->ref.load(), 2); + + f2 = f; + QVERIFY(QFontPrivate::get(f2) == QFontPrivate::get(f)); + QCOMPARE(QFontPrivate::get(f2)->ref.load(), 2); + QVERIFY(QFontPrivate::get(f2)->engineData); + QVERIFY(QFontPrivate::get(f2)->engineData == QFontPrivate::get(f)->engineData); + QCOMPARE(QFontPrivate::get(f2)->engineData->ref.load(), 1); + + if (f.pointSize() > 0) + f2.setPointSize(f.pointSize() * 2 / 3); + else + f2.setPixelSize(f.pixelSize() * 2 / 3); + QVERIFY(QFontPrivate::get(f2) != QFontPrivate::get(f)); + QCOMPARE(QFontPrivate::get(f2)->ref.load(), 1); + QVERIFY(!QFontPrivate::get(f2)->engineData); + QVERIFY(QFontPrivate::get(f2)->engineData != QFontPrivate::get(f)->engineData); +} + QTEST_MAIN(tst_QFont) #include "tst_qfont.moc" |