mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-04 00:05:25 +08:00
qt 6.5.1 original
This commit is contained in:
12
tests/auto/corelib/animation/CMakeLists.txt
Normal file
12
tests/auto/corelib/animation/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
add_subdirectory(qabstractanimation)
|
||||
add_subdirectory(qanimationgroup)
|
||||
add_subdirectory(qparallelanimationgroup)
|
||||
add_subdirectory(qpauseanimation)
|
||||
add_subdirectory(qsequentialanimationgroup)
|
||||
add_subdirectory(qvariantanimation)
|
||||
if(TARGET Qt::Widgets)
|
||||
add_subdirectory(qpropertyanimation)
|
||||
endif()
|
@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qabstractanimation Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qabstractanimation
|
||||
SOURCES
|
||||
tst_qabstractanimation.cpp
|
||||
LIBRARIES
|
||||
Qt::TestPrivate
|
||||
)
|
@ -0,0 +1,298 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
|
||||
#include <QtCore/qabstractanimation.h>
|
||||
#include <QtCore/qanimationgroup.h>
|
||||
#include <QTest>
|
||||
#include <QtTest/private/qpropertytesthelper_p.h>
|
||||
|
||||
class tst_QAbstractAnimation : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void construction();
|
||||
void destruction();
|
||||
void currentLoop();
|
||||
void currentLoopTime();
|
||||
void currentTime();
|
||||
void direction();
|
||||
void group();
|
||||
void loopCount();
|
||||
void state();
|
||||
void totalDuration();
|
||||
void avoidJumpAtStart();
|
||||
void avoidJumpAtStartWithStop();
|
||||
void avoidJumpAtStartWithRunning();
|
||||
void stateBinding();
|
||||
void loopCountBinding();
|
||||
void currentTimeBinding();
|
||||
void currentLoopBinding();
|
||||
void directionBinding();
|
||||
};
|
||||
|
||||
class TestableQAbstractAnimation : public QAbstractAnimation
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestableQAbstractAnimation() : m_duration(10) {}
|
||||
virtual ~TestableQAbstractAnimation() override { }
|
||||
|
||||
int duration() const override { return m_duration; }
|
||||
virtual void updateCurrentTime(int) override {}
|
||||
|
||||
void setDuration(int duration) { m_duration = duration; }
|
||||
private:
|
||||
int m_duration;
|
||||
};
|
||||
|
||||
class DummyQAnimationGroup : public QAnimationGroup
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
int duration() const override { return 10; }
|
||||
virtual void updateCurrentTime(int) override {}
|
||||
};
|
||||
|
||||
void tst_QAbstractAnimation::construction()
|
||||
{
|
||||
TestableQAbstractAnimation anim;
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::destruction()
|
||||
{
|
||||
TestableQAbstractAnimation *anim = new TestableQAbstractAnimation;
|
||||
delete anim;
|
||||
|
||||
// Animations should stop when deleted
|
||||
auto *stopWhenDeleted = new TestableQAbstractAnimation;
|
||||
QAbstractAnimation::State lastOldState, lastNewState;
|
||||
QObject::connect(stopWhenDeleted, &QAbstractAnimation::stateChanged,
|
||||
[&](QAbstractAnimation::State newState, QAbstractAnimation::State oldState) {
|
||||
lastNewState = newState;
|
||||
lastOldState = oldState;
|
||||
});
|
||||
stopWhenDeleted->start();
|
||||
QCOMPARE(lastOldState, QAbstractAnimation::Stopped);
|
||||
QCOMPARE(lastNewState, QAbstractAnimation::Running);
|
||||
delete stopWhenDeleted;
|
||||
QCOMPARE(lastOldState, QAbstractAnimation::Running);
|
||||
QCOMPARE(lastNewState, QAbstractAnimation::Stopped);
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::currentLoop()
|
||||
{
|
||||
TestableQAbstractAnimation anim;
|
||||
QCOMPARE(anim.currentLoop(), 0);
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::currentLoopTime()
|
||||
{
|
||||
TestableQAbstractAnimation anim;
|
||||
QCOMPARE(anim.currentLoopTime(), 0);
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::currentTime()
|
||||
{
|
||||
TestableQAbstractAnimation anim;
|
||||
QCOMPARE(anim.currentTime(), 0);
|
||||
anim.setCurrentTime(10);
|
||||
QCOMPARE(anim.currentTime(), 10);
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::direction()
|
||||
{
|
||||
TestableQAbstractAnimation anim;
|
||||
QCOMPARE(anim.direction(), QAbstractAnimation::Forward);
|
||||
anim.setDirection(QAbstractAnimation::Backward);
|
||||
QCOMPARE(anim.direction(), QAbstractAnimation::Backward);
|
||||
anim.setDirection(QAbstractAnimation::Forward);
|
||||
QCOMPARE(anim.direction(), QAbstractAnimation::Forward);
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::group()
|
||||
{
|
||||
TestableQAbstractAnimation *anim = new TestableQAbstractAnimation;
|
||||
DummyQAnimationGroup group;
|
||||
group.addAnimation(anim);
|
||||
QCOMPARE(anim->group(), &group);
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::loopCount()
|
||||
{
|
||||
TestableQAbstractAnimation anim;
|
||||
QCOMPARE(anim.loopCount(), 1);
|
||||
anim.setLoopCount(10);
|
||||
QCOMPARE(anim.loopCount(), 10);
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::state()
|
||||
{
|
||||
TestableQAbstractAnimation anim;
|
||||
QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::totalDuration()
|
||||
{
|
||||
TestableQAbstractAnimation anim;
|
||||
QCOMPARE(anim.duration(), 10);
|
||||
anim.setLoopCount(5);
|
||||
QCOMPARE(anim.totalDuration(), 50);
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::avoidJumpAtStart()
|
||||
{
|
||||
TestableQAbstractAnimation anim;
|
||||
anim.setDuration(1000);
|
||||
|
||||
/*
|
||||
the timer shouldn't actually start until we hit the event loop,
|
||||
so the sleep should have no effect
|
||||
*/
|
||||
anim.start();
|
||||
QTest::qSleep(300);
|
||||
QCoreApplication::processEvents();
|
||||
QVERIFY(anim.currentTime() < 50);
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::avoidJumpAtStartWithStop()
|
||||
{
|
||||
TestableQAbstractAnimation anim;
|
||||
anim.setDuration(1000);
|
||||
|
||||
TestableQAbstractAnimation anim2;
|
||||
anim2.setDuration(1000);
|
||||
|
||||
TestableQAbstractAnimation anim3;
|
||||
anim3.setDuration(1000);
|
||||
|
||||
anim.start();
|
||||
QTest::qWait(300);
|
||||
anim.stop();
|
||||
|
||||
/*
|
||||
same test as avoidJumpAtStart, but after there is a
|
||||
running animation that is stopped
|
||||
*/
|
||||
anim2.start();
|
||||
QTest::qSleep(300);
|
||||
anim3.start();
|
||||
QCoreApplication::processEvents();
|
||||
QVERIFY(anim2.currentTime() < 50);
|
||||
QVERIFY(anim3.currentTime() < 50);
|
||||
}
|
||||
|
||||
void tst_QAbstractAnimation::avoidJumpAtStartWithRunning()
|
||||
{
|
||||
TestableQAbstractAnimation anim;
|
||||
anim.setDuration(2000);
|
||||
|
||||
TestableQAbstractAnimation anim2;
|
||||
anim2.setDuration(1000);
|
||||
|
||||
TestableQAbstractAnimation anim3;
|
||||
anim3.setDuration(1000);
|
||||
|
||||
anim.start();
|
||||
QTest::qWait(300); //make sure timer has started
|
||||
|
||||
/*
|
||||
same test as avoidJumpAtStart, but with an
|
||||
existing running animation
|
||||
*/
|
||||
anim2.start();
|
||||
QTest::qSleep(300); //force large delta for next tick
|
||||
anim3.start();
|
||||
QCoreApplication::processEvents();
|
||||
QVERIFY(anim2.currentTime() < 50);
|
||||
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)
|
||||
|
||||
#include "tst_qabstractanimation.moc"
|
11
tests/auto/corelib/animation/qanimationgroup/CMakeLists.txt
Normal file
11
tests/auto/corelib/animation/qanimationgroup/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qanimationgroup Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qanimationgroup
|
||||
SOURCES
|
||||
tst_qanimationgroup.cpp
|
||||
)
|
@ -0,0 +1,357 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QTest>
|
||||
#include <QPauseAnimation>
|
||||
#include <QVariantAnimation>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QSignalSpy>
|
||||
|
||||
#include <QtCore/qanimationgroup.h>
|
||||
#include <QtCore/qsequentialanimationgroup.h>
|
||||
#include <QtCore/qparallelanimationgroup.h>
|
||||
|
||||
Q_DECLARE_METATYPE(QAbstractAnimation::State)
|
||||
|
||||
class tst_QAnimationGroup : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public Q_SLOTS:
|
||||
void initTestCase();
|
||||
|
||||
private slots:
|
||||
void construction();
|
||||
void emptyGroup();
|
||||
void setCurrentTime();
|
||||
void setParentAutoAdd();
|
||||
void beginNestedGroup();
|
||||
void addChildTwice();
|
||||
void loopWithoutStartValue();
|
||||
};
|
||||
|
||||
void tst_QAnimationGroup::initTestCase()
|
||||
{
|
||||
qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
|
||||
}
|
||||
|
||||
void tst_QAnimationGroup::construction()
|
||||
{
|
||||
QSequentialAnimationGroup animationgroup;
|
||||
}
|
||||
|
||||
class AnimationObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int value READ value WRITE setValue)
|
||||
public:
|
||||
AnimationObject(int startValue = 0)
|
||||
: v(startValue)
|
||||
{ }
|
||||
|
||||
int value() const { return v; }
|
||||
void setValue(int value) { v = value; }
|
||||
|
||||
int v;
|
||||
};
|
||||
|
||||
class TestAnimation : public QVariantAnimation
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual void updateCurrentValue(const QVariant &value) override { Q_UNUSED(value)};
|
||||
virtual void updateState(QAbstractAnimation::State oldState,
|
||||
QAbstractAnimation::State newState) override
|
||||
{
|
||||
Q_UNUSED(oldState);
|
||||
Q_UNUSED(newState);
|
||||
};
|
||||
};
|
||||
|
||||
class UncontrolledAnimation : public QPropertyAnimation
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = nullptr)
|
||||
: QPropertyAnimation(target, propertyName, parent), id(0)
|
||||
{
|
||||
setDuration(250);
|
||||
}
|
||||
|
||||
int duration() const override { return -1; /* not time driven */ }
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *event) override
|
||||
{
|
||||
if (event->timerId() == id)
|
||||
stop();
|
||||
}
|
||||
|
||||
void updateRunning(bool running)
|
||||
{
|
||||
if (running) {
|
||||
id = startTimer(500);
|
||||
} else {
|
||||
killTimer(id);
|
||||
id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int id;
|
||||
};
|
||||
|
||||
void tst_QAnimationGroup::emptyGroup()
|
||||
{
|
||||
QSequentialAnimationGroup group;
|
||||
QSignalSpy groupStateChangedSpy(&group, &QSequentialAnimationGroup::stateChanged);
|
||||
QVERIFY(groupStateChangedSpy.isValid());
|
||||
|
||||
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
||||
group.start();
|
||||
|
||||
QCOMPARE(groupStateChangedSpy.size(), 2);
|
||||
|
||||
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(groupStateChangedSpy.at(0).first()),
|
||||
QAnimationGroup::Running);
|
||||
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(groupStateChangedSpy.at(1).first()),
|
||||
QAnimationGroup::Stopped);
|
||||
|
||||
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
||||
|
||||
QTest::ignoreMessage(QtWarningMsg, "QAbstractAnimation::pause: Cannot pause a stopped animation");
|
||||
group.pause();
|
||||
|
||||
QCOMPARE(groupStateChangedSpy.size(), 2);
|
||||
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
||||
|
||||
group.start();
|
||||
|
||||
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(groupStateChangedSpy.at(2).first()),
|
||||
QAnimationGroup::Running);
|
||||
QCOMPARE(qvariant_cast<QAbstractAnimation::State>(groupStateChangedSpy.at(3).first()),
|
||||
QAnimationGroup::Stopped);
|
||||
|
||||
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
||||
|
||||
group.stop();
|
||||
|
||||
QCOMPARE(groupStateChangedSpy.size(), 4);
|
||||
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
||||
}
|
||||
|
||||
void tst_QAnimationGroup::setCurrentTime()
|
||||
{
|
||||
AnimationObject s_o1;
|
||||
AnimationObject s_o2;
|
||||
AnimationObject s_o3;
|
||||
AnimationObject p_o1;
|
||||
AnimationObject p_o2;
|
||||
AnimationObject p_o3;
|
||||
AnimationObject t_o1;
|
||||
AnimationObject t_o2;
|
||||
|
||||
// sequence operating on same object/property
|
||||
QSequentialAnimationGroup *sequence = new QSequentialAnimationGroup();
|
||||
QAbstractAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
|
||||
QAbstractAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
|
||||
QAbstractAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
|
||||
a2_s_o1->setLoopCount(3);
|
||||
sequence->addAnimation(a1_s_o1);
|
||||
sequence->addAnimation(a2_s_o1);
|
||||
sequence->addAnimation(a3_s_o1);
|
||||
|
||||
// sequence operating on different object/properties
|
||||
QAnimationGroup *sequence2 = new QSequentialAnimationGroup();
|
||||
QAbstractAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value");
|
||||
QAbstractAnimation *a1_s_o3 = new QPropertyAnimation(&s_o3, "value");
|
||||
sequence2->addAnimation(a1_s_o2);
|
||||
sequence2->addAnimation(a1_s_o3);
|
||||
|
||||
// parallel operating on different object/properties
|
||||
QAnimationGroup *parallel = new QParallelAnimationGroup();
|
||||
QAbstractAnimation *a1_p_o1 = new QPropertyAnimation(&p_o1, "value");
|
||||
QAbstractAnimation *a1_p_o2 = new QPropertyAnimation(&p_o2, "value");
|
||||
QAbstractAnimation *a1_p_o3 = new QPropertyAnimation(&p_o3, "value");
|
||||
a1_p_o2->setLoopCount(3);
|
||||
parallel->addAnimation(a1_p_o1);
|
||||
parallel->addAnimation(a1_p_o2);
|
||||
parallel->addAnimation(a1_p_o3);
|
||||
|
||||
QAbstractAnimation *notTimeDriven = new UncontrolledAnimation(&t_o1, "value");
|
||||
QCOMPARE(notTimeDriven->totalDuration(), -1);
|
||||
|
||||
QAbstractAnimation *loopsForever = new QPropertyAnimation(&t_o2, "value");
|
||||
loopsForever->setLoopCount(-1);
|
||||
QCOMPARE(loopsForever->totalDuration(), -1);
|
||||
|
||||
QParallelAnimationGroup group;
|
||||
group.addAnimation(sequence);
|
||||
group.addAnimation(sequence2);
|
||||
group.addAnimation(parallel);
|
||||
group.addAnimation(notTimeDriven);
|
||||
group.addAnimation(loopsForever);
|
||||
|
||||
// Current time = 1
|
||||
group.setCurrentTime(1);
|
||||
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
||||
QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
|
||||
QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
|
||||
QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
|
||||
QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
|
||||
QCOMPARE(parallel->state(), QAnimationGroup::Stopped);
|
||||
QCOMPARE(a1_p_o1->state(), QAnimationGroup::Stopped);
|
||||
QCOMPARE(a1_p_o2->state(), QAnimationGroup::Stopped);
|
||||
QCOMPARE(a1_p_o3->state(), QAnimationGroup::Stopped);
|
||||
QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
|
||||
QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
|
||||
|
||||
QCOMPARE(group.currentLoopTime(), 1);
|
||||
QCOMPARE(sequence->currentLoopTime(), 1);
|
||||
QCOMPARE(a1_s_o1->currentLoopTime(), 1);
|
||||
QCOMPARE(a2_s_o1->currentLoopTime(), 0);
|
||||
QCOMPARE(a3_s_o1->currentLoopTime(), 0);
|
||||
QCOMPARE(a1_s_o2->currentLoopTime(), 1);
|
||||
QCOMPARE(a1_s_o3->currentLoopTime(), 0);
|
||||
QCOMPARE(a1_p_o1->currentLoopTime(), 1);
|
||||
QCOMPARE(a1_p_o2->currentLoopTime(), 1);
|
||||
QCOMPARE(a1_p_o3->currentLoopTime(), 1);
|
||||
QCOMPARE(notTimeDriven->currentLoopTime(), 1);
|
||||
QCOMPARE(loopsForever->currentLoopTime(), 1);
|
||||
|
||||
// Current time = 250
|
||||
group.setCurrentTime(250);
|
||||
QCOMPARE(group.currentLoopTime(), 250);
|
||||
QCOMPARE(sequence->currentLoopTime(), 250);
|
||||
QCOMPARE(a1_s_o1->currentLoopTime(), 250);
|
||||
QCOMPARE(a2_s_o1->currentLoopTime(), 0);
|
||||
QCOMPARE(a3_s_o1->currentLoopTime(), 0);
|
||||
QCOMPARE(a1_s_o2->currentLoopTime(), 250);
|
||||
QCOMPARE(a1_s_o3->currentLoopTime(), 0);
|
||||
QCOMPARE(a1_p_o1->currentLoopTime(), 250);
|
||||
QCOMPARE(a1_p_o2->currentLoopTime(), 0);
|
||||
QCOMPARE(a1_p_o2->currentLoop(), 1);
|
||||
QCOMPARE(a1_p_o3->currentLoopTime(), 250);
|
||||
QCOMPARE(notTimeDriven->currentLoopTime(), 250);
|
||||
QCOMPARE(loopsForever->currentLoopTime(), 0);
|
||||
QCOMPARE(loopsForever->currentLoop(), 1);
|
||||
QCOMPARE(sequence->currentAnimation(), a2_s_o1);
|
||||
|
||||
// Current time = 251
|
||||
group.setCurrentTime(251);
|
||||
QCOMPARE(group.currentLoopTime(), 251);
|
||||
QCOMPARE(sequence->currentLoopTime(), 251);
|
||||
QCOMPARE(a1_s_o1->currentLoopTime(), 250);
|
||||
QCOMPARE(a2_s_o1->currentLoopTime(), 1);
|
||||
QCOMPARE(a2_s_o1->currentLoop(), 0);
|
||||
QCOMPARE(a3_s_o1->currentLoopTime(), 0);
|
||||
QCOMPARE(sequence2->currentLoopTime(), 251);
|
||||
QCOMPARE(a1_s_o2->currentLoopTime(), 250);
|
||||
QCOMPARE(a1_s_o3->currentLoopTime(), 1);
|
||||
QCOMPARE(a1_p_o1->currentLoopTime(), 250);
|
||||
QCOMPARE(a1_p_o2->currentLoopTime(), 1);
|
||||
QCOMPARE(a1_p_o2->currentLoop(), 1);
|
||||
QCOMPARE(a1_p_o3->currentLoopTime(), 250);
|
||||
QCOMPARE(notTimeDriven->currentLoopTime(), 251);
|
||||
QCOMPARE(loopsForever->currentLoopTime(), 1);
|
||||
QCOMPARE(sequence->currentAnimation(), a2_s_o1);
|
||||
}
|
||||
|
||||
void tst_QAnimationGroup::setParentAutoAdd()
|
||||
{
|
||||
QParallelAnimationGroup group;
|
||||
QVariantAnimation *animation = new QPropertyAnimation(&group);
|
||||
QCOMPARE(animation->group(), static_cast<QAnimationGroup*>(&group));
|
||||
}
|
||||
|
||||
void tst_QAnimationGroup::beginNestedGroup()
|
||||
{
|
||||
QParallelAnimationGroup group;
|
||||
QAnimationGroup *parent = &group;
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
if (i & 1) {
|
||||
new QParallelAnimationGroup(parent);
|
||||
} else {
|
||||
new QSequentialAnimationGroup(parent);
|
||||
}
|
||||
|
||||
QCOMPARE(parent->animationCount(), 1);
|
||||
QAnimationGroup *child = static_cast<QAnimationGroup *>(parent->animationAt(0));
|
||||
|
||||
QCOMPARE(child->parent(), static_cast<QObject *>(parent));
|
||||
if (i & 1)
|
||||
QVERIFY(qobject_cast<QParallelAnimationGroup *> (child));
|
||||
else
|
||||
QVERIFY(qobject_cast<QSequentialAnimationGroup *> (child));
|
||||
|
||||
parent = child;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QAnimationGroup::addChildTwice()
|
||||
{
|
||||
QAbstractAnimation *subGroup;
|
||||
QAbstractAnimation *subGroup2;
|
||||
QAnimationGroup *parent = new QSequentialAnimationGroup();
|
||||
|
||||
subGroup = new QPropertyAnimation();
|
||||
subGroup->setParent(parent);
|
||||
parent->addAnimation(subGroup);
|
||||
QCOMPARE(parent->animationCount(), 1);
|
||||
|
||||
parent->clear();
|
||||
|
||||
QCOMPARE(parent->animationCount(), 0);
|
||||
|
||||
// adding the same item twice to a group will remove the item from its current position
|
||||
// and append it to the end
|
||||
subGroup = new QPropertyAnimation(parent);
|
||||
subGroup2 = new QPropertyAnimation(parent);
|
||||
|
||||
QCOMPARE(parent->animationCount(), 2);
|
||||
QCOMPARE(parent->animationAt(0), subGroup);
|
||||
QCOMPARE(parent->animationAt(1), subGroup2);
|
||||
|
||||
parent->addAnimation(subGroup);
|
||||
|
||||
QCOMPARE(parent->animationCount(), 2);
|
||||
QCOMPARE(parent->animationAt(0), subGroup2);
|
||||
QCOMPARE(parent->animationAt(1), subGroup);
|
||||
|
||||
delete parent;
|
||||
}
|
||||
|
||||
void tst_QAnimationGroup::loopWithoutStartValue()
|
||||
{
|
||||
QSequentialAnimationGroup group;
|
||||
QAnimationGroup *parent = &group;
|
||||
QObject o;
|
||||
o.setProperty("ole", 0);
|
||||
QCOMPARE(o.property("ole").toInt(), 0);
|
||||
|
||||
QPropertyAnimation anim1(&o, "ole");
|
||||
anim1.setEndValue(-50);
|
||||
anim1.setDuration(100);
|
||||
|
||||
QPropertyAnimation anim2(&o, "ole");
|
||||
anim2.setEndValue(50);
|
||||
anim2.setDuration(100);
|
||||
|
||||
parent->addAnimation(&anim1);
|
||||
parent->addAnimation(&anim2);
|
||||
|
||||
parent->setLoopCount(-1);
|
||||
parent->start();
|
||||
|
||||
QVERIFY(anim1.startValue().isNull());
|
||||
QCOMPARE(anim1.currentValue().toInt(), 0);
|
||||
QCOMPARE(parent->currentLoop(), 0);
|
||||
|
||||
parent->setCurrentTime(200);
|
||||
QCOMPARE(parent->currentLoop(), 1);
|
||||
QCOMPARE(anim1.currentValue().toInt(), 50);
|
||||
parent->stop();
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QAnimationGroup)
|
||||
#include "tst_qanimationgroup.moc"
|
@ -0,0 +1,2 @@
|
||||
[deleteChildrenWithRunningGroup]
|
||||
macos
|
@ -0,0 +1,11 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qparallelanimationgroup Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qparallelanimationgroup
|
||||
SOURCES
|
||||
tst_qparallelanimationgroup.cpp
|
||||
)
|
File diff suppressed because it is too large
Load Diff
6
tests/auto/corelib/animation/qpauseanimation/BLACKLIST
Normal file
6
tests/auto/corelib/animation/qpauseanimation/BLACKLIST
Normal file
@ -0,0 +1,6 @@
|
||||
[pauseAndPropertyAnimations]
|
||||
macos
|
||||
[multipleSequentialGroups]
|
||||
macos
|
||||
[noTimerUpdates]
|
||||
macos
|
13
tests/auto/corelib/animation/qpauseanimation/CMakeLists.txt
Normal file
13
tests/auto/corelib/animation/qpauseanimation/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qpauseanimation Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qpauseanimation
|
||||
SOURCES
|
||||
tst_qpauseanimation.cpp
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
)
|
@ -0,0 +1,462 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QTest>
|
||||
|
||||
#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)
|
||||
# define BAD_TIMER_RESOLUTION
|
||||
#endif
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
static const char timerError[] = "On this platform, consistent timing is not working properly due to bad timer resolution";
|
||||
|
||||
# define WAIT_FOR_STOPPED(animation, duration) \
|
||||
QTest::qWait(duration); \
|
||||
if (animation.state() != QAbstractAnimation::Stopped) \
|
||||
QEXPECT_FAIL("", timerError, Abort); \
|
||||
QCOMPARE(animation.state(), QAbstractAnimation::Stopped)
|
||||
#else
|
||||
// Use QTRY_COMPARE with one additional timer tick
|
||||
# define WAIT_FOR_STOPPED(animation, duration) \
|
||||
QTRY_COMPARE_WITH_TIMEOUT(animation.state(), QAbstractAnimation::Stopped, (duration))
|
||||
#endif
|
||||
|
||||
class TestablePauseAnimation : public QPauseAnimation
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TestablePauseAnimation(QObject *parent = nullptr)
|
||||
: QPauseAnimation(parent),
|
||||
m_updateCurrentTimeCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
int m_updateCurrentTimeCount;
|
||||
protected:
|
||||
void updateCurrentTime(int currentTime) override
|
||||
{
|
||||
QPauseAnimation::updateCurrentTime(currentTime);
|
||||
++m_updateCurrentTimeCount;
|
||||
}
|
||||
};
|
||||
|
||||
class EnableConsistentTiming
|
||||
{
|
||||
public:
|
||||
EnableConsistentTiming()
|
||||
{
|
||||
QUnifiedTimer *timer = QUnifiedTimer::instance();
|
||||
timer->setConsistentTiming(true);
|
||||
}
|
||||
~EnableConsistentTiming()
|
||||
{
|
||||
QUnifiedTimer *timer = QUnifiedTimer::instance();
|
||||
timer->setConsistentTiming(false);
|
||||
}
|
||||
};
|
||||
|
||||
class tst_QPauseAnimation : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public Q_SLOTS:
|
||||
void initTestCase();
|
||||
|
||||
private slots:
|
||||
void changeDirectionWhileRunning();
|
||||
void noTimerUpdates_data();
|
||||
void noTimerUpdates();
|
||||
void multiplePauseAnimations();
|
||||
void pauseAndPropertyAnimations();
|
||||
void pauseResume();
|
||||
void sequentialPauseGroup();
|
||||
void sequentialGroupWithPause();
|
||||
void multipleSequentialGroups();
|
||||
void zeroDuration();
|
||||
void bindings();
|
||||
};
|
||||
|
||||
void tst_QPauseAnimation::initTestCase()
|
||||
{
|
||||
qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
|
||||
qRegisterMetaType<QAbstractAnimation::DeletionPolicy>("QAbstractAnimation::DeletionPolicy");
|
||||
}
|
||||
|
||||
void tst_QPauseAnimation::changeDirectionWhileRunning()
|
||||
{
|
||||
EnableConsistentTiming enabled;
|
||||
|
||||
TestablePauseAnimation animation;
|
||||
animation.setDuration(400);
|
||||
animation.start();
|
||||
QTRY_COMPARE(animation.state(), QAbstractAnimation::Running);
|
||||
animation.setDirection(QAbstractAnimation::Backward);
|
||||
const int expectedDuration = animation.totalDuration() + 100;
|
||||
WAIT_FOR_STOPPED(animation, expectedDuration);
|
||||
}
|
||||
|
||||
void tst_QPauseAnimation::noTimerUpdates_data()
|
||||
{
|
||||
QTest::addColumn<int>("duration");
|
||||
QTest::addColumn<int>("loopCount");
|
||||
|
||||
QTest::newRow("0") << 200 << 1;
|
||||
QTest::newRow("1") << 160 << 1;
|
||||
QTest::newRow("2") << 160 << 2;
|
||||
QTest::newRow("3") << 200 << 3;
|
||||
}
|
||||
|
||||
void tst_QPauseAnimation::noTimerUpdates()
|
||||
{
|
||||
EnableConsistentTiming enabled;
|
||||
|
||||
QFETCH(int, duration);
|
||||
QFETCH(int, loopCount);
|
||||
|
||||
TestablePauseAnimation animation;
|
||||
animation.setDuration(duration);
|
||||
animation.setLoopCount(loopCount);
|
||||
animation.start();
|
||||
const int expectedDuration = animation.totalDuration() + 150;
|
||||
WAIT_FOR_STOPPED(animation, expectedDuration);
|
||||
|
||||
const int expectedLoopCount = 1 + loopCount;
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
if (animation.m_updateCurrentTimeCount != expectedLoopCount)
|
||||
QEXPECT_FAIL("", timerError, Abort);
|
||||
#endif
|
||||
QCOMPARE(animation.m_updateCurrentTimeCount, expectedLoopCount);
|
||||
}
|
||||
|
||||
void tst_QPauseAnimation::multiplePauseAnimations()
|
||||
{
|
||||
EnableConsistentTiming enabled;
|
||||
|
||||
TestablePauseAnimation animation;
|
||||
animation.setDuration(200);
|
||||
|
||||
TestablePauseAnimation animation2;
|
||||
animation2.setDuration(800);
|
||||
|
||||
animation.start();
|
||||
animation2.start();
|
||||
|
||||
const int expectedDuration = animation.totalDuration() + 150;
|
||||
WAIT_FOR_STOPPED(animation, expectedDuration);
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
if (animation2.state() != QAbstractAnimation::Running)
|
||||
QEXPECT_FAIL("", timerError, Abort);
|
||||
#endif
|
||||
QCOMPARE(animation2.state(), QAbstractAnimation::Running);
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
if (animation.m_updateCurrentTimeCount != 2)
|
||||
QEXPECT_FAIL("", timerError, Abort);
|
||||
#endif
|
||||
QCOMPARE(animation.m_updateCurrentTimeCount, 2);
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
if (animation2.m_updateCurrentTimeCount != 2)
|
||||
QEXPECT_FAIL("", timerError, Abort);
|
||||
#endif
|
||||
QCOMPARE(animation2.m_updateCurrentTimeCount, 2);
|
||||
|
||||
WAIT_FOR_STOPPED(animation2, 600);
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
if (animation2.m_updateCurrentTimeCount != 3)
|
||||
QEXPECT_FAIL("", timerError, Abort);
|
||||
#endif
|
||||
QCOMPARE(animation2.m_updateCurrentTimeCount, 3);
|
||||
}
|
||||
|
||||
void tst_QPauseAnimation::pauseAndPropertyAnimations()
|
||||
{
|
||||
EnableConsistentTiming enabled;
|
||||
|
||||
TestablePauseAnimation pause;
|
||||
pause.setDuration(200);
|
||||
|
||||
QObject o;
|
||||
o.setProperty("ole", 42);
|
||||
|
||||
QPropertyAnimation animation(&o, "ole");
|
||||
animation.setEndValue(43);
|
||||
|
||||
pause.start();
|
||||
|
||||
QTest::qWait(100);
|
||||
animation.start();
|
||||
|
||||
QCOMPARE(animation.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(pause.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(pause.m_updateCurrentTimeCount, 2);
|
||||
|
||||
const int expectedDuration = animation.totalDuration() + 150;
|
||||
WAIT_FOR_STOPPED(animation, expectedDuration);
|
||||
|
||||
QCOMPARE(pause.state(), QAbstractAnimation::Stopped);
|
||||
QVERIFY(pause.m_updateCurrentTimeCount > 3);
|
||||
}
|
||||
|
||||
void tst_QPauseAnimation::pauseResume()
|
||||
{
|
||||
TestablePauseAnimation animation;
|
||||
animation.setDuration(400);
|
||||
animation.start();
|
||||
QCOMPARE(animation.state(), QAbstractAnimation::Running);
|
||||
QTest::qWait(200);
|
||||
animation.pause();
|
||||
QCOMPARE(animation.state(), QAbstractAnimation::Paused);
|
||||
animation.start();
|
||||
QTRY_COMPARE(animation.state(), QAbstractAnimation::Stopped);
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
if (animation.m_updateCurrentTimeCount < 3)
|
||||
QEXPECT_FAIL("", timerError, Abort);
|
||||
#endif
|
||||
QVERIFY2(animation.m_updateCurrentTimeCount >= 3, qPrintable(
|
||||
QString::fromLatin1("animation.m_updateCurrentTimeCount = %1").arg(animation.m_updateCurrentTimeCount)));
|
||||
}
|
||||
|
||||
void tst_QPauseAnimation::sequentialPauseGroup()
|
||||
{
|
||||
QSequentialAnimationGroup group;
|
||||
|
||||
TestablePauseAnimation animation1(&group);
|
||||
animation1.setDuration(200);
|
||||
TestablePauseAnimation animation2(&group);
|
||||
animation2.setDuration(200);
|
||||
TestablePauseAnimation animation3(&group);
|
||||
animation3.setDuration(200);
|
||||
|
||||
group.start();
|
||||
QCOMPARE(animation1.m_updateCurrentTimeCount, 1);
|
||||
QCOMPARE(animation2.m_updateCurrentTimeCount, 0);
|
||||
QCOMPARE(animation3.m_updateCurrentTimeCount, 0);
|
||||
|
||||
QCOMPARE(group.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(animation1.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(animation2.state(), QAbstractAnimation::Stopped);
|
||||
QCOMPARE(animation3.state(), QAbstractAnimation::Stopped);
|
||||
|
||||
group.setCurrentTime(250);
|
||||
QCOMPARE(animation1.m_updateCurrentTimeCount, 2);
|
||||
QCOMPARE(animation2.m_updateCurrentTimeCount, 1);
|
||||
QCOMPARE(animation3.m_updateCurrentTimeCount, 0);
|
||||
|
||||
QCOMPARE(group.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(animation1.state(), QAbstractAnimation::Stopped);
|
||||
QCOMPARE((QAbstractAnimation*)&animation2, group.currentAnimation());
|
||||
QCOMPARE(animation2.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(animation3.state(), QAbstractAnimation::Stopped);
|
||||
|
||||
group.setCurrentTime(500);
|
||||
QCOMPARE(animation1.m_updateCurrentTimeCount, 2);
|
||||
QCOMPARE(animation2.m_updateCurrentTimeCount, 2);
|
||||
QCOMPARE(animation3.m_updateCurrentTimeCount, 1);
|
||||
|
||||
QCOMPARE(group.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(animation1.state(), QAbstractAnimation::Stopped);
|
||||
QCOMPARE(animation2.state(), QAbstractAnimation::Stopped);
|
||||
QCOMPARE((QAbstractAnimation*)&animation3, group.currentAnimation());
|
||||
QCOMPARE(animation3.state(), QAbstractAnimation::Running);
|
||||
|
||||
group.setCurrentTime(750);
|
||||
|
||||
QCOMPARE(group.state(), QAbstractAnimation::Stopped);
|
||||
QCOMPARE(animation1.state(), QAbstractAnimation::Stopped);
|
||||
QCOMPARE(animation2.state(), QAbstractAnimation::Stopped);
|
||||
QCOMPARE(animation3.state(), QAbstractAnimation::Stopped);
|
||||
|
||||
QCOMPARE(animation1.m_updateCurrentTimeCount, 2);
|
||||
QCOMPARE(animation2.m_updateCurrentTimeCount, 2);
|
||||
QCOMPARE(animation3.m_updateCurrentTimeCount, 2);
|
||||
}
|
||||
|
||||
void tst_QPauseAnimation::sequentialGroupWithPause()
|
||||
{
|
||||
QSequentialAnimationGroup group;
|
||||
|
||||
QObject o;
|
||||
o.setProperty("ole", 42);
|
||||
|
||||
QPropertyAnimation animation(&o, "ole", &group);
|
||||
animation.setEndValue(43);
|
||||
TestablePauseAnimation pause(&group);
|
||||
pause.setDuration(250);
|
||||
|
||||
group.start();
|
||||
|
||||
QCOMPARE(group.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(animation.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(pause.state(), QAbstractAnimation::Stopped);
|
||||
|
||||
group.setCurrentTime(300);
|
||||
|
||||
QCOMPARE(group.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(animation.state(), QAbstractAnimation::Stopped);
|
||||
QCOMPARE((QAbstractAnimation*)&pause, group.currentAnimation());
|
||||
QCOMPARE(pause.state(), QAbstractAnimation::Running);
|
||||
|
||||
group.setCurrentTime(600);
|
||||
|
||||
QCOMPARE(group.state(), QAbstractAnimation::Stopped);
|
||||
QCOMPARE(animation.state(), QAbstractAnimation::Stopped);
|
||||
QCOMPARE(pause.state(), QAbstractAnimation::Stopped);
|
||||
|
||||
QCOMPARE(pause.m_updateCurrentTimeCount, 2);
|
||||
}
|
||||
|
||||
void tst_QPauseAnimation::multipleSequentialGroups()
|
||||
{
|
||||
EnableConsistentTiming enabled;
|
||||
|
||||
QParallelAnimationGroup group;
|
||||
group.setLoopCount(2);
|
||||
|
||||
QSequentialAnimationGroup subgroup1(&group);
|
||||
|
||||
QObject o;
|
||||
o.setProperty("ole", 42);
|
||||
|
||||
QPropertyAnimation animation(&o, "ole", &subgroup1);
|
||||
animation.setEndValue(43);
|
||||
animation.setDuration(300);
|
||||
TestablePauseAnimation pause(&subgroup1);
|
||||
pause.setDuration(200);
|
||||
|
||||
QSequentialAnimationGroup subgroup2(&group);
|
||||
|
||||
o.setProperty("ole2", 42);
|
||||
QPropertyAnimation animation2(&o, "ole2", &subgroup2);
|
||||
animation2.setEndValue(43);
|
||||
animation2.setDuration(200);
|
||||
TestablePauseAnimation pause2(&subgroup2);
|
||||
pause2.setDuration(250);
|
||||
|
||||
QSequentialAnimationGroup subgroup3(&group);
|
||||
|
||||
TestablePauseAnimation pause3(&subgroup3);
|
||||
pause3.setDuration(400);
|
||||
|
||||
o.setProperty("ole3", 42);
|
||||
QPropertyAnimation animation3(&o, "ole3", &subgroup3);
|
||||
animation3.setEndValue(43);
|
||||
animation3.setDuration(200);
|
||||
|
||||
QSequentialAnimationGroup subgroup4(&group);
|
||||
|
||||
TestablePauseAnimation pause4(&subgroup4);
|
||||
pause4.setDuration(310);
|
||||
|
||||
TestablePauseAnimation pause5(&subgroup4);
|
||||
pause5.setDuration(60);
|
||||
|
||||
group.start();
|
||||
|
||||
QCOMPARE(group.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(subgroup1.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(subgroup2.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(subgroup3.state(), QAbstractAnimation::Running);
|
||||
QCOMPARE(subgroup4.state(), QAbstractAnimation::Running);
|
||||
|
||||
// This is a pretty long animation so it tends to get rather out of sync
|
||||
// when using the consistent timer, so run for an extra half second for good
|
||||
// measure...
|
||||
const int expectedDuration = group.totalDuration() + 550;
|
||||
WAIT_FOR_STOPPED(group, expectedDuration);
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
if (subgroup1.state() != QAbstractAnimation::Stopped)
|
||||
QEXPECT_FAIL("", timerError, Abort);
|
||||
#endif
|
||||
QCOMPARE(subgroup1.state(), QAbstractAnimation::Stopped);
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
if (subgroup2.state() != QAbstractAnimation::Stopped)
|
||||
QEXPECT_FAIL("", timerError, Abort);
|
||||
#endif
|
||||
QCOMPARE(subgroup2.state(), QAbstractAnimation::Stopped);
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
if (subgroup3.state() != QAbstractAnimation::Stopped)
|
||||
QEXPECT_FAIL("", timerError, Abort);
|
||||
#endif
|
||||
QCOMPARE(subgroup3.state(), QAbstractAnimation::Stopped);
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
if (subgroup4.state() != QAbstractAnimation::Stopped)
|
||||
QEXPECT_FAIL("", timerError, Abort);
|
||||
#endif
|
||||
QCOMPARE(subgroup4.state(), QAbstractAnimation::Stopped);
|
||||
|
||||
#ifdef BAD_TIMER_RESOLUTION
|
||||
if (pause5.m_updateCurrentTimeCount != 4)
|
||||
QEXPECT_FAIL("", timerError, Abort);
|
||||
#endif
|
||||
QCOMPARE(pause5.m_updateCurrentTimeCount, 4);
|
||||
}
|
||||
|
||||
void tst_QPauseAnimation::zeroDuration()
|
||||
{
|
||||
TestablePauseAnimation animation;
|
||||
animation.setDuration(0);
|
||||
animation.start();
|
||||
const int expectedDuration = animation.totalDuration() + 150;
|
||||
WAIT_FOR_STOPPED(animation, expectedDuration);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QPauseAnimation)
|
||||
#include "tst_qpauseanimation.moc"
|
@ -0,0 +1,17 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qpropertyanimation Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qpropertyanimation
|
||||
SOURCES
|
||||
tst_qpropertyanimation.cpp
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
LIBRARIES
|
||||
Qt::TestPrivate
|
||||
)
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,6 @@
|
||||
[finishWithUncontrolledAnimation]
|
||||
windows-10 msvc-2015
|
||||
macos
|
||||
[groupWithZeroDurationAnimations]
|
||||
macos
|
||||
|
@ -0,0 +1,11 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qsequentialanimationgroup Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qsequentialanimationgroup
|
||||
SOURCES
|
||||
tst_qsequentialanimationgroup.cpp
|
||||
)
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qvariantanimation Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qvariantanimation
|
||||
SOURCES
|
||||
tst_qvariantanimation.cpp
|
||||
LIBRARIES
|
||||
Qt::TestPrivate
|
||||
)
|
@ -0,0 +1,163 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
|
||||
#include <QtCore/qvariantanimation.h>
|
||||
#include <QTest>
|
||||
#include <QtTest/private/qpropertytesthelper_p.h>
|
||||
|
||||
class tst_QVariantAnimation : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void construction();
|
||||
void destruction();
|
||||
void currentValue();
|
||||
void easingCurve();
|
||||
void startValue();
|
||||
void endValue();
|
||||
void keyValueAt();
|
||||
void keyValues();
|
||||
void duration();
|
||||
void interpolation();
|
||||
void durationBindings();
|
||||
void easingCurveBindings();
|
||||
};
|
||||
|
||||
class TestableQVariantAnimation : public QVariantAnimation
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
void updateCurrentValue(const QVariant&) override {}
|
||||
};
|
||||
|
||||
void tst_QVariantAnimation::construction()
|
||||
{
|
||||
TestableQVariantAnimation anim;
|
||||
}
|
||||
|
||||
void tst_QVariantAnimation::destruction()
|
||||
{
|
||||
TestableQVariantAnimation *anim = new TestableQVariantAnimation;
|
||||
delete anim;
|
||||
}
|
||||
|
||||
void tst_QVariantAnimation::currentValue()
|
||||
{
|
||||
TestableQVariantAnimation anim;
|
||||
QVERIFY(!anim.currentValue().isValid());
|
||||
}
|
||||
|
||||
void tst_QVariantAnimation::easingCurve()
|
||||
{
|
||||
TestableQVariantAnimation anim;
|
||||
QCOMPARE(anim.easingCurve().type(), QEasingCurve::Linear);
|
||||
anim.setEasingCurve(QEasingCurve::InQuad);
|
||||
QCOMPARE(anim.easingCurve().type(), QEasingCurve::InQuad);
|
||||
}
|
||||
|
||||
void tst_QVariantAnimation::endValue()
|
||||
{
|
||||
TestableQVariantAnimation anim;
|
||||
anim.setEndValue(QVariant(1));
|
||||
QCOMPARE(anim.endValue().toInt(), 1);
|
||||
}
|
||||
|
||||
void tst_QVariantAnimation::startValue()
|
||||
{
|
||||
TestableQVariantAnimation anim;
|
||||
anim.setStartValue(QVariant(1));
|
||||
QCOMPARE(anim.startValue().toInt(), 1);
|
||||
anim.setStartValue(QVariant(-1));
|
||||
QCOMPARE(anim.startValue().toInt(), -1);
|
||||
}
|
||||
|
||||
void tst_QVariantAnimation::keyValueAt()
|
||||
{
|
||||
TestableQVariantAnimation anim;
|
||||
|
||||
int i=0;
|
||||
for (qreal r=0.0; r<1.0; r+=0.1) {
|
||||
anim.setKeyValueAt(0.1, ++i);
|
||||
QCOMPARE(anim.keyValueAt(0.1).toInt(), i);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QVariantAnimation::keyValues()
|
||||
{
|
||||
TestableQVariantAnimation anim;
|
||||
|
||||
QVariantAnimation::KeyValues values;
|
||||
int i=0;
|
||||
for (qreal r=0.0; r<1.0; r+=0.1) {
|
||||
values.append(QVariantAnimation::KeyValue(r, i));
|
||||
}
|
||||
|
||||
anim.setKeyValues(values);
|
||||
QCOMPARE(anim.keyValues(), values);
|
||||
}
|
||||
|
||||
void tst_QVariantAnimation::duration()
|
||||
{
|
||||
TestableQVariantAnimation anim;
|
||||
QCOMPARE(anim.duration(), 250);
|
||||
anim.setDuration(500);
|
||||
QCOMPARE(anim.duration(), 500);
|
||||
QTest::ignoreMessage(QtWarningMsg, "QVariantAnimation::setDuration: cannot set a negative duration");
|
||||
anim.setDuration(-1);
|
||||
QCOMPARE(anim.duration(), 500);
|
||||
}
|
||||
|
||||
void tst_QVariantAnimation::interpolation()
|
||||
{
|
||||
QVariantAnimation unsignedAnim;
|
||||
unsignedAnim.setStartValue(100u);
|
||||
unsignedAnim.setEndValue(0u);
|
||||
unsignedAnim.setDuration(100);
|
||||
unsignedAnim.setCurrentTime(50);
|
||||
QCOMPARE(unsignedAnim.currentValue().toUInt(), 50u);
|
||||
|
||||
QVariantAnimation signedAnim;
|
||||
signedAnim.setStartValue(100);
|
||||
signedAnim.setEndValue(0);
|
||||
signedAnim.setDuration(100);
|
||||
signedAnim.setCurrentTime(50);
|
||||
QCOMPARE(signedAnim.currentValue().toInt(), 50);
|
||||
|
||||
QVariantAnimation pointAnim;
|
||||
pointAnim.setStartValue(QPoint(100, 100));
|
||||
pointAnim.setEndValue(QPoint(0, 0));
|
||||
pointAnim.setDuration(100);
|
||||
pointAnim.setCurrentTime(50);
|
||||
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"
|
Reference in New Issue
Block a user