From a439a25f468d8c5623f2e0949b55a0c85c850f5f Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 24 Sep 2019 09:11:04 +0200 Subject: Ensure AnimatedImage currentFrame/onCurrentFrameChanged 2.0 compatibility Change 5d995ae122aa07486ead849560b74d2b62b883bb did not make the actual QQuickImageBase::currentFrameChanged signal accessible to the Qt Quick 2.0 revision. Normally the QML engine would implement a JS onCurrentFrameChanged handler by connecting to the currentFrame property's frameChanged notifier signal; but in this case it tried to connect to the explicit QQuickImageBase::currentFrameChanged signal instead (because the name is a better match), and failed because of the revision. So we need another duplicate unrevisioned signal QQuickAnimatedImage::currentFrameChanged for use when the import is less than Qt Quick 2.14. As pointed out during review, an autotest for the revisioning is good to have anyway. Fixes: QTBUG-78713 Task-number: QTBUG-77506 Change-Id: I121508acac81d47e3c0a4c0ed12257c10b30970b Reviewed-by: Ulf Hermann Reviewed-by: Fabian Kosmale --- .../tst_qquickanimatedimage.cpp | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp') diff --git a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp index 8026bafb9e..31c3fb9946 100644 --- a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp +++ b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include #include +#include #include #include #include @@ -40,6 +41,23 @@ Q_DECLARE_METATYPE(QQuickImageBase::Status) +template static T evaluate(QObject *scope, const QString &expression) +{ + QQmlExpression expr(qmlContext(scope), scope, expression); + QVariant result = expr.evaluate(); + if (expr.hasError()) + qWarning() << expr.error().toString(); + return result.value(); +} + +template <> void evaluate(QObject *scope, const QString &expression) +{ + QQmlExpression expr(qmlContext(scope), scope, expression); + expr.evaluate(); + if (expr.hasError()) + qWarning() << expr.error().toString(); +} + class tst_qquickanimatedimage : public QQmlDataTest { Q_OBJECT @@ -68,6 +86,7 @@ private slots: void playingAndPausedChanges(); void noCaching(); void sourceChangesOnFrameChanged(); + void currentFrame(); }; void tst_qquickanimatedimage::cleanup() @@ -618,6 +637,33 @@ void tst_qquickanimatedimage::sourceChangesOnFrameChanged() qDeleteAll(images); } +void tst_qquickanimatedimage::currentFrame() +{ + QQuickView window; + window.setSource(testFileUrl("currentframe.qml")); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + QQuickAnimatedImage *anim = qobject_cast(window.rootObject()); + QVERIFY(anim); + QSignalSpy frameChangedSpy(anim, SIGNAL(frameChanged())); + QSignalSpy currentFrameChangedSpy(anim, SIGNAL(currentFrameChanged())); + + anim->setCurrentFrame(1); + QCOMPARE(anim->currentFrame(), 1); + QCOMPARE(frameChangedSpy.count(), 1); + QCOMPARE(currentFrameChangedSpy.count(), 1); + QCOMPARE(anim->property("currentFrameChangeCount"), 1); + QCOMPARE(anim->property("frameChangeCount"), 1); + + evaluate(anim, "scriptedSetCurrentFrame(2)"); + QCOMPARE(anim->currentFrame(), 2); + QCOMPARE(frameChangedSpy.count(), 2); + QCOMPARE(currentFrameChangedSpy.count(), 2); + QCOMPARE(anim->property("currentFrameChangeCount"), 2); + QCOMPARE(anim->property("frameChangeCount"), 2); +} + QTEST_MAIN(tst_qquickanimatedimage) #include "tst_qquickanimatedimage.moc" -- cgit v1.2.3