summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qfontdatabase
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-08-08 15:53:31 +0200
committerJake Petroules <jake.petroules@qt.io>2016-10-16 00:11:13 +0000
commit90fe2c64f5edf299783b2a9cf695a1a417a0361a (patch)
tree5ada7e425293d18be09a78d2ebd90cf0b1f93cd2 /tests/auto/gui/text/qfontdatabase
parentd976cee1e524006a3c813c23d46fd0404d1cac08 (diff)
Make self-contained test of condensed font matching and width
Fixes the test for width of condensed fonts so it doesn't depend on the presence of the Liberation font on the system, and adds another test that condensed sub-families can be matched consistently. The latter will however not work on Windows until QTBUG-53458 is solved. Task-number: QTBUG-51335. Change-Id: Id6d046274fa21b2dce0ad6b32dce7f1c8a92a4f4 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'tests/auto/gui/text/qfontdatabase')
-rw-r--r--tests/auto/gui/text/qfontdatabase/qfontdatabase.pro4
-rw-r--r--tests/auto/gui/text/qfontdatabase/testdata.qrc2
-rw-r--r--tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp69
3 files changed, 57 insertions, 18 deletions
diff --git a/tests/auto/gui/text/qfontdatabase/qfontdatabase.pro b/tests/auto/gui/text/qfontdatabase/qfontdatabase.pro
index 8a08cdc182..9d357a35f2 100644
--- a/tests/auto/gui/text/qfontdatabase/qfontdatabase.pro
+++ b/tests/auto/gui/text/qfontdatabase/qfontdatabase.pro
@@ -4,7 +4,5 @@ SOURCES += tst_qfontdatabase.cpp
QT += testlib core-private gui-private
TESTDATA += LED_REAL.TTF
-android {
- RESOURCES += testdata.qrc
-}
+RESOURCES += testdata.qrc
diff --git a/tests/auto/gui/text/qfontdatabase/testdata.qrc b/tests/auto/gui/text/qfontdatabase/testdata.qrc
index 8a8670bf17..81a0b5b0bf 100644
--- a/tests/auto/gui/text/qfontdatabase/testdata.qrc
+++ b/tests/auto/gui/text/qfontdatabase/testdata.qrc
@@ -1,5 +1,7 @@
<RCC>
<qresource prefix="/">
<file>LED_REAL.TTF</file>
+ <file alias="testfont.ttf">../../../shared/resources/testfont.ttf</file>
+ <file alias="testfont_condensed.ttf">../../../shared/resources/testfont_condensed.ttf</file>
</qresource>
</RCC>
diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
index f71d808390..c53792da99 100644
--- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
+++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
@@ -64,20 +64,27 @@ private slots:
void aliases();
void fallbackFonts();
- void liberationFont();
+ void condensedFontWidth();
+ void condensedFontMatching();
private:
- const QString m_testFont;
+ QString m_ledFont;
+ QString m_testFont;
+ QString m_testFontCondensed;
};
tst_QFontDatabase::tst_QFontDatabase()
- : m_testFont(QFINDTESTDATA("LED_REAL.TTF"))
{
}
void tst_QFontDatabase::initTestCase()
{
+ m_ledFont = QFINDTESTDATA("LED_REAL.TTF");
+ m_testFont = QFINDTESTDATA("testfont.ttf");
+ m_testFontCondensed = QFINDTESTDATA("testfont_condensed.ttf");
+ QVERIFY(!m_ledFont.isEmpty());
QVERIFY(!m_testFont.isEmpty());
+ QVERIFY(!m_testFontCondensed.isEmpty());
}
void tst_QFontDatabase::styles_data()
@@ -209,13 +216,13 @@ void tst_QFontDatabase::addAppFont()
int id;
if (useMemoryFont) {
- QFile fontfile(m_testFont);
+ QFile fontfile(m_ledFont);
fontfile.open(QIODevice::ReadOnly);
QByteArray fontdata = fontfile.readAll();
QVERIFY(!fontdata.isEmpty());
id = QFontDatabase::addApplicationFontFromData(fontdata);
} else {
- id = QFontDatabase::addApplicationFont(m_testFont);
+ id = QFontDatabase::addApplicationFont(m_ledFont);
}
#if defined(Q_OS_HPUX) && defined(QT_NO_FONTCONFIG)
// Documentation says that X11 systems that don't have fontconfig
@@ -277,22 +284,54 @@ void tst_QFontDatabase::fallbackFonts()
}
}
-void tst_QFontDatabase::liberationFont()
+static QString testString()
{
- QString libSans("Liberation Sans");
- QString libSansNarrow("Liberation Sans Narrow");
+ return QStringLiteral("foo bar");
+}
+void tst_QFontDatabase::condensedFontWidth()
+{
QFontDatabase db;
- if (!db.hasFamily(libSans) || !db.hasFamily(libSansNarrow))
- QSKIP("Requires Liberation Sans installed");
+ QFontDatabase::addApplicationFont(m_testFont);
+ QFontDatabase::addApplicationFont(m_testFontCondensed);
+
+ QVERIFY(db.hasFamily("QtBidiTestFont"));
+ if (!db.hasFamily("QtBidiTestFontCondensed"))
+ QSKIP("This platform doesn't support font sub-family names (QTBUG-55625)");
- QFont fontLS(libSans);
- QFont fontLSN(libSansNarrow);
+ // Test we really get a condensed font, and a not renormalized one (QTBUG-48043):
+ QFont testFont("QtBidiTestFont");
+ QFont testFontCondensed("QtBidiTestFontCondensed");
+ QFontMetrics fmTF(testFont);
+ QFontMetrics fmTFC(testFontCondensed);
+ QVERIFY(fmTF.width(testString()) > fmTFC.width(testString()));
- QFontMetrics fmLS(fontLS);
- QFontMetrics fmLSN(fontLSN);
+}
- QVERIFY(fmLS.width(QStringLiteral("foo bar")) > fmLSN.width(QStringLiteral("foo bar")));
+void tst_QFontDatabase::condensedFontMatching()
+{
+ QFontDatabase db;
+ QFontDatabase::removeAllApplicationFonts();
+ QFontDatabase::addApplicationFont(m_testFontCondensed);
+ if (!db.hasFamily("QtBidiTestFont"))
+ QSKIP("This platform doesn't support preferred font family names (QTBUG-53478)");
+ QFontDatabase::addApplicationFont(m_testFont);
+
+ // Test we correctly get the condensed font using different font matching methods:
+ QFont tfcByStretch("QtBidiTestFont");
+ tfcByStretch.setStretch(QFont::Condensed);
+ QFont tfcByStyleName("QtBidiTestFont");
+ tfcByStyleName.setStyleName("Condensed");
+
+ QCOMPARE(QFontMetrics(tfcByStretch).width(testString()),
+ QFontMetrics(tfcByStyleName).width(testString()));
+
+ if (!db.hasFamily("QtBidiTestFontCondensed"))
+ QSKIP("This platform doesn't support font sub-family names (QTBUG-55625)");
+
+ QFont tfcBySubfamilyName("QtBidiTestFontCondensed");
+ QCOMPARE(QFontMetrics(tfcByStyleName).width(testString()),
+ QFontMetrics(tfcBySubfamilyName).width(testString()));
}
QTEST_MAIN(tst_QFontDatabase)