diff options
Diffstat (limited to 'tests/auto/quick/qquickanimations')
3 files changed, 144 insertions, 32 deletions
diff --git a/tests/auto/quick/qquickanimations/data/animatorInvalidTargetCrash.qml b/tests/auto/quick/qquickanimations/data/animatorInvalidTargetCrash.qml new file mode 100644 index 0000000000..f2c378e4b5 --- /dev/null +++ b/tests/auto/quick/qquickanimations/data/animatorInvalidTargetCrash.qml @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.3 +import QtQuick.Window 2.2 + +Window { + visible: true + width: 100 + height: 100 + + OpacityAnimator { + id: anim + from: 1 + to:0 + duration: 5000 + running: false + } + + Loader { + id: loader + sourceComponent: Text { + text: "Hello World" + anchors.centerIn: parent + } + } + + Component.onCompleted: { + anim.target = loader.item; + anim.start(); + loader.active = false; + } +} diff --git a/tests/auto/quick/qquickanimations/data/defaultRotationAnimation.qml b/tests/auto/quick/qquickanimations/data/defaultRotationAnimation.qml new file mode 100644 index 0000000000..94692add60 --- /dev/null +++ b/tests/auto/quick/qquickanimations/data/defaultRotationAnimation.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +Rectangle { + id: rect + + RotationAnimation { + target: rect + from: 0 + to: 360 + running: true + duration: 1000 + loops: Animation.Infinite + } +} diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index 45cfe4f334..5cad68b275 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -104,6 +104,8 @@ private slots: void scriptActionBug(); void groupAnimationNullChildBug(); void scriptActionCrash(); + void animatorInvalidTargetCrash(); + void defaultPropertyWarning(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -122,9 +124,9 @@ void tst_qquickanimations::simpleProperty() animation.setTargetObject(&rect); animation.setProperty("x"); animation.setTo(200); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "x"); - QVERIFY(animation.to().toReal() == 200.0); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("x")); + QCOMPARE(animation.to().toReal(), 200.0); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -136,7 +138,7 @@ void tst_qquickanimations::simpleProperty() animation.pause(); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.x(),100.0); } @@ -147,9 +149,9 @@ void tst_qquickanimations::simpleNumber() animation.setTargetObject(&rect); animation.setProperty("x"); animation.setTo(200); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "x"); - QVERIFY(animation.to() == 200); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("x")); + QCOMPARE(animation.to(), qreal(200)); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -161,7 +163,7 @@ void tst_qquickanimations::simpleNumber() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.x(), qreal(100)); } @@ -172,9 +174,9 @@ void tst_qquickanimations::simpleColor() animation.setTargetObject(&rect); animation.setProperty("color"); animation.setTo(QColor("red")); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "color"); - QVERIFY(animation.to() == QColor("red")); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("color")); + QCOMPARE(animation.to(), QColor("red")); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -186,12 +188,12 @@ void tst_qquickanimations::simpleColor() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1)); rect.setColor(QColor("green")); animation.setFrom(QColor("blue")); - QVERIFY(animation.from() == QColor("blue")); + QCOMPARE(animation.from(), QColor("blue")); animation.restart(); QCOMPARE(rect.color(), QColor("blue")); QVERIFY(animation.isRunning()); @@ -206,10 +208,10 @@ void tst_qquickanimations::simpleRotation() animation.setTargetObject(&rect); animation.setProperty("rotation"); animation.setTo(270); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "rotation"); - QVERIFY(animation.to() == 270); - QVERIFY(animation.direction() == QQuickRotationAnimation::Numerical); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("rotation")); + QCOMPARE(animation.to(), qreal(270)); + QCOMPARE(animation.direction(), QQuickRotationAnimation::Numerical); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -221,7 +223,7 @@ void tst_qquickanimations::simpleRotation() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.rotation(), qreal(135)); } @@ -567,8 +569,8 @@ void tst_qquickanimations::alwaysRunToEnd() animation.setDuration(1000); animation.setLoops(-1); animation.setAlwaysRunToEnd(true); - QVERIFY(animation.loops() == -1); - QVERIFY(animation.alwaysRunToEnd() == true); + QCOMPARE(animation.loops(), -1); + QVERIFY(animation.alwaysRunToEnd()); QElapsedTimer timer; timer.start(); @@ -600,7 +602,7 @@ void tst_qquickanimations::complete() animation.setFrom(1); animation.setTo(200); animation.setDuration(500); - QVERIFY(animation.from() == 1); + QCOMPARE(animation.from().toInt(), 1); animation.start(); QTest::qWait(50); animation.stop(); @@ -620,7 +622,7 @@ void tst_qquickanimations::resume() animation.setFrom(10); animation.setTo(200); animation.setDuration(1000); - QVERIFY(animation.from() == 10); + QCOMPARE(animation.from().toInt(), 10); animation.start(); QTest::qWait(400); @@ -685,7 +687,7 @@ void tst_qquickanimations::dotProperty() animation.start(); animation.pause(); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.border()->width(), 5.0); } @@ -708,7 +710,7 @@ void tst_qquickanimations::badTypes() QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); c.create(); - QVERIFY(c.errors().count() == 1); + QCOMPARE(c.errors().count(), 1); QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: number expected")); } @@ -719,7 +721,7 @@ void tst_qquickanimations::badTypes() QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); c.create(); - QVERIFY(c.errors().count() == 1); + QCOMPARE(c.errors().count(), 1); QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: color expected")); } @@ -1065,7 +1067,7 @@ void tst_qquickanimations::propertyValueSourceDefaultStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim); - QVERIFY(myAnim->isRunning() == false); + QVERIFY(!myAnim->isRunning()); } { @@ -1078,7 +1080,7 @@ void tst_qquickanimations::propertyValueSourceDefaultStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim && !myAnim->qtAnimation()); - //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); + //QCOMPARE(myAnim->qtAnimation()->state(), QAbstractAnimationJob::Stopped); } } @@ -1097,7 +1099,7 @@ void tst_qquickanimations::dontStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim && !myAnim->qtAnimation()); - //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); + //QCOMPARE(myAnim->qtAnimation()->state(), QAbstractAnimationJob::Stopped); } { @@ -1112,7 +1114,7 @@ void tst_qquickanimations::dontStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim && !myAnim->qtAnimation()); - //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); + //QCOMPARE(myAnim->qtAnimation()->state(), QAbstractAnimationJob::Stopped); } } @@ -1350,8 +1352,8 @@ void tst_qquickanimations::alwaysRunToEndRestartBug() animation.setDuration(1000); animation.setLoops(-1); animation.setAlwaysRunToEnd(true); - QVERIFY(animation.loops() == -1); - QVERIFY(animation.alwaysRunToEnd() == true); + QCOMPARE(animation.loops(), -1); + QVERIFY(animation.alwaysRunToEnd()); animation.start(); animation.stop(); animation.start(); @@ -1387,7 +1389,7 @@ void tst_qquickanimations::pauseBindingBug() QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); QVERIFY(rect != 0); QQuickAbstractAnimation *anim = rect->findChild<QQuickAbstractAnimation*>("animation"); - QVERIFY(anim->qtAnimation()->state() == QAbstractAnimationJob::Paused); + QCOMPARE(anim->qtAnimation()->state(), QAbstractAnimationJob::Paused); delete rect; } @@ -1491,7 +1493,40 @@ void tst_qquickanimations::scriptActionCrash() delete obj; } +// QTBUG-49364 +// Test that we don't crash when the target of an Animator becomes +// invalid between the time the animator is started and the time the +// animator job is actually started +void tst_qquickanimations::animatorInvalidTargetCrash() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("animatorInvalidTargetCrash.qml")); + QObject *obj = c.create(); + + //just testing that we don't crash + QTest::qWait(5000); //animator duration + + delete obj; +} + +Q_DECLARE_METATYPE(QList<QQmlError>) + +// QTBUG-22141 +void tst_qquickanimations::defaultPropertyWarning() +{ + QQmlEngine engine; + + qRegisterMetaType<QList<QQmlError> >(); + QSignalSpy warnings(&engine, SIGNAL(warnings(QList<QQmlError>))); + QVERIFY(warnings.isValid()); + + QQmlComponent component(&engine, testFileUrl("defaultRotationAnimation.qml")); + QScopedPointer<QQuickItem> root(qobject_cast<QQuickItem*>(component.create())); + QVERIFY(root); + + QVERIFY(warnings.isEmpty()); +} QTEST_MAIN(tst_qquickanimations) |