summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/animation
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/animation')
-rw-r--r--tests/auto/corelib/animation/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/animation/animation.pro12
-rw-r--r--tests/auto/corelib/animation/qabstractanimation/CMakeLists.txt11
-rw-r--r--tests/auto/corelib/animation/qabstractanimation/qabstractanimation.pro4
-rw-r--r--tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp122
-rw-r--r--tests/auto/corelib/animation/qanimationgroup/CMakeLists.txt9
-rw-r--r--tests/auto/corelib/animation/qanimationgroup/qanimationgroup.pro4
-rw-r--r--tests/auto/corelib/animation/qanimationgroup/tst_qanimationgroup.cpp49
-rw-r--r--tests/auto/corelib/animation/qparallelanimationgroup/CMakeLists.txt9
-rw-r--r--tests/auto/corelib/animation/qparallelanimationgroup/qparallelanimationgroup.pro4
-rw-r--r--tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp178
-rw-r--r--tests/auto/corelib/animation/qpauseanimation/CMakeLists.txt12
-rw-r--r--tests/auto/corelib/animation/qpauseanimation/qpauseanimation.pro4
-rw-r--r--tests/auto/corelib/animation/qpauseanimation/tst_qpauseanimation.cpp85
-rw-r--r--tests/auto/corelib/animation/qpropertyanimation/CMakeLists.txt13
-rw-r--r--tests/auto/corelib/animation/qpropertyanimation/qpropertyanimation.pro4
-rw-r--r--tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp166
-rw-r--r--tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST1
-rw-r--r--tests/auto/corelib/animation/qsequentialanimationgroup/CMakeLists.txt11
-rw-r--r--tests/auto/corelib/animation/qsequentialanimationgroup/qsequentialanimationgroup.pro4
-rw-r--r--tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp205
-rw-r--r--tests/auto/corelib/animation/qvariantanimation/CMakeLists.txt11
-rw-r--r--tests/auto/corelib/animation/qvariantanimation/qvariantanimation.pro4
-rw-r--r--tests/auto/corelib/animation/qvariantanimation/tst_qvariantanimation.cpp60
24 files changed, 554 insertions, 431 deletions
diff --git a/tests/auto/corelib/animation/CMakeLists.txt b/tests/auto/corelib/animation/CMakeLists.txt
index 79c2d6c4e9..85c121d243 100644
--- a/tests/auto/corelib/animation/CMakeLists.txt
+++ b/tests/auto/corelib/animation/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from animation.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qabstractanimation)
add_subdirectory(qanimationgroup)
diff --git a/tests/auto/corelib/animation/animation.pro b/tests/auto/corelib/animation/animation.pro
deleted file mode 100644
index 30c98f4a11..0000000000
--- a/tests/auto/corelib/animation/animation.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-TEMPLATE=subdirs
-SUBDIRS=\
- qabstractanimation \
- qanimationgroup \
- qparallelanimationgroup \
- qpauseanimation \
- qpropertyanimation \
- qsequentialanimationgroup \
- qvariantanimation
-
-!qtHaveModule(widgets): SUBDIRS -= \
- qpropertyanimation
diff --git a/tests/auto/corelib/animation/qabstractanimation/CMakeLists.txt b/tests/auto/corelib/animation/qabstractanimation/CMakeLists.txt
index 7db3ef9462..6e1ac655ba 100644
--- a/tests/auto/corelib/animation/qabstractanimation/CMakeLists.txt
+++ b/tests/auto/corelib/animation/qabstractanimation/CMakeLists.txt
@@ -1,10 +1,19 @@
-# Generated from qabstractanimation.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qabstractanimation Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qabstractanimation LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qabstractanimation
SOURCES
tst_qabstractanimation.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/animation/qabstractanimation/qabstractanimation.pro b/tests/auto/corelib/animation/qabstractanimation/qabstractanimation.pro
deleted file mode 100644
index 32701c2c9c..0000000000
--- a/tests/auto/corelib/animation/qabstractanimation/qabstractanimation.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qabstractanimation
-QT = core testlib
-SOURCES = tst_qabstractanimation.cpp
diff --git a/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp b/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp
index b490e5ca72..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 <QtTest>
+#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)
diff --git a/tests/auto/corelib/animation/qanimationgroup/CMakeLists.txt b/tests/auto/corelib/animation/qanimationgroup/CMakeLists.txt
index 5dcdf49836..a8160051a3 100644
--- a/tests/auto/corelib/animation/qanimationgroup/CMakeLists.txt
+++ b/tests/auto/corelib/animation/qanimationgroup/CMakeLists.txt
@@ -1,9 +1,16 @@
-# Generated from qanimationgroup.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qanimationgroup Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qanimationgroup LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qanimationgroup
SOURCES
tst_qanimationgroup.cpp
diff --git a/tests/auto/corelib/animation/qanimationgroup/qanimationgroup.pro b/tests/auto/corelib/animation/qanimationgroup/qanimationgroup.pro
deleted file mode 100644
index f4b5747216..0000000000
--- a/tests/auto/corelib/animation/qanimationgroup/qanimationgroup.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qanimationgroup
-QT = core testlib
-SOURCES = tst_qanimationgroup.cpp
diff --git a/tests/auto/corelib/animation/qanimationgroup/tst_qanimationgroup.cpp b/tests/auto/corelib/animation/qanimationgroup/tst_qanimationgroup.cpp
index fd1e288b4d..5345283252 100644
--- a/tests/auto/corelib/animation/qanimationgroup/tst_qanimationgroup.cpp
+++ b/tests/auto/corelib/animation/qanimationgroup/tst_qanimationgroup.cpp
@@ -1,32 +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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
+#include <QPauseAnimation>
+#include <QVariantAnimation>
+#include <QPropertyAnimation>
+#include <QSignalSpy>
#include <QtCore/qanimationgroup.h>
#include <QtCore/qsequentialanimationgroup.h>
@@ -130,7 +109,7 @@ void tst_QAnimationGroup::emptyGroup()
QCOMPARE(group.state(), QAnimationGroup::Stopped);
group.start();
- QCOMPARE(groupStateChangedSpy.count(), 2);
+ QCOMPARE(groupStateChangedSpy.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(groupStateChangedSpy.at(0).first()),
QAnimationGroup::Running);
@@ -142,7 +121,7 @@ void tst_QAnimationGroup::emptyGroup()
QTest::ignoreMessage(QtWarningMsg, "QAbstractAnimation::pause: Cannot pause a stopped animation");
group.pause();
- QCOMPARE(groupStateChangedSpy.count(), 2);
+ QCOMPARE(groupStateChangedSpy.size(), 2);
QCOMPARE(group.state(), QAnimationGroup::Stopped);
group.start();
@@ -156,7 +135,7 @@ void tst_QAnimationGroup::emptyGroup()
group.stop();
- QCOMPARE(groupStateChangedSpy.count(), 4);
+ QCOMPARE(groupStateChangedSpy.size(), 4);
QCOMPARE(group.state(), QAnimationGroup::Stopped);
}
@@ -286,7 +265,8 @@ void tst_QAnimationGroup::setParentAutoAdd()
void tst_QAnimationGroup::beginNestedGroup()
{
- QAnimationGroup *parent = new QParallelAnimationGroup();
+ QParallelAnimationGroup group;
+ QAnimationGroup *parent = &group;
for (int i = 0; i < 10; ++i) {
if (i & 1) {
@@ -343,7 +323,8 @@ void tst_QAnimationGroup::addChildTwice()
void tst_QAnimationGroup::loopWithoutStartValue()
{
- QAnimationGroup *parent = new QSequentialAnimationGroup();
+ QSequentialAnimationGroup group;
+ QAnimationGroup *parent = &group;
QObject o;
o.setProperty("ole", 0);
QCOMPARE(o.property("ole").toInt(), 0);
diff --git a/tests/auto/corelib/animation/qparallelanimationgroup/CMakeLists.txt b/tests/auto/corelib/animation/qparallelanimationgroup/CMakeLists.txt
index 9a6c9f45db..c532ad7327 100644
--- a/tests/auto/corelib/animation/qparallelanimationgroup/CMakeLists.txt
+++ b/tests/auto/corelib/animation/qparallelanimationgroup/CMakeLists.txt
@@ -1,9 +1,16 @@
-# Generated from qparallelanimationgroup.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qparallelanimationgroup Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qparallelanimationgroup LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qparallelanimationgroup
SOURCES
tst_qparallelanimationgroup.cpp
diff --git a/tests/auto/corelib/animation/qparallelanimationgroup/qparallelanimationgroup.pro b/tests/auto/corelib/animation/qparallelanimationgroup/qparallelanimationgroup.pro
deleted file mode 100644
index 5b4c6ab90a..0000000000
--- a/tests/auto/corelib/animation/qparallelanimationgroup/qparallelanimationgroup.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qparallelanimationgroup
-QT = core testlib
-SOURCES = tst_qparallelanimationgroup.cpp
diff --git a/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp b/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp
index dab7a8cd6f..c47ce53364 100644
--- a/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp
+++ b/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp
@@ -1,34 +1,13 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
+#include <QVariantAnimation>
+#include <QPropertyAnimation>
+#include <QSignalSpy>
#include <QtCore/qparallelanimationgroup.h>
+#include <QtCore/qscopeguard.h>
Q_DECLARE_METATYPE(QAbstractAnimation::State)
@@ -256,38 +235,38 @@ void tst_QParallelAnimationGroup::stateChanged()
//first; let's start forward
group.start();
//all the animations should be started
- QCOMPARE(spy1.count(), 1);
+ QCOMPARE(spy1.size(), 1);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy1.last().first()), TestAnimation::Running);
- QCOMPARE(spy2.count(), 1);
+ QCOMPARE(spy2.size(), 1);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy2.last().first()), TestAnimation::Running);
- QCOMPARE(spy3.count(), 1);
+ QCOMPARE(spy3.size(), 1);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy3.last().first()), TestAnimation::Running);
- QCOMPARE(spy4.count(), 1);
+ QCOMPARE(spy4.size(), 1);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy4.last().first()), TestAnimation::Running);
group.setCurrentTime(1500); //anim1 should be finished
QCOMPARE(group.state(), QAnimationGroup::Running);
- QCOMPARE(spy1.count(), 2);
+ QCOMPARE(spy1.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy1.last().first()), TestAnimation::Stopped);
- QCOMPARE(spy2.count(), 1); //no change
- QCOMPARE(spy3.count(), 1); //no change
- QCOMPARE(spy4.count(), 1); //no change
+ QCOMPARE(spy2.size(), 1); //no change
+ QCOMPARE(spy3.size(), 1); //no change
+ QCOMPARE(spy4.size(), 1); //no change
group.setCurrentTime(2500); //anim2 should be finished
QCOMPARE(group.state(), QAnimationGroup::Running);
- QCOMPARE(spy1.count(), 2); //no change
- QCOMPARE(spy2.count(), 2);
+ QCOMPARE(spy1.size(), 2); //no change
+ QCOMPARE(spy2.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy2.last().first()), TestAnimation::Stopped);
- QCOMPARE(spy3.count(), 1); //no change
- QCOMPARE(spy4.count(), 1); //no change
+ QCOMPARE(spy3.size(), 1); //no change
+ QCOMPARE(spy4.size(), 1); //no change
group.setCurrentTime(3500); //everything should be finished
QCOMPARE(group.state(), QAnimationGroup::Stopped);
- QCOMPARE(spy1.count(), 2); //no change
- QCOMPARE(spy2.count(), 2); //no change
- QCOMPARE(spy3.count(), 2);
+ QCOMPARE(spy1.size(), 2); //no change
+ QCOMPARE(spy2.size(), 2); //no change
+ QCOMPARE(spy3.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy3.last().first()), TestAnimation::Stopped);
- QCOMPARE(spy4.count(), 2);
+ QCOMPARE(spy4.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy4.last().first()), TestAnimation::Stopped);
//cleanup
@@ -302,38 +281,38 @@ void tst_QParallelAnimationGroup::stateChanged()
//only anim3 and anim4 should be started
QCOMPARE(group.state(), QAnimationGroup::Running);
- QCOMPARE(spy1.count(), 0);
- QCOMPARE(spy2.count(), 0);
- QCOMPARE(spy3.count(), 1);
+ QCOMPARE(spy1.size(), 0);
+ QCOMPARE(spy2.size(), 0);
+ QCOMPARE(spy3.size(), 1);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy3.last().first()), TestAnimation::Running);
- QCOMPARE(spy4.count(), 1);
+ QCOMPARE(spy4.size(), 1);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy4.last().first()), TestAnimation::Running);
group.setCurrentTime(1500); //anim2 should be started
QCOMPARE(group.state(), QAnimationGroup::Running);
- QCOMPARE(spy1.count(), 0); //no change
- QCOMPARE(spy2.count(), 1);
+ QCOMPARE(spy1.size(), 0); //no change
+ QCOMPARE(spy2.size(), 1);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy2.last().first()), TestAnimation::Running);
- QCOMPARE(spy3.count(), 1); //no change
- QCOMPARE(spy4.count(), 1); //no change
+ QCOMPARE(spy3.size(), 1); //no change
+ QCOMPARE(spy4.size(), 1); //no change
group.setCurrentTime(500); //anim1 is finally also started
QCOMPARE(group.state(), QAnimationGroup::Running);
- QCOMPARE(spy1.count(), 1);
+ QCOMPARE(spy1.size(), 1);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy1.last().first()), TestAnimation::Running);
- QCOMPARE(spy2.count(), 1); //no change
- QCOMPARE(spy3.count(), 1); //no change
- QCOMPARE(spy4.count(), 1); //no change
+ QCOMPARE(spy2.size(), 1); //no change
+ QCOMPARE(spy3.size(), 1); //no change
+ QCOMPARE(spy4.size(), 1); //no change
group.setCurrentTime(0); //everything should be stopped
QCOMPARE(group.state(), QAnimationGroup::Stopped);
- QCOMPARE(spy1.count(), 2);
+ QCOMPARE(spy1.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy1.last().first()), TestAnimation::Stopped);
- QCOMPARE(spy2.count(), 2);
+ QCOMPARE(spy2.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy2.last().first()), TestAnimation::Stopped);
- QCOMPARE(spy3.count(), 2);
+ QCOMPARE(spy3.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy3.last().first()), TestAnimation::Stopped);
- QCOMPARE(spy4.count(), 2);
+ QCOMPARE(spy4.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy4.last().first()), TestAnimation::Stopped);
}
@@ -427,8 +406,8 @@ void tst_QParallelAnimationGroup::updateChildrenWithRunningGroup()
QVERIFY(groupStateChangedSpy.isValid());
QVERIFY(childStateChangedSpy.isValid());
- QCOMPARE(groupStateChangedSpy.count(), 0);
- QCOMPARE(childStateChangedSpy.count(), 0);
+ QCOMPARE(groupStateChangedSpy.size(), 0);
+ QCOMPARE(childStateChangedSpy.size(), 0);
QCOMPARE(group.state(), QAnimationGroup::Stopped);
QCOMPARE(anim.state(), QAnimationGroup::Stopped);
@@ -439,8 +418,8 @@ void tst_QParallelAnimationGroup::updateChildrenWithRunningGroup()
QCOMPARE(group.state(), QAnimationGroup::Running);
QCOMPARE(anim.state(), QAnimationGroup::Running);
- QCOMPARE(groupStateChangedSpy.count(), 1);
- QCOMPARE(childStateChangedSpy.count(), 1);
+ QCOMPARE(groupStateChangedSpy.size(), 1);
+ QCOMPARE(childStateChangedSpy.size(), 1);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(groupStateChangedSpy.at(0).first()),
QAnimationGroup::Running);
@@ -450,8 +429,8 @@ void tst_QParallelAnimationGroup::updateChildrenWithRunningGroup()
// starting directly a running child will not have any effect
anim.start();
- QCOMPARE(groupStateChangedSpy.count(), 1);
- QCOMPARE(childStateChangedSpy.count(), 1);
+ QCOMPARE(groupStateChangedSpy.size(), 1);
+ QCOMPARE(childStateChangedSpy.size(), 1);
anim.pause();
@@ -594,8 +573,8 @@ void tst_QParallelAnimationGroup::startGroupWithRunningChild()
QVERIFY(stateChangedSpy1.isValid());
QVERIFY(stateChangedSpy2.isValid());
- QCOMPARE(stateChangedSpy1.count(), 0);
- QCOMPARE(stateChangedSpy2.count(), 0);
+ QCOMPARE(stateChangedSpy1.size(), 0);
+ QCOMPARE(stateChangedSpy2.size(), 0);
QCOMPARE(group.state(), QAnimationGroup::Stopped);
QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
@@ -620,13 +599,13 @@ void tst_QParallelAnimationGroup::startGroupWithRunningChild()
group.start();
- QCOMPARE(stateChangedSpy1.count(), 3);
+ QCOMPARE(stateChangedSpy1.size(), 3);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy1.at(1).first()),
QAnimationGroup::Stopped);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy1.at(2).first()),
QAnimationGroup::Running);
- QCOMPARE(stateChangedSpy2.count(), 4);
+ QCOMPARE(stateChangedSpy2.size(), 4);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy2.at(2).first()),
QAnimationGroup::Stopped);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy2.at(3).first()),
@@ -677,22 +656,22 @@ void tst_QParallelAnimationGroup::zeroDurationAnimation()
group.addAnimation(&anim1);
group.addAnimation(&anim2);
group.addAnimation(&anim3);
- QCOMPARE(stateChangedSpy1.count(), 0);
+ QCOMPARE(stateChangedSpy1.size(), 0);
group.start();
- QCOMPARE(stateChangedSpy1.count(), 2);
- QCOMPARE(finishedSpy1.count(), 1);
+ QCOMPARE(stateChangedSpy1.size(), 2);
+ QCOMPARE(finishedSpy1.size(), 1);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy1.at(0).first()),
QAnimationGroup::Running);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy1.at(1).first()),
QAnimationGroup::Stopped);
- QCOMPARE(stateChangedSpy2.count(), 1);
- QCOMPARE(finishedSpy2.count(), 0);
+ QCOMPARE(stateChangedSpy2.size(), 1);
+ QCOMPARE(finishedSpy2.size(), 0);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy1.at(0).first()),
QAnimationGroup::Running);
- QCOMPARE(stateChangedSpy3.count(), 1);
- QCOMPARE(finishedSpy3.count(), 0);
+ QCOMPARE(stateChangedSpy3.size(), 1);
+ QCOMPARE(finishedSpy3.size(), 0);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy3.at(0).first()),
QAnimationGroup::Running);
@@ -710,21 +689,21 @@ void tst_QParallelAnimationGroup::zeroDurationAnimation()
stateChangedSpy3.clear();
group.start();
- QCOMPARE(stateChangedSpy1.count(), 2);
- QCOMPARE(stateChangedSpy2.count(), 1);
- QCOMPARE(stateChangedSpy3.count(), 1);
+ QCOMPARE(stateChangedSpy1.size(), 2);
+ QCOMPARE(stateChangedSpy2.size(), 1);
+ QCOMPARE(stateChangedSpy3.size(), 1);
group.setCurrentTime(50);
- QCOMPARE(stateChangedSpy1.count(), 2);
- QCOMPARE(stateChangedSpy2.count(), 1);
- QCOMPARE(stateChangedSpy3.count(), 2);
+ QCOMPARE(stateChangedSpy1.size(), 2);
+ QCOMPARE(stateChangedSpy2.size(), 1);
+ QCOMPARE(stateChangedSpy3.size(), 2);
group.setCurrentTime(150);
- QCOMPARE(stateChangedSpy1.count(), 4);
- QCOMPARE(stateChangedSpy2.count(), 3);
- QCOMPARE(stateChangedSpy3.count(), 4);
+ QCOMPARE(stateChangedSpy1.size(), 4);
+ QCOMPARE(stateChangedSpy2.size(), 3);
+ QCOMPARE(stateChangedSpy3.size(), 4);
group.setCurrentTime(50);
- QCOMPARE(stateChangedSpy1.count(), 6);
- QCOMPARE(stateChangedSpy2.count(), 5);
- QCOMPARE(stateChangedSpy3.count(), 6);
+ QCOMPARE(stateChangedSpy1.size(), 6);
+ QCOMPARE(stateChangedSpy2.size(), 5);
+ QCOMPARE(stateChangedSpy3.size(), 6);
}
@@ -756,7 +735,7 @@ void tst_QParallelAnimationGroup::stopUncontrolledAnimations()
group.start();
- QCOMPARE(stateChangedSpy.count(), 2);
+ QCOMPARE(stateChangedSpy.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy.at(0).first()),
QAnimationGroup::Running);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy.at(1).first()),
@@ -787,7 +766,7 @@ struct AnimState {
int state;
};
QT_BEGIN_NAMESPACE
-Q_DECLARE_TYPEINFO(AnimState, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(AnimState, Q_RELOCATABLE_TYPE);
QT_END_NAMESPACE
#define Running QAbstractAnimation::Running
@@ -950,6 +929,7 @@ void tst_QParallelAnimationGroup::autoAdd()
test = static_cast<TestAnimation2*>(group.animationAt(0));
test->setParent(0); // remove the last one (with duration = 250)
+ const auto deleteParentlessObject = qScopeGuard([test] { delete test; });
QCOMPARE(test->group(), static_cast<QAnimationGroup*>(0));
QCOMPARE(group.duration(), 0);
}
@@ -965,7 +945,7 @@ void tst_QParallelAnimationGroup::pauseResume()
QTest::qWait(100);
QCOMPARE(group.state(), QAnimationGroup::Running);
QCOMPARE(anim->state(), QAnimationGroup::Running);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
const int currentTime = group.currentLoopTime();
QCOMPARE(anim->currentLoopTime(), currentTime);
@@ -975,7 +955,7 @@ void tst_QParallelAnimationGroup::pauseResume()
QCOMPARE(group.currentLoopTime(), currentTime);
QCOMPARE(anim->state(), QAnimationGroup::Paused);
QCOMPARE(anim->currentLoopTime(), currentTime);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
group.resume();
@@ -983,21 +963,21 @@ void tst_QParallelAnimationGroup::pauseResume()
QCOMPARE(group.currentLoopTime(), currentTime);
QCOMPARE(anim->state(), QAnimationGroup::Running);
QCOMPARE(anim->currentLoopTime(), currentTime);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
group.stop();
spy.clear();
new TestAnimation2(500, &group);
group.start();
- QCOMPARE(spy.count(), 1); //the animation should have been started
+ QCOMPARE(spy.size(), 1); //the animation should have been started
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy.last().first()), TestAnimation::Running);
group.setCurrentTime(250); //end of first animation
- QCOMPARE(spy.count(), 2); //the animation should have been stopped
+ QCOMPARE(spy.size(), 2); //the animation should have been stopped
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(spy.last().first()), TestAnimation::Stopped);
group.pause();
- QCOMPARE(spy.count(), 2); //this shouldn't have changed
+ QCOMPARE(spy.size(), 2); //this shouldn't have changed
group.resume();
- QCOMPARE(spy.count(), 2); //this shouldn't have changed
+ QCOMPARE(spy.size(), 2); //this shouldn't have changed
}
// This is a regression test for QTBUG-8910, where a crash occurred when the
diff --git a/tests/auto/corelib/animation/qpauseanimation/CMakeLists.txt b/tests/auto/corelib/animation/qpauseanimation/CMakeLists.txt
index bc846d33e7..aa0cb1edc5 100644
--- a/tests/auto/corelib/animation/qpauseanimation/CMakeLists.txt
+++ b/tests/auto/corelib/animation/qpauseanimation/CMakeLists.txt
@@ -1,12 +1,20 @@
-# Generated from qpauseanimation.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpauseanimation Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpauseanimation LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpauseanimation
SOURCES
tst_qpauseanimation.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/animation/qpauseanimation/qpauseanimation.pro b/tests/auto/corelib/animation/qpauseanimation/qpauseanimation.pro
deleted file mode 100644
index 7f19bc7545..0000000000
--- a/tests/auto/corelib/animation/qpauseanimation/qpauseanimation.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qpauseanimation
-QT = core-private testlib
-SOURCES = tst_qpauseanimation.cpp
diff --git a/tests/auto/corelib/animation/qpauseanimation/tst_qpauseanimation.cpp b/tests/auto/corelib/animation/qpauseanimation/tst_qpauseanimation.cpp
index 5f2923f498..8b11656706 100644
--- a/tests/auto/corelib/animation/qpauseanimation/tst_qpauseanimation.cpp
+++ b/tests/auto/corelib/animation/qpauseanimation/tst_qpauseanimation.cpp
@@ -1,40 +1,18 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
+#include <QtTest/private/qpropertytesthelper_p.h>
#include <QtCore/qpauseanimation.h>
#include <QtCore/qpropertyanimation.h>
#include <QtCore/qsequentialanimationgroup.h>
+#include <QParallelAnimationGroup>
+
#include <private/qabstractanimation_p.h>
-#if defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
+#if defined(Q_OS_WIN) || defined(Q_OS_ANDROID) || defined(Q_OS_QNX)
# define BAD_TIMER_RESOLUTION
#endif
@@ -103,6 +81,7 @@ private slots:
void sequentialGroupWithPause();
void multipleSequentialGroups();
void zeroDuration();
+ void bindings();
};
void tst_QPauseAnimation::initTestCase()
@@ -440,5 +419,51 @@ void tst_QPauseAnimation::zeroDuration()
QCOMPARE(animation.m_updateCurrentTimeCount, 1);
}
+void tst_QPauseAnimation::bindings()
+{
+ TestablePauseAnimation animation;
+
+ QProperty<int> duration;
+ animation.bindableDuration().setBinding(Qt::makePropertyBinding(duration));
+
+ duration = 42;
+ QCOMPARE(animation.duration(), 42);
+
+ // negative values must be ignored
+ QTest::ignoreMessage(QtWarningMsg,
+ "QPauseAnimation::setDuration: cannot set a negative duration");
+ duration = -1;
+ QCOMPARE(animation.duration(), 42);
+ QCOMPARE(duration, -1);
+
+ // Setting an invalid value shouldn't clear the binding
+ QTest::ignoreMessage(QtWarningMsg,
+ "QPauseAnimation::setDuration: cannot set a negative duration");
+ animation.setDuration(-1);
+ QVERIFY(animation.bindableDuration().hasBinding());
+ QCOMPARE(animation.duration(), 42);
+
+ QProperty<int> durationObserver;
+ durationObserver.setBinding(animation.bindableDuration().makeBinding());
+
+ animation.setDuration(46);
+ QCOMPARE(durationObserver, 46);
+
+ // Setting a valid value should clear the binding
+ QVERIFY(!animation.bindableDuration().hasBinding());
+
+ // Setting an invalid value also doesn't affect the observer
+ QTest::ignoreMessage(QtWarningMsg,
+ "QPauseAnimation::setDuration: cannot set a negative duration");
+ animation.setDuration(-1);
+ QCOMPARE(durationObserver, 46);
+
+ QTestPrivate::testReadWritePropertyBasics(animation, 10, 20, "duration");
+ if (QTest::currentTestFailed()) {
+ qDebug("Failed property test for QPauseAnimation::duration");
+ return;
+ }
+}
+
QTEST_MAIN(tst_QPauseAnimation)
#include "tst_qpauseanimation.moc"
diff --git a/tests/auto/corelib/animation/qpropertyanimation/CMakeLists.txt b/tests/auto/corelib/animation/qpropertyanimation/CMakeLists.txt
index 5233616115..38383aff46 100644
--- a/tests/auto/corelib/animation/qpropertyanimation/CMakeLists.txt
+++ b/tests/auto/corelib/animation/qpropertyanimation/CMakeLists.txt
@@ -1,14 +1,23 @@
-# Generated from qpropertyanimation.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpropertyanimation Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpropertyanimation LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpropertyanimation
SOURCES
tst_qpropertyanimation.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::Widgets
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/animation/qpropertyanimation/qpropertyanimation.pro b/tests/auto/corelib/animation/qpropertyanimation/qpropertyanimation.pro
deleted file mode 100644
index 72a36876b7..0000000000
--- a/tests/auto/corelib/animation/qpropertyanimation/qpropertyanimation.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qpropertyanimation
-QT = core gui widgets testlib core-private
-SOURCES = tst_qpropertyanimation.cpp
diff --git a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp
index ada5d29f5c..03755fa7ab 100644
--- a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp
+++ b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp
@@ -1,32 +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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
+#include <QtTest/private/qpropertytesthelper_p.h>
+#include <QSignalSpy>
+#include <QAnimationGroup>
+#include <QSequentialAnimationGroup>
#include <QtCore/qpropertyanimation.h>
#include <QtCore/qvariantanimation.h>
#include <private/qabstractanimation_p.h>
@@ -190,6 +169,7 @@ private slots:
void totalDuration();
void zeroLoopCount();
void recursiveAnimations();
+ void bindings();
};
void tst_QPropertyAnimation::initTestCase()
@@ -286,16 +266,16 @@ void tst_QPropertyAnimation::statesAndSignals_data()
void tst_QPropertyAnimation::statesAndSignals()
{
QFETCH(bool, uncontrolled);
- QPropertyAnimation *anim;
+ std::unique_ptr<QPropertyAnimation> anim;
if (uncontrolled)
- anim = new UncontrolledAnimation;
+ anim = std::make_unique<UncontrolledAnimation>();
else
- anim = new DummyPropertyAnimation;
+ anim = std::make_unique<DummyPropertyAnimation>();
anim->setDuration(100);
- QSignalSpy finishedSpy(anim, &QPropertyAnimation::finished);
- QSignalSpy runningSpy(anim, &QPropertyAnimation::stateChanged);
- QSignalSpy currentLoopSpy(anim, &QPropertyAnimation::currentLoopChanged);
+ QSignalSpy finishedSpy(anim.get(), &QPropertyAnimation::finished);
+ QSignalSpy runningSpy(anim.get(), &QPropertyAnimation::stateChanged);
+ QSignalSpy currentLoopSpy(anim.get(), &QPropertyAnimation::currentLoopChanged);
QVERIFY(finishedSpy.isValid());
QVERIFY(runningSpy.isValid());
@@ -303,9 +283,9 @@ void tst_QPropertyAnimation::statesAndSignals()
anim->setCurrentTime(1);
anim->setCurrentTime(100);
- QCOMPARE(finishedSpy.count(), 0);
- QCOMPARE(runningSpy.count(), 0);
- QCOMPARE(currentLoopSpy.count(), 0);
+ QCOMPARE(finishedSpy.size(), 0);
+ QCOMPARE(runningSpy.size(), 0);
+ QCOMPARE(currentLoopSpy.size(), 0);
QCOMPARE(anim->state(), QAnimationGroup::Stopped);
anim->setLoopCount(3);
@@ -314,26 +294,26 @@ void tst_QPropertyAnimation::statesAndSignals()
if (uncontrolled)
QSKIP("Uncontrolled animations don't handle looping");
- QCOMPARE(currentLoopSpy.count(), 1);
+ QCOMPARE(currentLoopSpy.size(), 1);
QCOMPARE(anim->currentLoop(), 1);
anim->setCurrentTime(0);
- QCOMPARE(currentLoopSpy.count(), 2);
+ QCOMPARE(currentLoopSpy.size(), 2);
QCOMPARE(anim->currentLoop(), 0);
anim->start();
QCOMPARE(anim->state(), QAnimationGroup::Running);
- QCOMPARE(runningSpy.count(), 1); //anim must have started
+ QCOMPARE(runningSpy.size(), 1); //anim must have started
QCOMPARE(anim->currentLoop(), 0);
runningSpy.clear();
anim->stop();
QCOMPARE(anim->state(), QAnimationGroup::Stopped);
- QCOMPARE(runningSpy.count(), 1); //anim must have stopped
- QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(runningSpy.size(), 1); //anim must have stopped
+ QCOMPARE(finishedSpy.size(), 0);
QCOMPARE(anim->currentLoopTime(), 0);
QCOMPARE(anim->currentLoop(), 0);
- QCOMPARE(currentLoopSpy.count(), 2);
+ QCOMPARE(currentLoopSpy.size(), 2);
runningSpy.clear();
{
@@ -341,33 +321,31 @@ void tst_QPropertyAnimation::statesAndSignals()
anim->start();
timeDriver.wait(1000);
QCOMPARE(anim->state(), QAnimationGroup::Stopped);
- QCOMPARE(runningSpy.count(), 2); //started and stopped again
+ QCOMPARE(runningSpy.size(), 2); //started and stopped again
runningSpy.clear();
- QCOMPARE(finishedSpy.count(), 1);
+ QCOMPARE(finishedSpy.size(), 1);
QCOMPARE(anim->currentLoopTime(), 100);
QCOMPARE(anim->currentLoop(), 2);
- QCOMPARE(currentLoopSpy.count(), 4);
+ QCOMPARE(currentLoopSpy.size(), 4);
anim->start(); // auto-rewinds
QCOMPARE(anim->state(), QAnimationGroup::Running);
QCOMPARE(anim->currentTime(), 0);
QCOMPARE(anim->currentLoop(), 0);
- QCOMPARE(currentLoopSpy.count(), 5);
- QCOMPARE(runningSpy.count(), 1); // anim has started
- QCOMPARE(finishedSpy.count(), 1);
+ QCOMPARE(currentLoopSpy.size(), 5);
+ QCOMPARE(runningSpy.size(), 1); // anim has started
+ QCOMPARE(finishedSpy.size(), 1);
QCOMPARE(anim->currentLoop(), 0);
runningSpy.clear();
timeDriver.wait(1000);
- QCOMPARE(currentLoopSpy.count(), 7);
+ QCOMPARE(currentLoopSpy.size(), 7);
QCOMPARE(anim->state(), QAnimationGroup::Stopped);
QCOMPARE(anim->currentLoop(), 2);
- QCOMPARE(runningSpy.count(), 1); // anim has stopped
- QCOMPARE(finishedSpy.count(), 2);
+ QCOMPARE(runningSpy.size(), 1); // anim has stopped
+ QCOMPARE(finishedSpy.size(), 2);
QCOMPARE(anim->currentLoopTime(), 100);
-
- delete anim;
}
}
@@ -386,8 +364,8 @@ void tst_QPropertyAnimation::deletion1()
anim->setEndValue(20);
anim->setDuration(200);
anim->start();
- QCOMPARE(runningSpy.count(), 1);
- QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(runningSpy.size(), 1);
+ QCOMPARE(finishedSpy.size(), 0);
QVERIFY(anim);
QCOMPARE(anim->state(), QAnimationGroup::Running);
@@ -397,8 +375,8 @@ void tst_QPropertyAnimation::deletion1()
timeDriver.wait(150);
QVERIFY(anim); //The animation should not have been deleted
QCOMPARE(anim->state(), QAnimationGroup::Stopped);
- QCOMPARE(runningSpy.count(), 2);
- QCOMPARE(finishedSpy.count(), 1);
+ QCOMPARE(runningSpy.size(), 2);
+ QCOMPARE(finishedSpy.size(), 1);
anim->start(QVariantAnimation::DeleteWhenStopped);
QVERIFY(anim);
@@ -407,8 +385,8 @@ void tst_QPropertyAnimation::deletion1()
QVERIFY(anim);
QCOMPARE(anim->state(), QAnimationGroup::Running);
timeDriver.wait(150);
- QCOMPARE(runningSpy.count(), 4);
- QCOMPARE(finishedSpy.count(), 2);
+ QCOMPARE(runningSpy.size(), 4);
+ QCOMPARE(finishedSpy.size(), 2);
QVERIFY(!anim); //The animation must have been deleted
delete object;
}
@@ -416,9 +394,10 @@ void tst_QPropertyAnimation::deletion1()
void tst_QPropertyAnimation::deletion2()
{
TestAnimationDriver timeDriver;
- //test that the animation get deleted if the object is deleted
+ // test that the animation does not get deleted if the object is deleted
QObject *object = new QWidget;
QPointer<QPropertyAnimation> anim = new QPropertyAnimation(object,"minimumWidth");
+ QVERIFY(anim->parent() != object);
anim->setStartValue(10);
anim->setEndValue(20);
anim->setDuration(200);
@@ -438,21 +417,25 @@ void tst_QPropertyAnimation::deletion2()
QVERIFY(anim);
QCOMPARE(anim->state(), QAnimationGroup::Running);
- QCOMPARE(runningSpy.count(), 1);
- QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(runningSpy.size(), 1);
+ QCOMPARE(finishedSpy.size(), 0);
//we can't call deletaLater directly because the delete would only happen in the next loop of _this_ event loop
QTimer::singleShot(0, object, SLOT(deleteLater()));
timeDriver.wait(50);
+ QVERIFY(anim);
QVERIFY(!anim->targetObject());
+
+ delete anim;
}
void tst_QPropertyAnimation::deletion3()
{
//test that the stopped signal is emit when the animation is destroyed
TestAnimationDriver timeDriver;
- QObject *object = new QWidget;
+ QWidget w;
+ QObject *object = &w;
QPropertyAnimation *anim = new QPropertyAnimation(object,"minimumWidth");
anim->setStartValue(10);
anim->setEndValue(20);
@@ -468,11 +451,11 @@ void tst_QPropertyAnimation::deletion3()
timeDriver.wait(50);
QCOMPARE(anim->state(), QAnimationGroup::Running);
- QCOMPARE(runningSpy.count(), 1);
- QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(runningSpy.size(), 1);
+ QCOMPARE(finishedSpy.size(), 0);
delete anim;
- QCOMPARE(runningSpy.count(), 2);
- QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(runningSpy.size(), 2);
+ QCOMPARE(finishedSpy.size(), 0);
}
void tst_QPropertyAnimation::duration0()
@@ -564,7 +547,7 @@ void tst_QPropertyAnimation::startWhenAnotherIsRunning()
QVERIFY(runningSpy.isValid());
anim->start(QVariantAnimation::DeleteWhenStopped);
timeDriver.wait(anim->duration());
- QCOMPARE(runningSpy.count(), 2); //started and then stopped
+ QCOMPARE(runningSpy.size(), 2); //started and then stopped
QVERIFY(!anim);
}
{
@@ -576,7 +559,7 @@ void tst_QPropertyAnimation::startWhenAnotherIsRunning()
timeDriver.wait(anim->duration()/2);
QPointer<QVariantAnimation> anim2 = new QPropertyAnimation(&o, "ole");
anim2->setEndValue(100);
- QCOMPARE(runningSpy.count(), 1);
+ QCOMPARE(runningSpy.size(), 1);
QCOMPARE(anim->state(), QVariantAnimation::Running);
//anim2 will interrupt anim1
@@ -925,7 +908,7 @@ void tst_QPropertyAnimation::zeroDurationStart()
anim.start();
//the animation stops immediately
QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
//let's check the first state change
const QVariantList firstChange = spy.first();
@@ -1210,8 +1193,8 @@ void tst_QPropertyAnimation::valueChanged()
QCOMPARE(anim.currentTime(), anim.duration());
//let's check that the values go forward
- QCOMPARE(spy.count(), 6); //we should have got everything from 0 to 5
- for (int i = 0; i < spy.count(); ++i) {
+ QCOMPARE(spy.size(), 6); //we should have got everything from 0 to 5
+ for (int i = 0; i < spy.size(); ++i) {
QCOMPARE(qvariant_cast<QVariant>(spy.at(i).first()).toInt(), i);
}
}
@@ -1327,8 +1310,8 @@ void tst_QPropertyAnimation::totalDuration()
void tst_QPropertyAnimation::zeroLoopCount()
{
- DummyPropertyAnimation* anim;
- anim = new DummyPropertyAnimation;
+ DummyPropertyAnimation animation;
+ auto *anim = &animation;
anim->setStartValue(0);
anim->setDuration(20);
anim->setLoopCount(0);
@@ -1341,15 +1324,15 @@ void tst_QPropertyAnimation::zeroLoopCount()
QCOMPARE(anim->state(), QAnimationGroup::Stopped);
QCOMPARE(anim->currentValue().toInt(), 0);
- QCOMPARE(runningSpy.count(), 0);
- QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(runningSpy.size(), 0);
+ QCOMPARE(finishedSpy.size(), 0);
anim->start();
QCOMPARE(anim->state(), QAnimationGroup::Stopped);
QCOMPARE(anim->currentValue().toInt(), 0);
- QCOMPARE(runningSpy.count(), 0);
- QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(runningSpy.size(), 0);
+ QCOMPARE(finishedSpy.size(), 0);
}
@@ -1396,6 +1379,29 @@ void tst_QPropertyAnimation::recursiveAnimations()
QCOMPARE(o.y(), qreal(4000));
}
+void tst_QPropertyAnimation::bindings()
+{
+ std::unique_ptr<AnimationObject> o1(new AnimationObject);
+ std::unique_ptr<AnimationObject> o2(new AnimationObject);
+ QPropertyAnimation a(o1.get(), "value");
+
+ QTestPrivate::testReadWritePropertyBasics<QPropertyAnimation, QByteArray>(
+ a, QByteArray("realValue"), QByteArray("value"), "propertyName");
+ if (QTest::currentTestFailed()) {
+ qDebug() << "Failed property test for QPropertyAnimation::propertyName";
+ return;
+ }
+ QTestPrivate::testReadWritePropertyBasics<QPropertyAnimation, QObject *>(a, o2.get(), o1.get(),
+ "targetObject");
+ if (QTest::currentTestFailed()) {
+ qDebug() << "Failed property test for QPropertyAnimation::targetObject";
+ return;
+ }
+
+ a.setTargetObject(o1.get());
+ o1.reset();
+ QCOMPARE(a.targetObject(), nullptr);
+}
QTEST_MAIN(tst_QPropertyAnimation)
#include "tst_qpropertyanimation.moc"
diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST b/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST
index f07c0ec4a1..79053cbf68 100644
--- a/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST
+++ b/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST
@@ -1,5 +1,4 @@
[finishWithUncontrolledAnimation]
-windows-10 msvc-2015
macos
[groupWithZeroDurationAnimations]
macos
diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/CMakeLists.txt b/tests/auto/corelib/animation/qsequentialanimationgroup/CMakeLists.txt
index e56f9f6ff8..e2ebe8baa9 100644
--- a/tests/auto/corelib/animation/qsequentialanimationgroup/CMakeLists.txt
+++ b/tests/auto/corelib/animation/qsequentialanimationgroup/CMakeLists.txt
@@ -1,10 +1,19 @@
-# Generated from qsequentialanimationgroup.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qsequentialanimationgroup Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qsequentialanimationgroup LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qsequentialanimationgroup
SOURCES
tst_qsequentialanimationgroup.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/qsequentialanimationgroup.pro b/tests/auto/corelib/animation/qsequentialanimationgroup/qsequentialanimationgroup.pro
deleted file mode 100644
index b0271e8ea2..0000000000
--- a/tests/auto/corelib/animation/qsequentialanimationgroup/qsequentialanimationgroup.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qsequentialanimationgroup
-QT = core testlib
-SOURCES = tst_qsequentialanimationgroup.cpp
diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
index 1a03254e0b..7555622162 100644
--- a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
+++ b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
@@ -1,34 +1,18 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
+#include <QtTest/private/qpropertytesthelper_p.h>
+
+#include <QVariantAnimation>
+#include <QProperty>
+#include <QPropertyAnimation>
+#include <QSignalSpy>
+#include <QParallelAnimationGroup>
+
#include <QtCore/qanimationgroup.h>
#include <QtCore/qsequentialanimationgroup.h>
+#include <QtCore/qscopeguard.h>
Q_DECLARE_METATYPE(QAbstractAnimation::State)
@@ -65,6 +49,7 @@ private slots:
void insertAnimation();
void clear();
void pauseResume();
+ void bindings();
};
void tst_QSequentialAnimationGroup::initTestCase()
@@ -568,8 +553,8 @@ using StateList = QList<QAbstractAnimation::State>;
static bool compareStates(const QSignalSpy& spy, const StateList &expectedStates)
{
bool equals = true;
- for (int i = 0; i < qMax(expectedStates.count(), spy.count()); ++i) {
- if (i >= spy.count() || i >= expectedStates.count()) {
+ for (int i = 0; i < qMax(expectedStates.size(), spy.size()); ++i) {
+ if (i >= spy.size() || i >= expectedStates.size()) {
equals = false;
break;
}
@@ -584,14 +569,14 @@ static bool compareStates(const QSignalSpy& spy, const StateList &expectedStates
if (!equals) {
const char *stateStrings[] = {"Stopped", "Paused", "Running"};
QString e,a;
- for (int i = 0; i < qMax(expectedStates.count(), spy.count()); ++i) {
- if (i < expectedStates.count()) {
+ for (int i = 0; i < qMax(expectedStates.size(), spy.size()); ++i) {
+ if (i < expectedStates.size()) {
int exp = int(expectedStates.at(i));
if (!e.isEmpty())
e += QLatin1String(", ");
e += QLatin1String(stateStrings[exp]);
}
- if (i < spy.count()) {
+ if (i < spy.size()) {
QList<QVariant> args = spy.at(i);
QAbstractAnimation::State actual = qvariant_cast<QAbstractAnimation::State>(args.value(1));
if (!a.isEmpty())
@@ -606,7 +591,7 @@ static bool compareStates(const QSignalSpy& spy, const StateList &expectedStates
}
qDebug("\n"
"expected (count == %zd): %s\n"
- "actual (count == %zd): %s\n", size_t(expectedStates.count()), qPrintable(e), size_t(spy.count()), qPrintable(a));
+ "actual (count == %zd): %s\n", size_t(expectedStates.size()), qPrintable(e), size_t(spy.size()), qPrintable(a));
}
return equals;
}
@@ -653,8 +638,8 @@ void tst_QSequentialAnimationGroup::pauseAndResume()
QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
QCOMPARE(a3_s_o1->state(), QAnimationGroup::Paused);
- QCOMPARE(a1StateChangedSpy.count(), 5); // Running,Paused,Stopped,Running,Stopped
- QCOMPARE(seqStateChangedSpy.count(), 2); // Running,Paused
+ QCOMPARE(a1StateChangedSpy.size(), 5); // Running,Paused,Stopped,Running,Stopped
+ QCOMPARE(seqStateChangedSpy.size(), 2); // Running,Paused
QVERIFY(compareStates(a1StateChangedSpy, (StateList() << QAbstractAnimation::Running
<< QAbstractAnimation::Paused
@@ -695,7 +680,7 @@ void tst_QSequentialAnimationGroup::pauseAndResume()
QCOMPARE(a3_s_o1->currentLoop(), 0);
QVERIFY(a3_s_o1->currentLoopTime() >= 1);
- QCOMPARE(seqStateChangedSpy.count(), 3); // Running,Paused,Running
+ QCOMPARE(seqStateChangedSpy.size(), 3); // Running,Paused,Running
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(seqStateChangedSpy.at(2).first()),
QAnimationGroup::Running);
@@ -716,13 +701,13 @@ void tst_QSequentialAnimationGroup::pauseAndResume()
QCOMPARE(a3_s_o1->currentLoop(), 0);
QVERIFY(a3_s_o1->currentLoopTime() >= 1);
- QCOMPARE(seqStateChangedSpy.count(), 4); // Running,Paused,Running,Paused
+ QCOMPARE(seqStateChangedSpy.size(), 4); // Running,Paused,Running,Paused
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(seqStateChangedSpy.at(3).first()),
QAnimationGroup::Paused);
group.stop();
- QCOMPARE(seqStateChangedSpy.count(), 5); // Running,Paused,Running,Paused,Stopped
+ QCOMPARE(seqStateChangedSpy.size(), 5); // Running,Paused,Running,Paused,Stopped
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(seqStateChangedSpy.at(4).first()),
QAnimationGroup::Stopped);
}
@@ -738,12 +723,12 @@ void tst_QSequentialAnimationGroup::restart()
QVERIFY(seqStateChangedSpy.isValid());
QVariantAnimation *anims[3];
- QSignalSpy *animsStateChanged[3];
+ QScopedPointer<QSignalSpy> animsStateChanged[3];
for (int i = 0; i < 3; i++) {
anims[i] = new DummyPropertyAnimation;
anims[i]->setDuration(100);
- animsStateChanged[i] = new QSignalSpy(anims[i], &QVariantAnimation::stateChanged);
+ animsStateChanged[i].reset(new QSignalSpy(anims[i], &QVariantAnimation::stateChanged));
QVERIFY(animsStateChanged[i]->isValid());
}
@@ -766,7 +751,7 @@ void tst_QSequentialAnimationGroup::restart()
QTRY_COMPARE(group.state(), QAnimationGroup::Stopped);
for (int i = 0; i < 3; i++) {
- QCOMPARE(animsStateChanged[i]->count(), 4);
+ QCOMPARE(animsStateChanged[i]->size(), 4);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(animsStateChanged[i]->at(0).first()),
QAnimationGroup::Running);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(animsStateChanged[i]->at(1).first()),
@@ -777,22 +762,22 @@ void tst_QSequentialAnimationGroup::restart()
QAnimationGroup::Stopped);
}
- QCOMPARE(seqStateChangedSpy.count(), 2);
+ QCOMPARE(seqStateChangedSpy.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(seqStateChangedSpy.at(0).first()),
QAnimationGroup::Running);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(seqStateChangedSpy.at(1).first()),
QAnimationGroup::Stopped);
- QCOMPARE(seqCurrentAnimChangedSpy.count(), 6);
- for(int i=0; i<seqCurrentAnimChangedSpy.count(); i++)
+ QCOMPARE(seqCurrentAnimChangedSpy.size(), 6);
+ for(int i=0; i<seqCurrentAnimChangedSpy.size(); i++)
QCOMPARE(static_cast<QAbstractAnimation*>(anims[i%3]), qvariant_cast<QAbstractAnimation*>(seqCurrentAnimChangedSpy.at(i).at(0)));
group.start();
- QCOMPARE(animsStateChanged[0]->count(), 5);
- QCOMPARE(animsStateChanged[1]->count(), 4);
- QCOMPARE(animsStateChanged[2]->count(), 4);
- QCOMPARE(seqStateChangedSpy.count(), 3);
+ QCOMPARE(animsStateChanged[0]->size(), 5);
+ QCOMPARE(animsStateChanged[1]->size(), 4);
+ QCOMPARE(animsStateChanged[2]->size(), 4);
+ QCOMPARE(seqStateChangedSpy.size(), 3);
}
void tst_QSequentialAnimationGroup::looping()
@@ -848,21 +833,21 @@ void tst_QSequentialAnimationGroup::looping()
QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
QCOMPARE(a3_s_o1->state(), QAnimationGroup::Paused);
- QCOMPARE(a1Spy.count(), 5); // Running,Paused,Stopped,Running,Stopped
+ QCOMPARE(a1Spy.size(), 5); // Running,Paused,Stopped,Running,Stopped
QVERIFY(compareStates(a1Spy, (StateList() << QAbstractAnimation::Running
<< QAbstractAnimation::Paused
<< QAbstractAnimation::Stopped
<< QAbstractAnimation::Running
<< QAbstractAnimation::Stopped)));
- QCOMPARE(a2Spy.count(), 4); // Running,Stopped,Running,Stopped
+ QCOMPARE(a2Spy.size(), 4); // Running,Stopped,Running,Stopped
QVERIFY(compareStates(a3Spy, (StateList() << QAbstractAnimation::Running
<< QAbstractAnimation::Stopped
<< QAbstractAnimation::Running
<< QAbstractAnimation::Paused)));
- QCOMPARE(seqSpy.count(), 2); // Running,Paused
- QCOMPARE(groupSpy.count(), 2); // Running,Paused
+ QCOMPARE(seqSpy.size(), 2); // Running,Paused
+ QCOMPARE(groupSpy.size(), 2); // Running,Paused
// Looping, current time = duration + 1
group.setCurrentTime(group.duration() + 1);
@@ -883,8 +868,8 @@ void tst_QSequentialAnimationGroup::looping()
QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
QCOMPARE(a3_s_o1->state(), QAnimationGroup::Stopped);
- QCOMPARE(a1Spy.count(), 7); // Running,Paused,Stopped,Running,Stopped,Running,Stopped
- QCOMPARE(a2Spy.count(), 4); // Running, Stopped, Running, Stopped
+ QCOMPARE(a1Spy.size(), 7); // Running,Paused,Stopped,Running,Stopped,Running,Stopped
+ QCOMPARE(a2Spy.size(), 4); // Running, Stopped, Running, Stopped
QVERIFY(compareStates(a3Spy, (StateList() << QAbstractAnimation::Running
<< QAbstractAnimation::Stopped
<< QAbstractAnimation::Running
@@ -895,7 +880,7 @@ void tst_QSequentialAnimationGroup::looping()
<< QAbstractAnimation::Stopped
<< QAbstractAnimation::Running
<< QAbstractAnimation::Paused)));
- QCOMPARE(groupSpy.count(), 2);
+ QCOMPARE(groupSpy.size(), 2);
}
void tst_QSequentialAnimationGroup::startDelay()
@@ -1094,8 +1079,8 @@ void tst_QSequentialAnimationGroup::updateChildrenWithRunningGroup()
QVERIFY(groupStateChangedSpy.isValid());
QVERIFY(childStateChangedSpy.isValid());
- QCOMPARE(groupStateChangedSpy.count(), 0);
- QCOMPARE(childStateChangedSpy.count(), 0);
+ QCOMPARE(groupStateChangedSpy.size(), 0);
+ QCOMPARE(childStateChangedSpy.size(), 0);
QCOMPARE(group.state(), QAnimationGroup::Stopped);
QCOMPARE(anim.state(), QAnimationGroup::Stopped);
@@ -1106,8 +1091,8 @@ void tst_QSequentialAnimationGroup::updateChildrenWithRunningGroup()
QCOMPARE(group.state(), QAnimationGroup::Running);
QCOMPARE(anim.state(), QAnimationGroup::Running);
- QCOMPARE(groupStateChangedSpy.count(), 1);
- QCOMPARE(childStateChangedSpy.count(), 1);
+ QCOMPARE(groupStateChangedSpy.size(), 1);
+ QCOMPARE(childStateChangedSpy.size(), 1);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(groupStateChangedSpy.at(0).first()),
QAnimationGroup::Running);
@@ -1117,8 +1102,8 @@ void tst_QSequentialAnimationGroup::updateChildrenWithRunningGroup()
// starting directly a running child will not have any effect
anim.start();
- QCOMPARE(groupStateChangedSpy.count(), 1);
- QCOMPARE(childStateChangedSpy.count(), 1);
+ QCOMPARE(groupStateChangedSpy.size(), 1);
+ QCOMPARE(childStateChangedSpy.size(), 1);
anim.pause();
@@ -1261,8 +1246,8 @@ void tst_QSequentialAnimationGroup::startGroupWithRunningChild()
QVERIFY(stateChangedSpy1.isValid());
QVERIFY(stateChangedSpy2.isValid());
- QCOMPARE(stateChangedSpy1.count(), 0);
- QCOMPARE(stateChangedSpy2.count(), 0);
+ QCOMPARE(stateChangedSpy1.size(), 0);
+ QCOMPARE(stateChangedSpy2.size(), 0);
QCOMPARE(group.state(), QAnimationGroup::Stopped);
QCOMPARE(anim1->state(), QAnimationGroup::Stopped);
QCOMPARE(anim2->state(), QAnimationGroup::Stopped);
@@ -1300,7 +1285,7 @@ void tst_QSequentialAnimationGroup::startGroupWithRunningChild()
QCOMPARE(group.state(), QAnimationGroup::Running);
QCOMPARE(anim2->state(), QAnimationGroup::Running);
- QCOMPARE(stateChangedSpy2.count(), 4);
+ QCOMPARE(stateChangedSpy2.size(), 4);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy2.at(2).first()),
QAnimationGroup::Stopped);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy2.at(3).first()),
@@ -1340,7 +1325,7 @@ void tst_QSequentialAnimationGroup::zeroDurationAnimation()
group.setLoopCount(2);
group.start();
- QCOMPARE(stateChangedSpy.count(), 2);
+ QCOMPARE(stateChangedSpy.size(), 2);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy.at(0).first()),
QAnimationGroup::Running);
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(stateChangedSpy.at(1).first()),
@@ -1417,7 +1402,7 @@ void tst_QSequentialAnimationGroup::finishWithUncontrolledAnimation()
const int actualDuration = notTimeDriven.currentLoopTime();
QCOMPARE(group.state(), QAnimationGroup::Stopped);
QCOMPARE(group.currentLoopTime(), actualDuration);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
//2nd case:
// lets make sure the seeking will work again
@@ -1433,54 +1418,62 @@ void tst_QSequentialAnimationGroup::finishWithUncontrolledAnimation()
//3rd case:
//now let's add a perfectly defined animation at the end
- QCOMPARE(animStateChangedSpy.count(), 0);
+ QCOMPARE(animStateChangedSpy.size(), 0);
group.start();
QCOMPARE(group.state(), QAnimationGroup::Running);
QCOMPARE(notTimeDriven.state(), QAnimationGroup::Running);
QCOMPARE(group.currentLoopTime(), 0);
QCOMPARE(notTimeDriven.currentLoopTime(), 0);
- QCOMPARE(animStateChangedSpy.count(), 0);
+ QCOMPARE(animStateChangedSpy.size(), 0);
QTest::qWait(300); //wait for the end of notTimeDriven
QTRY_COMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
QCOMPARE(group.state(), QAnimationGroup::Running);
QCOMPARE(anim.state(), QAnimationGroup::Running);
QCOMPARE(group.currentAnimation(), static_cast<QAbstractAnimation*>(&anim));
- QCOMPARE(animStateChangedSpy.count(), 1);
+ QCOMPARE(animStateChangedSpy.size(), 1);
QTest::qWait(300); //wait for the end of anim
QTRY_COMPARE(anim.state(), QAnimationGroup::Stopped);
QCOMPARE(anim.currentLoopTime(), anim.duration());
//we should simply be at the end
- QCOMPARE(spy.count(), 1);
- QCOMPARE(animStateChangedSpy.count(), 2);
+ QCOMPARE(spy.size(), 1);
+ QCOMPARE(animStateChangedSpy.size(), 2);
QCOMPARE(group.currentLoopTime(), notTimeDriven.currentLoopTime() + anim.currentLoopTime());
}
void tst_QSequentialAnimationGroup::addRemoveAnimation()
{
//this test is specific to the sequential animation group
+ QPointer<QAbstractAnimation> anim0 = new QPropertyAnimation;
+ QPointer<QAbstractAnimation> anim1 = new QPropertyAnimation;
+ QPointer<QAbstractAnimation> anim2 = new QPropertyAnimation;
+
+ const auto guard = qScopeGuard([&]() {
+ // If they don't belong to a group when the function returns, we have to delete.
+ delete anim0.data();
+ delete anim1.data();
+ delete anim2.data();
+ });
+
QSequentialAnimationGroup group;
QCOMPARE(group.duration(), 0);
QCOMPARE(group.currentLoopTime(), 0);
- QAbstractAnimation *anim1 = new QPropertyAnimation;
group.addAnimation(anim1);
QCOMPARE(group.duration(), 250);
QCOMPARE(group.currentLoopTime(), 0);
QCOMPARE(group.currentAnimation(), anim1);
//let's append an animation
- QAbstractAnimation *anim2 = new QPropertyAnimation;
group.addAnimation(anim2);
QCOMPARE(group.duration(), 500);
QCOMPARE(group.currentLoopTime(), 0);
QCOMPARE(group.currentAnimation(), anim1);
//let's prepend an animation
- QAbstractAnimation *anim0 = new QPropertyAnimation;
group.insertAnimation(0, anim0);
QCOMPARE(group.duration(), 750);
QCOMPARE(group.currentLoopTime(), 0);
@@ -1599,7 +1592,7 @@ void tst_QSequentialAnimationGroup::clear()
{
SequentialAnimationGroup group;
QPointer<QAbstractAnimation> anim1 = new DummyPropertyAnimation(&group);
- group.connect(anim1, SIGNAL(finished()), SLOT(clear()));
+ connect(anim1, &QAbstractAnimation::finished, &group, &QSequentialAnimationGroup::clear);
new DummyPropertyAnimation(&group);
QCOMPARE(group.animationCount(), 2);
@@ -1632,7 +1625,7 @@ void tst_QSequentialAnimationGroup::pauseResume()
QTest::qWait(100);
QTRY_COMPARE(group.state(), QAnimationGroup::Running);
QCOMPARE(anim->state(), QAnimationGroup::Running);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
const int currentTime = group.currentLoopTime();
QCOMPARE(anim->currentLoopTime(), currentTime);
@@ -1642,7 +1635,7 @@ void tst_QSequentialAnimationGroup::pauseResume()
QCOMPARE(group.currentLoopTime(), currentTime);
QCOMPARE(anim->state(), QAnimationGroup::Paused);
QCOMPARE(anim->currentLoopTime(), currentTime);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
group.resume();
@@ -1650,7 +1643,59 @@ void tst_QSequentialAnimationGroup::pauseResume()
QCOMPARE(group.currentLoopTime(), currentTime);
QCOMPARE(anim->state(), QAnimationGroup::Running);
QCOMPARE(anim->currentLoopTime(), currentTime);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
+}
+
+void tst_QSequentialAnimationGroup::bindings()
+{
+ // create a group consisting of three animations
+ QSequentialAnimationGroup group;
+ QPointer<QAbstractAnimation> anim1 = new DummyPropertyAnimation(&group);
+ QCOMPARE(group.animationCount(), 1);
+ QPointer<QAbstractAnimation> anim2 = new DummyPropertyAnimation(&group);
+ QCOMPARE(group.animationCount(), 2);
+ QPointer<QAbstractAnimation> anim3 = new DummyPropertyAnimation(&group);
+ QCOMPARE(group.animationCount(), 3);
+
+ // bind a QProperty to group.currentAnimation
+ QProperty<QAbstractAnimation *> currentAnim;
+ currentAnim.setBinding([&]() { return group.currentAnimation(); });
+
+ // check that everything behaves as expected
+ QSignalSpy spy(&group, &QSequentialAnimationGroup::currentAnimationChanged);
+ QVERIFY(spy.isValid());
+
+ int totalDuration = group.duration();
+
+ group.setCurrentTime(int(totalDuration * 0.5 / 3));
+ QCOMPARE(currentAnim.value(), anim1.get());
+ QCOMPARE(spy.size(), 0);
+
+ group.setCurrentTime(int(totalDuration * 1.5 / 3));
+ QCOMPARE(currentAnim.value(), anim2.get());
+ QCOMPARE(spy.size(), 1);
+
+ // change to other style of formulating a binding to test both
+ currentAnim.setBinding(group.bindableCurrentAnimation().makeBinding());
+
+ group.setCurrentTime(int(totalDuration * 2.5 / 3));
+ QCOMPARE(currentAnim.value(), anim3.get());
+ QCOMPARE(spy.size(), 2);
+
+ // currentAnimation is read-only. Binding it to something should have no effect
+ QProperty<QAbstractAnimation *> leader;
+ group.bindableCurrentAnimation().setBinding([&]() { return leader.value(); });
+
+ QCOMPARE(group.currentAnimation(), anim3.get());
+
+ QTestPrivate::testReadOnlyPropertyBasics(group, anim3.get(), anim2.get(), "currentAnimation",
+ [&group, totalDuration]() {
+ group.setCurrentTime(int(totalDuration * 1.5 / 3));
+ });
+ if (QTest::currentTestFailed()) {
+ qDebug("Failed property test for QSequentialAnimationGroup::currentAnimation");
+ return;
+ }
}
QTEST_MAIN(tst_QSequentialAnimationGroup)
diff --git a/tests/auto/corelib/animation/qvariantanimation/CMakeLists.txt b/tests/auto/corelib/animation/qvariantanimation/CMakeLists.txt
index aa85e1fb5c..9abc16040f 100644
--- a/tests/auto/corelib/animation/qvariantanimation/CMakeLists.txt
+++ b/tests/auto/corelib/animation/qvariantanimation/CMakeLists.txt
@@ -1,10 +1,19 @@
-# Generated from qvariantanimation.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qvariantanimation Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qvariantanimation LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qvariantanimation
SOURCES
tst_qvariantanimation.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/animation/qvariantanimation/qvariantanimation.pro b/tests/auto/corelib/animation/qvariantanimation/qvariantanimation.pro
deleted file mode 100644
index b82d3bc6e0..0000000000
--- a/tests/auto/corelib/animation/qvariantanimation/qvariantanimation.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qvariantanimation
-QT = core testlib
-SOURCES = tst_qvariantanimation.cpp
diff --git a/tests/auto/corelib/animation/qvariantanimation/tst_qvariantanimation.cpp b/tests/auto/corelib/animation/qvariantanimation/tst_qvariantanimation.cpp
index 724db5ae21..661c4b8108 100644
--- a/tests/auto/corelib/animation/qvariantanimation/tst_qvariantanimation.cpp
+++ b/tests/auto/corelib/animation/qvariantanimation/tst_qvariantanimation.cpp
@@ -1,34 +1,10 @@
-/****************************************************************************
-**
-** 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/qvariantanimation.h>
-#include <QtTest>
+#include <QTest>
+#include <QtTest/private/qpropertytesthelper_p.h>
class tst_QVariantAnimation : public QObject
{
@@ -44,6 +20,8 @@ private slots:
void keyValues();
void duration();
void interpolation();
+ void durationBindings();
+ void easingCurveBindings();
};
class TestableQVariantAnimation : public QVariantAnimation
@@ -154,6 +132,32 @@ void tst_QVariantAnimation::interpolation()
QCOMPARE(pointAnim.currentValue().toPoint(), QPoint(50, 50));
}
+void tst_QVariantAnimation::durationBindings()
+{
+ QVariantAnimation animation;
+
+ // duration property
+ QProperty<int> duration;
+ animation.bindableDuration().setBinding(Qt::makePropertyBinding(duration));
+
+ // negative values must be ignored
+ QTest::ignoreMessage(QtWarningMsg,
+ "QVariantAnimation::setDuration: cannot set a negative duration");
+ duration = -1;
+ QVERIFY(animation.duration() != duration);
+
+ QTestPrivate::testReadWritePropertyBasics(animation, 42, 43, "duration");
+}
+
+void tst_QVariantAnimation::easingCurveBindings()
+{
+ QVariantAnimation animation;
+
+ QTestPrivate::testReadWritePropertyBasics(animation, QEasingCurve(QEasingCurve::InQuad),
+ QEasingCurve(QEasingCurve::BezierSpline),
+ "easingCurve");
+}
+
QTEST_MAIN(tst_QVariantAnimation)
#include "tst_qvariantanimation.moc"