summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qfont
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/text/qfont')
-rw-r--r--tests/auto/gui/text/qfont/BLACKLIST2
-rw-r--r--tests/auto/gui/text/qfont/CMakeLists.txt35
-rw-r--r--tests/auto/gui/text/qfont/testfont.qrc6
-rw-r--r--tests/auto/gui/text/qfont/tst_qfont.cpp134
4 files changed, 118 insertions, 59 deletions
diff --git a/tests/auto/gui/text/qfont/BLACKLIST b/tests/auto/gui/text/qfont/BLACKLIST
index 3629f1fee6..f85d8ceebb 100644
--- a/tests/auto/gui/text/qfont/BLACKLIST
+++ b/tests/auto/gui/text/qfont/BLACKLIST
@@ -1,10 +1,8 @@
[defaultFamily:cursive]
-ubuntu-20.04
centos
b2qt
rhel
[defaultFamily:fantasy]
-ubuntu-20.04
centos
b2qt
rhel
diff --git a/tests/auto/gui/text/qfont/CMakeLists.txt b/tests/auto/gui/text/qfont/CMakeLists.txt
index 6e0583bc30..88ae9959e4 100644
--- a/tests/auto/gui/text/qfont/CMakeLists.txt
+++ b/tests/auto/gui/text/qfont/CMakeLists.txt
@@ -1,18 +1,15 @@
-# Generated from qfont.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qfont Test:
#####################################################################
-qt_internal_add_test(tst_qfont
- SOURCES
- tst_qfont.cpp
- PUBLIC_LIBRARIES
- Qt::CorePrivate
- Qt::Gui
- Qt::GuiPrivate
- Qt::TestPrivate
-)
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qfont LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
# Resources:
set(testfont_resource_files
@@ -20,18 +17,22 @@ set(testfont_resource_files
"weirdfont.otf"
)
-qt_internal_add_resource(tst_qfont "testfont"
- PREFIX
- "/"
- FILES
- ${testfont_resource_files}
+qt_internal_add_test(tst_qfont
+ SOURCES
+ tst_qfont.cpp
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::GuiPrivate
+ Qt::TestPrivate
+ TESTDATA ${testfont_resource_files}
+ BUILTIN_TESTDATA
)
-
## Scopes:
#####################################################################
qt_internal_extend_target(tst_qfont CONDITION TARGET Qt::Widgets
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Widgets
)
diff --git a/tests/auto/gui/text/qfont/testfont.qrc b/tests/auto/gui/text/qfont/testfont.qrc
deleted file mode 100644
index 7a7b66f984..0000000000
--- a/tests/auto/gui/text/qfont/testfont.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>weirdfont.otf</file>
- <file>datastream.515</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp
index e0ece40bdf..5426d7b117 100644
--- a/tests/auto/gui/text/qfont/tst_qfont.cpp
+++ b/tests/auto/gui/text/qfont/tst_qfont.cpp
@@ -1,30 +1,7 @@
-/****************************************************************************
-**
-** 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
+
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include <QTest>
#include <QBuffer>
@@ -44,6 +21,9 @@
#endif
#include <qlist.h>
#include <QtTest/private/qemulationdetector_p.h>
+#include <private/qcomparisontesthelper_p.h>
+
+using namespace Qt::StringLiterals;
class tst_QFont : public QObject
{
@@ -79,6 +59,9 @@ private slots:
void setFamilies();
void setFamiliesAndFamily_data();
void setFamiliesAndFamily();
+ void featureAccessors();
+ void tagCompares_data();
+ void tagCompares();
};
// Testing get/set functions
@@ -175,7 +158,7 @@ void tst_QFont::italicOblique()
continue;
}
QFont f = QFontDatabase::font(family, style, 12);
- QVERIFY(f.italic());
+ QVERIFY2(f.italic(), qPrintable(QString::asprintf("Failed for font \"%ls\"", qUtf16Printable(f.family()))));
}
}
}
@@ -382,15 +365,15 @@ void tst_QFont::insertAndRemoveSubstitutions()
// inserting Foo
QFont::insertSubstitution("BogusFontFamily", "Foo");
- QCOMPARE(QFont::substitutes("BogusFontFamily").count(), 1);
- QCOMPARE(QFont::substitutes("bogusfontfamily").count(), 1);
+ QCOMPARE(QFont::substitutes("BogusFontFamily").size(), 1);
+ QCOMPARE(QFont::substitutes("bogusfontfamily").size(), 1);
// inserting Bar and Baz
QStringList moreFonts;
moreFonts << "Bar" << "Baz";
QFont::insertSubstitutions("BogusFontFamily", moreFonts);
- QCOMPARE(QFont::substitutes("BogusFontFamily").count(), 3);
- QCOMPARE(QFont::substitutes("bogusfontfamily").count(), 3);
+ QCOMPARE(QFont::substitutes("BogusFontFamily").size(), 3);
+ QCOMPARE(QFont::substitutes("bogusfontfamily").size(), 3);
QFont::removeSubstitutions("BogusFontFamily");
// make sure it is empty again
@@ -417,7 +400,7 @@ void tst_QFont::serialize_data()
QTest::newRow("defaultConstructed") << font << QDataStream::Qt_1_0;
font.setLetterSpacing(QFont::AbsoluteSpacing, 105);
- QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5;
+ QTest::newRow("letterSpacing=105") << font << QDataStream::Qt_4_5;
font = basicFont;
font.setWordSpacing(50.0);
@@ -461,7 +444,7 @@ void tst_QFont::serialize_data()
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;
+ QTest::newRow("letterSpacing=10") << font << QDataStream::Qt_4_5;
font = basicFont;
font.setKerning(false);
@@ -614,6 +597,11 @@ void tst_QFont::defaultFamily()
break;
}
}
+
+#if defined(Q_OS_UNIX) && defined(QT_NO_FONTCONFIG)
+ QSKIP("This platform does not support checking for default font acceptability");
+#endif
+
#ifdef Q_PROCESSOR_ARM_32
if (QTestPrivate::isRunningArmOnX86())
QEXPECT_FAIL("", "Fails on ARMv7 QEMU (QTQAINFRA-4127)", Continue);
@@ -861,5 +849,83 @@ void tst_QFont::setFamiliesAndFamily()
QFontDatabase::removeApplicationFont(weirdFontId);
}
+void tst_QFont::featureAccessors()
+{
+ const QFont::Tag abcdTag("abcd");
+ QCOMPARE(abcdTag.toString(), "abcd");
+ QVERIFY(abcdTag.isValid());
+
+ QFont font;
+ QVERIFY(font.featureTags().isEmpty());
+ font.setFeature("abcd", 0xc0ffee);
+
+ QVERIFY(font.isFeatureSet(abcdTag));
+ QVERIFY(!font.isFeatureSet("bcde"));
+ QCOMPARE(font.featureTags().size(), 1);
+ QCOMPARE(font.featureTags().first(), abcdTag);
+ QCOMPARE(font.featureTags().first(), "abcd");
+ QCOMPARE(font.featureValue(abcdTag), 0xc0ffeeU);
+ QCOMPARE(font.featureValue("bcde"), 0U);
+ font.setFeature(abcdTag, 0xf00d);
+ QCOMPARE(font.featureTags().size(), 1);
+ QCOMPARE(font.featureValue(abcdTag), 0xf00dU);
+
+ QFont::Tag invalidTag;
+ QVERIFY(!invalidTag.isValid());
+ font.setFeature(invalidTag, 0xcaca0);
+ QVERIFY(!font.isFeatureSet(invalidTag));
+ QCOMPARE(font.featureTags().size(), 1);
+ QFont font2 = font;
+
+ font.unsetFeature("abcd");
+ QVERIFY(!font.isFeatureSet("abcd"));
+ QVERIFY(font.featureTags().isEmpty());
+
+ QVERIFY(font2.isFeatureSet("abcd"));
+ font2.clearFeatures();
+ QVERIFY(font.featureTags().isEmpty());
+
+ // various constructor compile tests
+ QFont::Tag tag;
+ tag = QFont::Tag("1234");
+ QVERIFY(QFont::Tag::fromString(QByteArray("abcd")));
+ QVERIFY(QFont::Tag::fromString(u"frac"_s));
+
+ // named constructors with invalid input
+ QTest::ignoreMessage(QtWarningMsg, "The tag name must be exactly 4 characters long!");
+ QVERIFY(!QFont::Tag::fromString(u"fraction"_s));
+ QVERIFY(!QFont::Tag::fromValue(0));
+ QVERIFY(QFont::Tag::fromValue(abcdTag.value()));
+
+ enum Features {
+ Frac = QFont::Tag("frac").value()
+ };
+}
+
+void tst_QFont::tagCompares_data()
+{
+ QTestPrivate::testAllComparisonOperatorsCompile<QFont::Tag>();
+
+ QTest::addColumn<QFont::Tag>("lhs");
+ QTest::addColumn<QFont::Tag>("rhs");
+ QTest::addColumn<Qt::strong_ordering>("expectedOrder");
+
+ auto row = [](QFont::Tag left, QFont::Tag right) {
+ QTest::addRow("%s<=>%s", left.toString().constData(), right.toString().constData())
+ << left << right << Qt::compareThreeWay(left.value(), right.value());
+ };
+ row("frac", "wght");
+}
+
+void tst_QFont::tagCompares()
+{
+ QFETCH(QFont::Tag, lhs);
+ QFETCH(QFont::Tag, rhs);
+ QFETCH(Qt::strong_ordering, expectedOrder);
+
+ QVERIFY(comparesEqual(lhs, lhs));
+ QCOMPARE(compareThreeWay(lhs, rhs), expectedOrder);
+}
+
QTEST_MAIN(tst_QFont)
#include "tst_qfont.moc"