diff options
Diffstat (limited to 'tests/auto/gui/text/qfontcache/tst_qfontcache.cpp')
-rw-r--r-- | tests/auto/gui/text/qfontcache/tst_qfontcache.cpp | 76 |
1 files changed, 49 insertions, 27 deletions
diff --git a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp index 3a7eebdc64..79f24a2f0d 100644 --- a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp +++ b/tests/auto/gui/text/qfontcache/tst_qfontcache.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> @@ -47,6 +22,7 @@ private slots: void engineData(); void engineDataFamilies_data(); void engineDataFamilies(); + void threadedAccess(); void clear(); }; @@ -227,5 +203,51 @@ for (int i = 0; i < leakedEngines.size(); ++i) qWarning() << i << leakedEngines. #endif } +struct MessageHandler +{ + MessageHandler() + { + oldMessageHandler = qInstallMessageHandler(myMessageHandler); + messages.clear(); + } + ~MessageHandler() + { + qInstallMessageHandler(oldMessageHandler); + } + + inline static bool receivedMessage = false; + inline static QtMessageHandler oldMessageHandler = nullptr; + inline static QStringList messages; + static void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &text) + { + if (!text.startsWith("Populating font family aliases took")) { + receivedMessage = true; + messages += text; + } + if (oldMessageHandler) + oldMessageHandler(type, context, text); + } +}; + + +void tst_QFontCache::threadedAccess() +{ + MessageHandler messageHandler; + auto lambda = []{ + for (const auto &family : QFontDatabase::families()) { + QFont font(family); + QFontMetrics fontMetrics(font); + fontMetrics.height(); + } + }; + auto *qThread = QThread::create(lambda); + qThread->start(); + qThread->wait(); + + std::thread stdThread(lambda); + stdThread.join(); + QVERIFY2(!messageHandler.receivedMessage, qPrintable(messageHandler.messages.join('\n'))); +} + QTEST_MAIN(tst_QFontCache) #include "tst_qfontcache.moc" |