diff options
Diffstat (limited to 'tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp')
-rw-r--r-- | tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp | 92 |
1 files changed, 63 insertions, 29 deletions
diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index c78475a76f..9471c1d93f 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -43,6 +18,7 @@ private slots: void same(); void metrics(); void boundingRect(); + void boundingRect2(); void elidedText_data(); void elidedText(); void veryNarrowElidedText(); @@ -56,6 +32,10 @@ private slots: void leadingBelowLine(); void elidedMetrics(); void zeroWidthMetrics(); + void verticalMetrics_data(); + void verticalMetrics(); + void largeText_data(); + void largeText(); // QTBUG-123339 }; void tst_QFontMetrics::same() @@ -149,6 +129,21 @@ void tst_QFontMetrics::boundingRect() QVERIFY(r.top() < 0); } +void tst_QFontMetrics::boundingRect2() +{ + QFont f; + f.setPixelSize(16); + QFontMetricsF fm(f); + QString str("AVAVAVA vvvvvvvvvv fffffffff file"); + QRectF br = fm.boundingRect(str); + QRectF tbr = fm.tightBoundingRect(str); + qreal advance = fm.horizontalAdvance(str); + // Bounding rect plus bearings should be similar to advance + qreal bearings = fm.leftBearing(QChar('A')) + fm.rightBearing(QChar('e')); + QVERIFY(qAbs(br.width() + bearings - advance) < fm.averageCharWidth()/2.0); + QVERIFY(qAbs(tbr.width() + bearings - advance) < fm.averageCharWidth()/2.0); +} + void tst_QFontMetrics::elidedText_data() { QTest::addColumn<QFont>("font"); @@ -268,7 +263,7 @@ void tst_QFontMetrics::inFontUcs4() glyphs.glyphs[0] = 0; QVERIFY(engine->stringToCMap(string.constData(), string.size(), &glyphs, &glyphs.numGlyphs, - QFontEngine::GlyphIndicesOnly)); + QFontEngine::GlyphIndicesOnly) > 0); QCOMPARE(glyphs.numGlyphs, 1); QCOMPARE(glyphs.glyphs[0], uint(1)); } @@ -280,7 +275,7 @@ void tst_QFontMetrics::inFontUcs4() glyphs.glyphs[0] = 0; QVERIFY(engine->stringToCMap(string.constData(), string.size(), &glyphs, &glyphs.numGlyphs, - QFontEngine::GlyphIndicesOnly)); + QFontEngine::GlyphIndicesOnly) >= 0); QVERIFY(glyphs.glyphs[0] != 1); } } @@ -374,6 +369,45 @@ void tst_QFontMetrics::zeroWidthMetrics() QCOMPARE(fm.horizontalAdvance(string3), fm.horizontalAdvance(string4)); QCOMPARE(fm.boundingRect(string1).width(), fm.boundingRect(string2).width()); QCOMPARE(fm.boundingRect(string3).width(), fm.boundingRect(string4).width()); + QCOMPARE(fm.tightBoundingRect(string1).width(), fm.tightBoundingRect(string2).width()); + QCOMPARE(fm.tightBoundingRect(string3).width(), fm.tightBoundingRect(string4).width()); +} + +void tst_QFontMetrics::verticalMetrics_data() +{ + QTest::addColumn<QFont>("font"); + QStringList families = QFontDatabase::families(); + for (const QString &family : families) { + QFont font(family); + QTest::newRow(family.toUtf8()) << font; + } +} + +void tst_QFontMetrics::verticalMetrics() +{ + QFETCH(QFont, font); + QFontMetrics fm(font); + QVERIFY(fm.ascent() != 0 || fm.descent() != 0); +} + +void tst_QFontMetrics::largeText_data() +{ + QTest::addColumn<qsizetype>("size"); + for (int i = 1; i < 20; ++i) { + qsizetype size = qsizetype(1) << i; + QByteArray rowText = QByteArray::number(size); + QTest::newRow(rowText.constData()) << size; + } +} + +void tst_QFontMetrics::largeText() +{ + QFont font; + QFontMetrics fm(font); + QFETCH(qsizetype, size); + QString string(size, QLatin1Char('A')); + QRect boundingRect = fm.boundingRect(string); + QVERIFY(boundingRect.isValid()); } QTEST_MAIN(tst_QFontMetrics) |