From f0bf7667a9914d00c3b3510bd46bb94d573d7d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 10 Mar 2021 14:30:31 +0100 Subject: Auto-test some high-dpi env variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add auto-tests for QT_SCALE_FACTOR and QT_SCREEN_SCALE_FACTORS Change-Id: I57bffa266be910f2ba26cb1a870e09ae202fcae0 Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (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 512209ab73..339ff0ed20 100644 --- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp +++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp @@ -47,12 +47,15 @@ private: // helpers static void standardScreenDpiTestData(); private slots: void initTestCase(); + void cleanup(); void qhighdpiscaling_data(); void qhighdpiscaling(); void minimumDpr(); void noscreens(); void screenDpiAndDpr_data(); void screenDpiAndDpr(); + void environment_QT_SCALE_FACTOR(); + void environment_QT_SCREEN_SCALE_FACTORS(); void screenAt_data(); void screenAt(); void screenGeometry_data(); @@ -178,6 +181,14 @@ void tst_QHighDpi::initTestCase() #endif } +void tst_QHighDpi::cleanup() +{ + // Some test functions set environment variables. Unset them here, + // in order to avoid getting confusing follow-on errors on test failures. + qunsetenv("QT_SCALE_FACTOR"); + qunsetenv("QT_SCREEN_SCALE_FACTORS"); +} + void tst_QHighDpi::qhighdpiscaling_data() { standardScreenDpiTestData(); @@ -224,6 +235,44 @@ void tst_QHighDpi::screenDpiAndDpr() } } +void tst_QHighDpi::environment_QT_SCALE_FACTOR() +{ + qreal factor = 3.1415; + qputenv("QT_SCALE_FACTOR", QByteArray::number(factor)); + + QList dpiValues { 96, 144, 192 }; + std::unique_ptr app(createStandardOffscreenApp(dpiValues)); + int i = 0; + for (QScreen *screen : app->screens()) { + // Verify that QT_SCALE_FACTOR applies as a multiplicative factor. + qreal expextedDpr = (dpiValues[i] / standardBaseDpi) * factor; + ++i; + QCOMPARE(screen->devicePixelRatio(), expextedDpr); + QCOMPARE(screen->logicalDotsPerInch(), 96); + QWindow window(screen); + QCOMPARE(window.devicePixelRatio(), expextedDpr); + } +} + +void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS() +{ + qreal factors[] = {1, 1.5, 2}; + qputenv("QT_SCREEN_SCALE_FACTORS", "1;1.5;2"); + + 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::minimumDpr() { QList dpiValues { 40, 60, 95 }; -- cgit v1.2.3