Make tst_qwidget_window pass on High-DPI screens (Windows)

Use a fuzz check (cf 6309062722) and a minimum
size similar to tst_qwidget to make the test pass on large monitors with or
without active scaling.

Change-Id: I5a9e28e38e1d007057894c349c94f0e6fe12009c
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Friedemann Kleint 2019-05-09 15:48:37 +02:00
parent e72e5aa83a
commit b88be04519

View File

@ -54,12 +54,25 @@
using namespace QTestPrivate; using namespace QTestPrivate;
// Compare a window position that may go through scaling in the platform plugin with fuzz.
static inline bool qFuzzyCompareWindowPosition(const QPoint &p1, const QPoint p2, int fuzz)
{
return (p1 - p2).manhattanLength() <= fuzz;
}
static QString msgPointMismatch(const QPoint &p1, const QPoint p2)
{
QString result;
QDebug(&result) << p1 << "!=" << p2 << ", manhattanLength=" << (p1 - p2).manhattanLength();
return result;
}
class tst_QWidget_window : public QObject class tst_QWidget_window : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
tst_QWidget_window(){}; tst_QWidget_window();
public slots: public slots:
void initTestCase(); void initTestCase();
@ -110,8 +123,20 @@ private slots:
void nativeShow(); void nativeShow();
void QTBUG_56277_resize_on_showEvent(); void QTBUG_56277_resize_on_showEvent();
private:
QSize m_testWidgetSize;
const int m_fuzz;
}; };
tst_QWidget_window::tst_QWidget_window() :
m_fuzz(int(QHighDpiScaling::factor(QGuiApplication::primaryScreen())))
{
const int screenWidth = QGuiApplication::primaryScreen()->geometry().width();
const int width = qMax(200, 100 * ((screenWidth + 500) / 1000));
m_testWidgetSize = QSize(width, width);
}
void tst_QWidget_window::initTestCase() void tst_QWidget_window::initTestCase()
{ {
} }
@ -162,65 +187,65 @@ void tst_QWidget_window::tst_min_max_size()
void tst_QWidget_window::tst_move_show() void tst_QWidget_window::tst_move_show()
{ {
QWidget w; QWidget w;
w.move(100, 100); const QPoint pos(100, 100);
w.move(pos);
w.show(); w.show();
#ifdef Q_OS_WINRT #ifdef Q_OS_WINRT
QEXPECT_FAIL("", "Winrt does not support move", Abort); QEXPECT_FAIL("", "Winrt does not support move", Abort);
#endif #endif
QCOMPARE(w.pos(), QPoint(100, 100)); QVERIFY2(qFuzzyCompareWindowPosition(w.pos(), pos, m_fuzz),
// QCoreApplication::processEvents(QEventLoop::AllEvents, 3000); qPrintable(msgPointMismatch(w.pos(), pos)));
} }
void tst_QWidget_window::tst_show_move() void tst_QWidget_window::tst_show_move()
{ {
QWidget w; QWidget w;
w.show(); w.show();
w.move(100, 100); const QPoint pos(100, 100);
QCOMPARE(w.pos(), QPoint(100, 100)); w.move(pos);
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); QVERIFY2(qFuzzyCompareWindowPosition(w.pos(), pos, m_fuzz),
qPrintable(msgPointMismatch(w.pos(), pos)));
} }
void tst_QWidget_window::tst_show_move_hide_show() void tst_QWidget_window::tst_show_move_hide_show()
{ {
QWidget w; QWidget w;
w.show(); w.show();
w.move(100, 100); const QPoint pos(100, 100);
w.move(pos);
w.hide(); w.hide();
w.show(); w.show();
QCOMPARE(w.pos(), QPoint(100, 100)); QVERIFY2(qFuzzyCompareWindowPosition(w.pos(), pos, m_fuzz),
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); qPrintable(msgPointMismatch(w.pos(), pos)));
} }
void tst_QWidget_window::tst_resize_show() void tst_QWidget_window::tst_resize_show()
{ {
QWidget w; QWidget w;
w.resize(200, 200); w.resize(m_testWidgetSize);
w.show(); w.show();
#ifdef Q_OS_WINRT #ifdef Q_OS_WINRT
QEXPECT_FAIL("", "Winrt does not support resize", Abort); QEXPECT_FAIL("", "Winrt does not support resize", Abort);
#endif #endif
QCOMPARE(w.size(), QSize(200, 200)); QCOMPARE(w.size(), m_testWidgetSize);
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
} }
void tst_QWidget_window::tst_show_resize() void tst_QWidget_window::tst_show_resize()
{ {
QWidget w; QWidget w;
w.show(); w.show();
w.resize(200, 200); w.resize(m_testWidgetSize);
QCOMPARE(w.size(), QSize(200, 200)); QCOMPARE(w.size(), m_testWidgetSize);
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
} }
void tst_QWidget_window::tst_show_resize_hide_show() void tst_QWidget_window::tst_show_resize_hide_show()
{ {
QWidget w; QWidget w;
w.show(); w.show();
w.resize(200, 200); w.resize(m_testWidgetSize);
w.hide(); w.hide();
w.show(); w.show();
QCOMPARE(w.size(), QSize(200, 200)); QCOMPARE(w.size(), m_testWidgetSize);
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
} }
class PaintTestWidget : public QWidget class PaintTestWidget : public QWidget
@ -857,7 +882,7 @@ void tst_QWidget_window::tst_updateWinId_QTBUG40681()
lbl->setAttribute(Qt::WA_NativeWindow); lbl->setAttribute(Qt::WA_NativeWindow);
lbl->setObjectName("label1"); lbl->setObjectName("label1");
vl->addWidget(lbl); vl->addWidget(lbl);
w.setMinimumWidth(200); w.setMinimumWidth(m_testWidgetSize.width());
w.show(); w.show();
@ -880,6 +905,7 @@ void tst_QWidget_window::tst_updateWinId_QTBUG40681()
void tst_QWidget_window::tst_recreateWindow_QTBUG40817() void tst_QWidget_window::tst_recreateWindow_QTBUG40817()
{ {
QTabWidget tab; QTabWidget tab;
tab.setMinimumWidth(m_testWidgetSize.width());
QWidget *w = new QWidget; QWidget *w = new QWidget;
tab.addTab(w, "Tab1"); tab.addTab(w, "Tab1");
@ -946,7 +972,7 @@ void tst_QWidget_window::tst_resize_count()
resize.resizeCount = 0; resize.resizeCount = 0;
ResizeWidget child(&resize); ResizeWidget child(&resize);
child.resize(200,200); child.resize(m_testWidgetSize);
child.winId(); child.winId();
child.show(); child.show();
QVERIFY(QTest::qWaitForWindowExposed(&child)); QVERIFY(QTest::qWaitForWindowExposed(&child));
@ -963,7 +989,7 @@ void tst_QWidget_window::tst_resize_count()
{ {
ResizeWidget parent; ResizeWidget parent;
ResizeWidget child(&parent); ResizeWidget child(&parent);
child.resize(200,200); child.resize(m_testWidgetSize);
child.winId(); child.winId();
parent.show(); parent.show();
QVERIFY(QTest::qWaitForWindowExposed(&parent)); QVERIFY(QTest::qWaitForWindowExposed(&parent));
@ -1076,6 +1102,7 @@ void tst_QWidget_window::QTBUG_50561_QCocoaBackingStore_paintDevice_crash()
ApplicationStateSaver as; ApplicationStateSaver as;
QMainWindow w; QMainWindow w;
w.setMinimumWidth(m_testWidgetSize.width());
w.addToolBar(new QToolBar(&w)); w.addToolBar(new QToolBar(&w));
w.show(); w.show();
QVERIFY(QTest::qWaitForWindowExposed(&w)); QVERIFY(QTest::qWaitForWindowExposed(&w));