From b6bcf01b81626b966a93ddd4928059f4cb3e656a Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Wed, 15 Sep 2021 16:39:31 +0200 Subject: [PATCH] tests/xcb: move xrandr process call to a function Change-Id: I4dab0a878a93fa2c3d0af80883b8e2198c72633c Reviewed-by: Shawn Rutledge --- .../qscreen_xrandr/tst_qscreen_xrandr.cpp | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/tests/manual/qscreen_xrandr/tst_qscreen_xrandr.cpp b/tests/manual/qscreen_xrandr/tst_qscreen_xrandr.cpp index 89b418cc1d..9eeba585c9 100644 --- a/tests/manual/qscreen_xrandr/tst_qscreen_xrandr.cpp +++ b/tests/manual/qscreen_xrandr/tst_qscreen_xrandr.cpp @@ -41,6 +41,9 @@ class tst_QScreen_Xrandr: public QObject private slots: void xrandr_15_merge_and_unmerge(); void xrandr_15_scale(); + +private: + void xrandr_process(const QStringList &arguments = {}); }; // this test requires an X11 desktop with at least two screens @@ -66,13 +69,9 @@ void tst_QScreen_Xrandr::xrandr_15_merge_and_unmerge() // combine the first two screens into one monitor // e.g. "xrandr --setmonitor Qt-merged auto eDP,HDMI-0" - QString prog1 = "xrandr"; - QStringList args1; - args1 << "--setmonitor" << "Qt-merged" << "auto" << mergedScreenNames.join(','); - qDebug() << prog1 << args1; - QProcess *myProcess1 = new QProcess(this); - myProcess1->start(prog1, args1); - QVERIFY(myProcess1->waitForFinished()); + QStringList args; + args << "--setmonitor" << "Qt-merged" << "auto" << mergedScreenNames.join(','); + xrandr_process(args); QTRY_COMPARE(removedSpy.count(), 2); QVERIFY(QGuiApplication::screens().size() != originalScreenNames.size()); @@ -91,12 +90,9 @@ void tst_QScreen_Xrandr::xrandr_15_merge_and_unmerge() removedSpy.clear(); // "xrandr --delmonitor Qt-merged" - QString prog2 = "xrandr"; - QStringList args2; - args2 << "--delmonitor" << "Qt-merged"; - QProcess *myProcess2 = new QProcess(this); - myProcess2->start(prog2, args2); - QVERIFY(myProcess2->waitForFinished()); + args.clear(); + args << "--delmonitor" << "Qt-merged"; + xrandr_process(args); QTRY_COMPARE(removedSpy.count(), 1); QVERIFY(QGuiApplication::screens().size() != combinedScreens.size()); @@ -127,12 +123,9 @@ void tst_QScreen_Xrandr::xrandr_15_scale() QSignalSpy geometryChangedSpy1(screen1, &QScreen::geometryChanged); // "xrandr --output name1 --scale 1.5x1.5" - QString prog1 = "xrandr"; - QStringList args1; - args1 << "--output" << name1 << "--scale" << "1.5x1.5"; - QProcess *myProcess1 = new QProcess(this); - myProcess1->start(prog1, args1); - QVERIFY(myProcess1->waitForFinished()); + QStringList args; + args << "--output" << name1 << "--scale" << "1.5x1.5"; + xrandr_process(args); QTRY_COMPARE(geometryChangedSpy1.count(), 1); QList screens2 = QGuiApplication::screens(); @@ -148,15 +141,12 @@ void tst_QScreen_Xrandr::xrandr_15_scale() QVERIFY(height2 == expectedHeight); QVERIFY(width2 == expectedWidth); - QSignalSpy geometryChangedSpy2(screen2, &QScreen::geometryChanged); + QSignalSpy geometryChangedSpy2(screen1, &QScreen::geometryChanged); // "xrandr --output name1 --scale 1x1" - QString prog2 = "xrandr"; - QStringList args2; - args2 << "--output" << name1 << "--scale" << "1x1"; - QProcess *myProcess2 = new QProcess(this); - myProcess2->start(prog2, args2); - QVERIFY(myProcess2->waitForFinished()); + args.clear(); + args << "--output" << name1 << "--scale" << "1x1"; + xrandr_process(args); QTRY_COMPARE(geometryChangedSpy2.count(), 1); QList screens3 = QGuiApplication::screens(); @@ -173,5 +163,14 @@ void tst_QScreen_Xrandr::xrandr_15_scale() QVERIFY(width3 == width1); } +void tst_QScreen_Xrandr::xrandr_process(const QStringList &args) +{ + QString prog = "xrandr"; + QProcess *process = new QProcess(this); + qDebug() << Q_FUNC_INFO << prog << args; + process->start(prog, args); + QVERIFY(process->waitForFinished()); +} + #include QTEST_MAIN(tst_QScreen_Xrandr);