| 1 | // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | |
| 5 | #include <QtTest/QTest> |
| 6 | #include <Qt3DAnimation/qclock.h> |
| 7 | #include <Qt3DAnimation/private/qclock_p.h> |
| 8 | #include <QObject> |
| 9 | #include <QSignalSpy> |
| 10 | #include <testarbiter.h> |
| 11 | |
| 12 | class tst_QClock : public QObject |
| 13 | { |
| 14 | Q_OBJECT |
| 15 | |
| 16 | private Q_SLOTS: |
| 17 | void initTestCase() |
| 18 | { |
| 19 | qRegisterMetaType<Qt3DAnimation::QClock*>(); |
| 20 | } |
| 21 | |
| 22 | void checkDefaultConstruction() |
| 23 | { |
| 24 | // GIVEN |
| 25 | Qt3DAnimation::QClock clock; |
| 26 | |
| 27 | // THEN |
| 28 | QCOMPARE(clock.playbackRate(), 1.0); |
| 29 | } |
| 30 | |
| 31 | void checkPropertyChanges() |
| 32 | { |
| 33 | // GIVEN |
| 34 | Qt3DAnimation::QClock clock; |
| 35 | |
| 36 | // WHEN |
| 37 | QSignalSpy spy(&clock, SIGNAL(playbackRateChanged(double))); |
| 38 | const double newValue = 5.5; |
| 39 | clock.setPlaybackRate(newValue); |
| 40 | |
| 41 | // THEN |
| 42 | QVERIFY(spy.isValid()); |
| 43 | QCOMPARE(clock.playbackRate(), newValue); |
| 44 | QCOMPARE(spy.size(), 1); |
| 45 | |
| 46 | // WHEN |
| 47 | spy.clear(); |
| 48 | clock.setPlaybackRate(newValue); |
| 49 | |
| 50 | // THEN |
| 51 | QCOMPARE(clock.playbackRate(), newValue); |
| 52 | QCOMPARE(spy.size(), 0); |
| 53 | } |
| 54 | |
| 55 | void checkPropertyUpdate() |
| 56 | { |
| 57 | // GIVEN |
| 58 | TestArbiter arbiter; |
| 59 | Qt3DAnimation::QClock clock; |
| 60 | arbiter.setArbiterOnNode(&clock); |
| 61 | |
| 62 | { |
| 63 | // WHEN |
| 64 | clock.setPlaybackRate(10.5f); |
| 65 | |
| 66 | // THEN |
| 67 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 68 | QCOMPARE(arbiter.dirtyNodes().front(), &clock); |
| 69 | |
| 70 | arbiter.clear(); |
| 71 | } |
| 72 | |
| 73 | { |
| 74 | // WHEN |
| 75 | clock.setPlaybackRate(10.5f); |
| 76 | |
| 77 | // THEN |
| 78 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 79 | } |
| 80 | } |
| 81 | }; |
| 82 | |
| 83 | QTEST_MAIN(tst_QClock) |
| 84 | |
| 85 | #include "tst_qclock.moc" |