From b5ceba01288acee2b658ea6599abd2e55d389aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 17 Mar 2021 10:19:41 +0100 Subject: Extend QT_SCREEN_SCALE_FACTORS test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test the name=factor format and various incorrect spec strings. We expect that the screen DPI is used if the scale factor specification is incorrect. Change-Id: Ia990e70cf71e370dd2bb4b1047a101dfe9e59cb0 Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp | 53 ++++++++++++++++++------- 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'tests/auto/gui/kernel') diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp index 4082611a0a..350be874f9 100644 --- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp +++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp @@ -55,6 +55,7 @@ private slots: void screenDpiAndDpr_data(); void screenDpiAndDpr(); void environment_QT_SCALE_FACTOR(); + void environment_QT_SCREEN_SCALE_FACTORS_data(); void environment_QT_SCREEN_SCALE_FACTORS(); void environment_QT_USE_PHYSICAL_DPI(); void screenAt_data(); @@ -256,22 +257,46 @@ void tst_QHighDpi::environment_QT_SCALE_FACTOR() } } -void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS() +void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS_data() { - qreal factors[] = {1, 1.5, 2}; - qputenv("QT_SCREEN_SCALE_FACTORS", "1;1.5;2"); + QTest::addColumn>("platformScreenDpi"); // The to-be-overridden values + QTest::addColumn("environment"); + QTest::addColumn>("expectedDprValues"); + + QList platformScreenDpi { 192, 216, 240 }; + QList fromPlatformScreenDpr { 2, 2.25, 2.5 }; + QList fromEnvironmentDpr { 1, 1.5, 2 }; + + // Correct env. variable values. + QTest::newRow("list") << platformScreenDpi << QByteArray("1;1.5;2") << fromEnvironmentDpr; + QTest::newRow("names") << platformScreenDpi << QByteArray("screen#1=1.5;screen#0=1;screen#2=2") << fromEnvironmentDpr; + + // Various broken env. variable values. Should not crash, + // and should not change the DPR. + QTest::newRow("empty") << platformScreenDpi << QByteArray("") << fromPlatformScreenDpr; + QTest::newRow("bogus-1") << platformScreenDpi << QByteArray("foo=bar") << fromPlatformScreenDpr; + QTest::newRow("bogus-2") << platformScreenDpi << QByteArray("fo0==2;;=;==;=3") << fromPlatformScreenDpr; +} - QList dpiValues { 192, 216, 240 }; - std::unique_ptr app(createStandardOffscreenApp(dpiValues)); - int i = 0; - for (QScreen *screen : app->screens()) { - qreal expextedDpr = factors[i]; - ++i; - // Verify that setting QT_SCREEN_SCALE_FACTORS overrides the from-dpi DPR - QCOMPARE(screen->devicePixelRatio(), expextedDpr); - QCOMPARE(screen->logicalDotsPerInch(), 96); - QWindow window(screen); - QCOMPARE(window.devicePixelRatio(), expextedDpr); +void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS() +{ + QFETCH(QList, platformScreenDpi); + QFETCH(QByteArray, environment); + QFETCH(QList, expectedDprValues); + + // Verify that setting QT_SCREEN_SCALE_FACTORS overrides the from-platform-screen-DPI DPR. + { + qputenv("QT_SCREEN_SCALE_FACTORS", environment); + std::unique_ptr app(createStandardOffscreenApp(platformScreenDpi)); + int i = 0; + for (QScreen *screen : app->screens()) { + qreal expextedDpr = expectedDprValues[i]; + ++i; + QCOMPARE(screen->devicePixelRatio(), expextedDpr); + QCOMPARE(screen->logicalDotsPerInch(), 96); + QWindow window(screen); + QCOMPARE(window.devicePixelRatio(), expextedDpr); + } } } -- cgit v1.2.3