aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-11-17 10:02:41 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2020-11-17 16:18:05 +0100
commit22c2008a94fd1ddec2621ac27033b573196c8882 (patch)
tree55785638d8abf23da2f594289e01951a0c16fd2b /tests
parent0506fba1a862a30af5dcd9c5e240a8fb2fe304cf (diff)
Add QQuickTest::showView(); give QQuickTest::initView() default args
Now the boilerplate for most QML-using C++ tests can be reduced from QQuickView window; QByteArray errorMessage; QVERIFY2(QQuickTest::initView(window, testFileUrl("myitems.qml"), true, &errorMessage), errorMessage.constData()); window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(window.rootObject() != nullptr); to QQuickView window; QVERIFY(QQuickTest::showView(window, testFileUrl("myitems.qml"))); The idea to dump the QML error output was nice, but the engine already generates QWARN output like this (lines partially wrapped, URL elided for brevity): QWARN : tst_TouchMouse::touchPointDeliveryOrder() [ 0.000 W] default unknown - file:/...rder.qml:14:29: Cannot assign to non-existent property "pill" Rectangle { anchors.pill: parent; color: "lightsteelblue" } ^ FAIL! : tst_TouchMouse::touchPointDeliveryOrder() 'QQuickTest::showView(window, testFileUrl("touchpointdeliveryorder.qml"))' returned FALSE. () Loc: [/home/rutledge/dev/qt6/qtdeclarative/tests/auto/quick/touchmouse/tst_touchmouse.cpp(1343)] Improves on a804f31ee2665501c1894cbae8302db181090bd5 Change-Id: I92b8e3720bb5b1d009580bb74566690ad3d5292c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/shared/viewtestutil.cpp56
-rw-r--r--tests/auto/quick/shared/viewtestutil.h3
2 files changed, 46 insertions, 13 deletions
diff --git a/tests/auto/quick/shared/viewtestutil.cpp b/tests/auto/quick/shared/viewtestutil.cpp
index b17ebebde0..5f84147792 100644
--- a/tests/auto/quick/shared/viewtestutil.cpp
+++ b/tests/auto/quick/shared/viewtestutil.cpp
@@ -469,30 +469,62 @@ namespace QQuickTouchUtils {
}
namespace QQuickTest {
- // Initialize view, set Url, center in available geometry, move mouse away if desired
- bool initView(QQuickView &v, const QUrl &url, bool moveMouseOut, QByteArray *errorMessage)
+
+ /*! \internal
+ Initialize \a view, set \a url, center in available geometry, move mouse away if desired.
+ If \a errorMessage is given, QQuickView::errors() will be concatenated into it;
+ otherwise, the QWARN messages are generally enough to debug the test.
+
+ Returns \c false if the view fails to load the QML. That should be fatal in most tests,
+ so normally the return value should be checked with QVERIFY.
+ */
+ bool initView(QQuickView &view, const QUrl &url, bool moveMouseOut, QByteArray *errorMessage)
{
- v.setBaseSize(QSize(240,320));
- v.setSource(url);
- while (v.status() == QQuickView::Loading)
+ view.setSource(url);
+ while (view.status() == QQuickView::Loading)
QTest::qWait(10);
- if (v.status() != QQuickView::Ready) {
- foreach (const QQmlError &e, v.errors())
- errorMessage->append(e.toString().toLocal8Bit() + '\n');
+ if (view.status() != QQuickView::Ready) {
+ if (errorMessage) {
+ for (const QQmlError &e : view.errors())
+ errorMessage->append(e.toString().toLocal8Bit() + '\n');
+ }
return false;
}
- const QRect screenGeometry = v.screen()->availableGeometry();
- const QSize size = v.size();
+ const QRect screenGeometry = view.screen()->availableGeometry();
+ const QSize size = view.size();
const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
- v.setFramePosition(screenGeometry.center() - offset);
+ view.setFramePosition(screenGeometry.center() - offset);
#if QT_CONFIG(cursor) // Get the cursor out of the way.
if (moveMouseOut)
- QCursor::setPos(v.geometry().topRight() + QPoint(100, 100));
+ QCursor::setPos(view.geometry().topRight() + QPoint(100, 100));
#else
Q_UNUSED(moveMouseOut);
#endif
return true;
}
+
+ /*! \internal
+ Initialize \a view, set \a url, center in available geometry, move mouse away,
+ show the \a view, wait for it to be exposed, and verify that its rootObject is not null.
+
+ Returns \c false if anything fails, which should be fatal in most tests.
+ The usual way to call this function is
+ \code
+ QQuickView window;
+ QVERIFY(QQuickTest::showView(window, testFileUrl("myitems.qml")));
+ \endcode
+ */
+ bool showView(QQuickView &view, const QUrl &url)
+ {
+ if (!initView(view, url))
+ return false;
+ view.show();
+ if (!QTest::qWaitForWindowExposed(&view))
+ return false;
+ if (!view.rootObject())
+ return false;
+ return true;
+ }
}
QT_END_NAMESPACE
diff --git a/tests/auto/quick/shared/viewtestutil.h b/tests/auto/quick/shared/viewtestutil.h
index 5dc0beeae0..377296b095 100644
--- a/tests/auto/quick/shared/viewtestutil.h
+++ b/tests/auto/quick/shared/viewtestutil.h
@@ -188,7 +188,8 @@ namespace QQuickTouchUtils {
}
namespace QQuickTest {
- bool initView(QQuickView &v, const QUrl &url, bool moveMouseOut, QByteArray *errorMessage);
+ bool initView(QQuickView &v, const QUrl &url, bool moveMouseOut = true, QByteArray *errorMessage = nullptr);
+ bool showView(QQuickView &v, const QUrl &url);
}
QT_END_NAMESPACE