summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2021-03-10 14:30:31 +0100
committerMorten Johan Sørvig <morten.sorvig@qt.io>2021-03-15 11:49:56 +0100
commitf0bf7667a9914d00c3b3510bd46bb94d573d7d1a (patch)
tree374e964bdb386f5ad9a60197863539f143436e79 /tests/auto/gui/kernel
parent657284acbc1869f5f93b2cc6e9b7530e2e145435 (diff)
Auto-test some high-dpi env variables
Add auto-tests for QT_SCALE_FACTOR and QT_SCREEN_SCALE_FACTORS Change-Id: I57bffa266be910f2ba26cb1a870e09ae202fcae0 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.cpp49
1 files changed, 49 insertions, 0 deletions
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<qreal> dpiValues { 96, 144, 192 };
+ std::unique_ptr<QGuiApplication> 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<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::minimumDpr()
{
QList<qreal> dpiValues { 40, 60, 95 };