From ecb6327762e58a83309027da90ebb953411a264e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 30 Jul 2019 10:16:53 +0200 Subject: QTestLib: Introduce initMain() to run in main before qApp exists When running Qt autotests on a developer machine with a high resolution, failures occur due to either some widget becoming too small, some rounding fuzz appearing when Qt High DPI scaling is active, or some test taking screenshots failing to deal with device pixel ratios != 1 in the obtained pixmaps. It is not feasible to adapt all tests to pass on high resolution monitors in both modes (Qt High DPI scaling enabled/disabled). It should be possible to specify the High DPI setting per test. Previously, it was not possible to set the Qt High DPI scaling attributes since they must be applied before QApplication instantiation. Enable this by checking for the presence of a static void initMain() function on the test object and invoking it before QApplication instantiation. Prototypically use it in tst_qtimer and to turn off High DPI scaling for tst_QGL. [ChangeLog][QtTestLib] It is now possible to perform static initialization before QApplication instantiation by implementing a initMain() function in the test class. Change-Id: Idec0134b189710a14c41a451fa8445bc0c5b1cf3 Reviewed-by: Volker Hilsheimer Reviewed-by: Paul Wicking Reviewed-by: Edward Welbourne --- tests/auto/testlib/initmain/initmain.pro | 5 +++ tests/auto/testlib/initmain/tst_initmain.cpp | 56 ++++++++++++++++++++++++++++ tests/auto/testlib/testlib.pro | 1 + 3 files changed, 62 insertions(+) create mode 100644 tests/auto/testlib/initmain/initmain.pro create mode 100644 tests/auto/testlib/initmain/tst_initmain.cpp (limited to 'tests/auto/testlib') diff --git a/tests/auto/testlib/initmain/initmain.pro b/tests/auto/testlib/initmain/initmain.pro new file mode 100644 index 0000000000..4c12aba08d --- /dev/null +++ b/tests/auto/testlib/initmain/initmain.pro @@ -0,0 +1,5 @@ +CONFIG += testcase +SOURCES += tst_initmain.cpp +QT = core testlib + +TARGET = tst_initmain diff --git a/tests/auto/testlib/initmain/tst_initmain.cpp b/tests/auto/testlib/initmain/tst_initmain.cpp new file mode 100644 index 0000000000..f08f82c5ec --- /dev/null +++ b/tests/auto/testlib/initmain/tst_initmain.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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$ +** +****************************************************************************/ + + +#include +#include + +class tst_InitMain : public QObject +{ + Q_OBJECT + +public: + static void initMain() { m_initMainCalled = true; } + +private slots: + void testcase(); + +private: + static bool m_initMainCalled; +}; + +bool tst_InitMain::m_initMainCalled = false; + +void tst_InitMain::testcase() +{ + QVERIFY(m_initMainCalled); +} + +QTEST_MAIN(tst_InitMain) + +#include "tst_initmain.moc" diff --git a/tests/auto/testlib/testlib.pro b/tests/auto/testlib/testlib.pro index 587c76a189..55f1f9b87b 100644 --- a/tests/auto/testlib/testlib.pro +++ b/tests/auto/testlib/testlib.pro @@ -1,5 +1,6 @@ TEMPLATE = subdirs SUBDIRS = \ + initmain \ outformat \ qsignalspy \ selftests \ -- cgit v1.2.3