From 3a1773dd7625e1bd727c5e851b8a84125fddb9e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 23 Dec 2020 11:53:14 +0100 Subject: High-DPI: Test application startup with no screens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Initialize the offscreen platform plugin with no screens, create QGuiApplication object. Not much of the high-dpi related Qt API can be used in this configuration, but at least Qt should not crash on startup. Task-number: QTBUG-71034 Change-Id: I6620843c3bd8b692c5c2419b1ba290e16175ba5b Reviewed-by: Morten Johan Sørvig --- tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp index 13cdce6b12..09bf8439c8 100644 --- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp +++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp @@ -43,11 +43,13 @@ private: // helpers QJsonArray createStandardScreens(const QList &dpiValues); QGuiApplication *createOffscreenApplication(const QByteArray &jsonConfig); QGuiApplication *createStandardOffscreenApp(const QList &dpiValues); + QGuiApplication *createStandardOffscreenApp(const QJsonArray &screens); static void standardScreenDpiTestData(); private slots: void initTestCase(); void qhighdpiscaling_data(); void qhighdpiscaling(); + void noscreens(); void screenDpiAndDpr_data(); void screenDpiAndDpr(); void screenAt_data(); @@ -142,6 +144,11 @@ QGuiApplication *tst_QHighDpi::createOffscreenApplication(const QByteArray &json QGuiApplication *tst_QHighDpi::createStandardOffscreenApp(const QList &dpiValues) { QJsonArray screens = createStandardScreens(dpiValues); + return createStandardOffscreenApp(screens); +} + +QGuiApplication *tst_QHighDpi::createStandardOffscreenApp(const QJsonArray &screens) +{ QJsonObject config { {"synchronousWindowSystemEvents", true}, {"windowFrameMargins", false}, @@ -216,6 +223,15 @@ void tst_QHighDpi::screenDpiAndDpr() } } +void tst_QHighDpi::noscreens() +{ + // Create application object with a no-screens configuration (should not crash) + QJsonArray noScreens; + std::unique_ptr app(createStandardOffscreenApp(noScreens)); + + QCOMPARE(qApp->devicePixelRatio(), 1); +} + void tst_QHighDpi::screenAt_data() { standardScreenDpiTestData(); -- cgit v1.2.3