summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp')
-rw-r--r--tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp120
1 files changed, 92 insertions, 28 deletions
diff --git a/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp b/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp
index b9cf91444f..6c87428d75 100644
--- a/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp
+++ b/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp
@@ -1,35 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** 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 https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/qabstractanimation.h>
#include <QtCore/qanimationgroup.h>
#include <QTest>
+#include <QtTest/private/qpropertytesthelper_p.h>
class tst_QAbstractAnimation : public QObject
{
@@ -48,6 +24,11 @@ private slots:
void avoidJumpAtStart();
void avoidJumpAtStartWithStop();
void avoidJumpAtStartWithRunning();
+ void stateBinding();
+ void loopCountBinding();
+ void currentTimeBinding();
+ void currentLoopBinding();
+ void directionBinding();
};
class TestableQAbstractAnimation : public QAbstractAnimation
@@ -56,7 +37,7 @@ class TestableQAbstractAnimation : public QAbstractAnimation
public:
TestableQAbstractAnimation() : m_duration(10) {}
- virtual ~TestableQAbstractAnimation() {};
+ virtual ~TestableQAbstractAnimation() override { }
int duration() const override { return m_duration; }
virtual void updateCurrentTime(int) override {}
@@ -228,6 +209,89 @@ void tst_QAbstractAnimation::avoidJumpAtStartWithRunning()
QVERIFY(anim3.currentTime() < 50);
}
+void tst_QAbstractAnimation::stateBinding()
+{
+ TestableQAbstractAnimation animation;
+ QTestPrivate::testReadOnlyPropertyBasics(animation, QAbstractAnimation::Stopped,
+ QAbstractAnimation::Running, "state",
+ [&] { animation.start(); });
+}
+
+void tst_QAbstractAnimation::loopCountBinding()
+{
+ TestableQAbstractAnimation animation;
+ QTestPrivate::testReadWritePropertyBasics(animation, 42, 43, "loopCount");
+}
+
+void tst_QAbstractAnimation::currentTimeBinding()
+{
+ TestableQAbstractAnimation animation;
+
+ QProperty<int> currentTimeProperty;
+ animation.bindableCurrentTime().setBinding(Qt::makePropertyBinding(currentTimeProperty));
+ QCOMPARE(animation.currentTime(), currentTimeProperty);
+
+ // This should cancel the binding
+ animation.start();
+
+ currentTimeProperty = 5;
+ QVERIFY(animation.currentTime() != currentTimeProperty);
+
+ QTestPrivate::testReadWritePropertyBasics(animation, 6, 7, "currentTime");
+}
+
+void tst_QAbstractAnimation::currentLoopBinding()
+{
+ TestableQAbstractAnimation animation;
+
+ QTestPrivate::testReadOnlyPropertyBasics(animation, 0, 3, "currentLoop", [&] {
+ // Trigger an update of currentLoop
+ animation.setLoopCount(4);
+ // This brings us to the end of the animation, so currentLoop should be loopCount - 1
+ animation.setCurrentTime(42);
+ });
+}
+
+void tst_QAbstractAnimation::directionBinding()
+{
+ TestableQAbstractAnimation animation;
+ QTestPrivate::testReadWritePropertyBasics(animation, QAbstractAnimation::Backward,
+ QAbstractAnimation::Forward, "direction");
+
+ // setDirection() may trigger a currentLoop update. Make sure the observers
+ // are notified about direction and currentLoop changes only after a consistent
+ // state is reached.
+ QProperty<int> currLoopObserver;
+ currLoopObserver.setBinding([&] { return animation.currentLoop(); });
+
+ QProperty<QAbstractAnimation::Direction> directionObserver;
+ directionObserver.setBinding([&] { return animation.direction(); });
+
+ animation.setLoopCount(10);
+
+ bool currentLoopChanged = false;
+ auto currentLoopHandler = animation.bindableCurrentLoop().onValueChanged([&] {
+ QVERIFY(!currentLoopChanged);
+ QCOMPARE(currLoopObserver, 9);
+ QCOMPARE(directionObserver, QAbstractAnimation::Backward);
+ currentLoopChanged = true;
+ });
+
+ bool directionChanged = false;
+ auto directionHandler = animation.bindableDirection().onValueChanged([&] {
+ QVERIFY(!directionChanged);
+ QCOMPARE(currLoopObserver, 9);
+ QCOMPARE(directionObserver, QAbstractAnimation::Backward);
+ directionChanged = true;
+ });
+
+ QCOMPARE(animation.direction(), QAbstractAnimation::Forward);
+ // This will set currentLoop to 9
+ animation.setDirection(QAbstractAnimation::Backward);
+
+ QVERIFY(currentLoopChanged);
+ QVERIFY(directionChanged);
+}
QTEST_MAIN(tst_QAbstractAnimation)