diff options
Diffstat (limited to 'tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp')
-rw-r--r-- | tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp | 94 |
1 files changed, 52 insertions, 42 deletions
diff --git a/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp b/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp index 3b5a9387ab..abb9262288 100644 --- a/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp +++ b/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp @@ -1,34 +1,10 @@ -/**************************************************************************** -** -** 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> #include <QSignalSpy> +#include <QFontDatabase> #include <qfontcombobox.h> @@ -49,6 +25,7 @@ private slots: void writingSystem_data(); void writingSystem(); void currentFontChanged(); + void emptyFont(); }; // Subclass that exposes the protected functions. @@ -100,7 +77,7 @@ void tst_QFontComboBox::currentFont_data() if (!QFontDatabase::isPrivateFamily(defaultFont.family())) QTest::newRow("default2") << defaultFont; QStringList list = QFontDatabase::families(); - for (int i = 0; i < list.count(); ++i) { + for (int i = 0; i < list.size(); ++i) { QFont f = QFont(QStringList{QFontInfo(QFont(list.at(i))).family()}); if (!QFontDatabase::isPrivateFamily(f.families().first())) QTest::newRow(qPrintable(list.at(i))) << f; @@ -128,7 +105,7 @@ void tst_QFontComboBox::currentFont() if (oldCurrentFont != box.currentFont()) { //the signal may be emit twice if there is a foundry into brackets - QCOMPARE(spy0.count(),1); + QCOMPARE(spy0.size(),1); } } @@ -178,7 +155,7 @@ void tst_QFontComboBox::fontFilters() if((fontFilters & spacingMask) == spacingMask) fontFilters &= ~spacingMask; - for (int i = 0; i < list.count(); ++i) { + for (int i = 0; i < list.size(); ++i) { if (QFontDatabase::isPrivateFamily(list[i])) continue; if (fontFilters & QFontComboBox::ScalableFonts) { @@ -203,7 +180,7 @@ void tst_QFontComboBox::fontFilters() if (c == 0) QCOMPARE(box.currentFont(), QFont()); - QCOMPARE(spy0.count(), (currentFont != box.currentFont()) ? 1 : 0); + QCOMPARE(spy0.size(), (currentFont != box.currentFont()) ? 1 : 0); } // public QSize sizeHint() const @@ -244,36 +221,69 @@ void tst_QFontComboBox::writingSystem() QCOMPARE(box.writingSystem(), writingSystem); QStringList list = QFontDatabase::families(writingSystem); - int c = list.count(); - for (int i = 0; i < list.count(); ++i) { + int c = list.size(); + for (int i = 0; i < list.size(); ++i) { if (QFontDatabase::isPrivateFamily(list[i])) c--; } QCOMPARE(box.model()->rowCount(), c); - if (list.count() == 0) + if (list.size() == 0) QCOMPARE(box.currentFont(), QFont()); - QCOMPARE(spy0.count(), (currentFont != box.currentFont()) ? 1 : 0); + QCOMPARE(spy0.size(), (currentFont != box.currentFont()) ? 1 : 0); } // protected void currentFontChanged(QFont const& f) void tst_QFontComboBox::currentFontChanged() { - SubQFontComboBox box; - QSignalSpy spy0(&box, SIGNAL(currentFontChanged(QFont))); + // The absence of this file does not affect the test results + QFontDatabase::addApplicationFont("ArianaVioleta-dz2K.ttf"); - if (box.model()->rowCount() > 2) { - QTest::keyPress(&box, Qt::Key_Down); - QCOMPARE(spy0.count(), 1); + SubQFontComboBox *box = new SubQFontComboBox; + QSignalSpy spy0(box, SIGNAL(currentFontChanged(QFont))); + + if (box->model()->rowCount() > 2) { + QTest::keyPress(box, Qt::Key_Down); + QCOMPARE(spy0.size(), 1); QFont f( "Sans Serif" ); - box.setCurrentFont(f); - QCOMPARE(spy0.count(), 2); + box->setCurrentFont(f); + QCOMPARE(spy0.size(), 2); } else qWarning("Not enough fonts installed on test system. Consider adding some"); } +void tst_QFontComboBox::emptyFont() +{ + QFontComboBox fontCB; + if (fontCB.count() < 2) + QSKIP("Not enough fonts on system to run test."); + + QFont font; + font.setFamilies(QStringList()); + + // Due to QTBUG-98341, we need to find an index in the family list + // which does not match the default index for the empty font, otherwise + // the font selection will not be properly updated. + { + QFontInfo fi(font); + QStringList families = QFontDatabase::families(); + int index = families.indexOf(fi.family()); + if (index < 0) + index = 0; + if (index > 0) + index--; + else + index++; + + fontCB.setCurrentIndex(index); + } + + fontCB.setCurrentFont(font); + QVERIFY(!fontCB.currentFont().families().isEmpty()); +} + QTEST_MAIN(tst_QFontComboBox) #include "tst_qfontcombobox.moc" |