25QQuickItem *QQuickVisualTestUtils::findVisibleChild(QQuickItem *parent,
const QString &objectName)
27 QQuickItem *item =
nullptr;
28 QList<QQuickItem*> items = parent->findChildren<QQuickItem*>(objectName);
29 for (
int i = 0; i < items.size(); ++i) {
30 if (items.at(i)->isVisible() && !QQuickItemPrivate::get(items.at(i))->culled) {
56 if (QGuiApplicationPrivate::platformIntegration()->hasCapability(
57 QPlatformIntegration::MouseCursorPositioning)) {
58 QCursor::setPos(window->frameGeometry().bottomLeft() + QPoint(-10, 10));
64 QEvent leave(QEvent::Leave);
65 QCoreApplication::sendEvent(window, &leave);
112 forEachStep(steps, [&](qreal progress) {
113 QQuickTest::pointerMove(mPointingDevice, mWindow, 0, lerpPoints(mFrom, pos, progress));
114 QTest::qWait(delayInMilliseconds);
152 auto maybeSaveImagesForDebugging = [ia, ib](QDebug &debug) {
153 if (!lcCompareImages().isDebugEnabled())
156 const QDir saveDir(QCoreApplication::applicationDirPath());
157 QString imageFileNamePrefix = QString::fromUtf8(
"%1-%2").arg(
158 QString::fromUtf8(QTest::currentAppName()),
159 QString::fromUtf8(QTest::currentTestFunction()));
160 if (QTest::currentDataTag())
161 imageFileNamePrefix.append(QStringLiteral(
"-") + QString::fromUtf8(QTest::currentDataTag()));
163 const QString actualImageFilePath = saveDir.filePath(imageFileNamePrefix + QLatin1String(
"-actual.png"));
164 const bool actualImageSaved = ia.save(actualImageFilePath);
165 if (!actualImageSaved)
166 qWarning() <<
"Failed to save actual image to" << actualImageFilePath;
168 const QString expectedImageFilePath = saveDir.filePath(imageFileNamePrefix + QLatin1String(
"-expected.png"));
169 const bool expectedImageSaved = ib.save(expectedImageFilePath);
170 if (!expectedImageSaved)
171 qWarning() <<
"Failed to save expected image to" << expectedImageFilePath;
173 if (actualImageSaved && expectedImageSaved) {
174 debug.noquote() <<
"\nActual image saved to:" << actualImageFilePath;
175 debug <<
"\nExpected image saved to:" << expectedImageFilePath;
179 if (ia.size() != ib.size()) {
180 QDebug debug(errorMessage);
181 debug <<
"Images are of different size:" << ia.size() << ib.size()
182 <<
"DPR:" << ia.devicePixelRatio() << ib.devicePixelRatio();
183 maybeSaveImagesForDebugging(debug);
186 if (ia.format() != ib.format()) {
187 QDebug debug(errorMessage);
188 debug <<
"Images are of different formats:" << ia.format() << ib.format();
189 maybeSaveImagesForDebugging(debug);
192 if (ia.depth() != 32) {
193 QDebug debug(errorMessage);
194 debug <<
"This function only supports bit depths of 32 - depth of images is:" << ia.depth();
195 maybeSaveImagesForDebugging(debug);
201 const int tolerance = 5;
202 for (
int y=0; y<h; ++y) {
203 const uint *as= (
const uint *) ia.constScanLine(y);
204 const uint *bs= (
const uint *) ib.constScanLine(y);
205 for (
int x=0; x<w; ++x) {
210 if ((a & 0xff000000) != (b & 0xff000000)
211 || qAbs(qRed(a) - qRed(b)) > tolerance
212 || qAbs(qGreen(a) - qGreen(b)) > tolerance
213 || qAbs(qBlue(a) - qBlue(b)) > tolerance) {
214 QDebug debug(errorMessage);
215 debug <<
"Mismatch at:" << x << y <<
':'
216 << Qt::hex << Qt::showbase << a << b;
217 maybeSaveImagesForDebugging(debug);
234QQuickItem *QQuickVisualTestUtils::findViewDelegateItem(QQuickItemView *itemView,
int index, FindViewDelegateItemFlags flags)
256QQuickVisualTestUtils::QQuickApplicationHelper::QQuickApplicationHelper(QQmlDataTest *testCase,
257 const QString &testFilePath,
const QVariantMap &initialProperties,
const QStringList &qmlImportPaths)
259 for (
const auto &path : qmlImportPaths)
260 engine.addImportPath(path);
262 QQmlComponent component(&engine);
264 component.loadUrl(testCase->testFileUrl(testFilePath));
265 QVERIFY2(component.isReady(), qPrintable(component.errorString()));
266 QObject *rootObject = component.createWithInitialProperties(initialProperties);
267 cleanup.reset(rootObject);
268 if (component.isError() || !rootObject) {
269 errorMessage = QString::fromUtf8(
"Failed to create window: %1").arg(component.errorString()).toUtf8();
273 window = qobject_cast<QQuickWindow*>(rootObject);
275 errorMessage = QString::fromUtf8(
"Root object %1 must be a QQuickWindow subclass").arg(QDebug::toString(window)).toUtf8();
279 if (window->isVisible()) {
280 errorMessage = QString::fromUtf8(
"Expected window not to be visible, but it is").toUtf8();