Add auto-test for QT_USE_PHYSICAL_DPI

Test that setting QT_USE_PHYSICAL_DPI uses physical
DPI instead of logical DPI.

Change-Id: I7f89cf1af5e013454cc3d8ec3559f2719514fea3
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Morten Johan Sørvig 2021-03-12 14:49:09 +01:00
parent f0bf7667a9
commit f9f9004b40

View File

@ -56,6 +56,7 @@ private slots:
void screenDpiAndDpr();
void environment_QT_SCALE_FACTOR();
void environment_QT_SCREEN_SCALE_FACTORS();
void environment_QT_USE_PHYSICAL_DPI();
void screenAt_data();
void screenAt();
void screenGeometry_data();
@ -187,6 +188,7 @@ void tst_QHighDpi::cleanup()
// in order to avoid getting confusing follow-on errors on test failures.
qunsetenv("QT_SCALE_FACTOR");
qunsetenv("QT_SCREEN_SCALE_FACTORS");
qunsetenv("QT_USE_PHYSICAL_DPI");
}
void tst_QHighDpi::qhighdpiscaling_data()
@ -273,6 +275,31 @@ void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS()
}
}
void tst_QHighDpi::environment_QT_USE_PHYSICAL_DPI()
{
qputenv("QT_USE_PHYSICAL_DPI", "1");
QList<qreal> dpiValues { 96, 144, 192 };
std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
// Verify that the device pixel ratio is computed as physicalDpi / baseDpi.
// (which in practice uses physicalSize since this is what QPlatformScreen provides)
// The default QPlatformScreen::physicalSize() implementation (which QOffscreenScreen
// currerently uses) assumes a default DPI of 100 and calculates a fake physical size
// based on that value. Use DPI 100 here as well: if you have changed the default value
// in QPlatformScreen and get a test failure then update the value below.
const qreal platformScreenDefualtDpi = 100;
qreal expextedDpr = (platformScreenDefualtDpi / qreal(standardBaseDpi));
for (QScreen *screen : app->screens()) {
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 };