diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-03-17 10:19:41 +0100 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-05-03 13:33:43 +0200 |
commit | b5ceba01288acee2b658ea6599abd2e55d389aa4 (patch) | |
tree | aeb6a323c2f3108511ce5db0290d88714f9f50b6 /tests/auto/gui/kernel | |
parent | 51e2a64ed9360c8e889726c3fbaf649a4d260e0d (diff) |
Extend QT_SCREEN_SCALE_FACTORS test
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ø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r-- | tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp | 53 |
1 files changed, 39 insertions, 14 deletions
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<QList<qreal>>("platformScreenDpi"); // The to-be-overridden values + QTest::addColumn<QByteArray>("environment"); + QTest::addColumn<QList<qreal>>("expectedDprValues"); + + QList<qreal> platformScreenDpi { 192, 216, 240 }; + QList<qreal> fromPlatformScreenDpr { 2, 2.25, 2.5 }; + QList<qreal> 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<qreal> dpiValues { 192, 216, 240 }; - std::unique_ptr<QGuiApplication> 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<qreal>, platformScreenDpi); + QFETCH(QByteArray, environment); + QFETCH(QList<qreal>, expectedDprValues); + + // Verify that setting QT_SCREEN_SCALE_FACTORS overrides the from-platform-screen-DPI DPR. + { + qputenv("QT_SCREEN_SCALE_FACTORS", environment); + std::unique_ptr<QGuiApplication> 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); + } } } |