| 1 | // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtTest/QTest> |
| 5 | #include <Qt3DAnimation/private/animationclip_p.h> |
| 6 | #include <Qt3DAnimation/qanimationcliploader.h> |
| 7 | #include <Qt3DCore/private/qnode_p.h> |
| 8 | #include <Qt3DCore/private/qscene_p.h> |
| 9 | #include <Qt3DCore/private/qbackendnode_p.h> |
| 10 | #include <qbackendnodetester.h> |
| 11 | |
| 12 | using namespace Qt3DAnimation::Animation; |
| 13 | |
| 14 | class tst_AnimationClip : public Qt3DCore::QBackendNodeTester |
| 15 | { |
| 16 | Q_OBJECT |
| 17 | |
| 18 | private Q_SLOTS: |
| 19 | void checkPeerPropertyMirroring() |
| 20 | { |
| 21 | // GIVEN |
| 22 | AnimationClip backendClip; |
| 23 | Handler handler; |
| 24 | backendClip.setHandler(&handler); |
| 25 | Qt3DAnimation::QAnimationClipLoader clip; |
| 26 | |
| 27 | clip.setSource(QUrl::fromLocalFile("walk.qlip")); |
| 28 | |
| 29 | // WHEN |
| 30 | simulateInitializationSync(&clip, &backendClip); |
| 31 | |
| 32 | // THEN |
| 33 | QCOMPARE(backendClip.peerId(), clip.id()); |
| 34 | QCOMPARE(backendClip.isEnabled(), clip.isEnabled()); |
| 35 | QCOMPARE(backendClip.source(), clip.source()); |
| 36 | } |
| 37 | |
| 38 | void checkInitialAndCleanedUpState() |
| 39 | { |
| 40 | // GIVEN |
| 41 | AnimationClip backendClip; |
| 42 | Handler handler; |
| 43 | backendClip.setHandler(&handler); |
| 44 | |
| 45 | // THEN |
| 46 | QVERIFY(backendClip.peerId().isNull()); |
| 47 | QCOMPARE(backendClip.isEnabled(), false); |
| 48 | QCOMPARE(backendClip.source(), QUrl()); |
| 49 | QCOMPARE(backendClip.duration(), 0.0f); |
| 50 | QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady); |
| 51 | |
| 52 | // GIVEN |
| 53 | Qt3DAnimation::QAnimationClipLoader clip; |
| 54 | clip.setSource(QUrl::fromLocalFile("walk.qlip")); |
| 55 | |
| 56 | // WHEN |
| 57 | simulateInitializationSync(&clip, &backendClip); |
| 58 | backendClip.setSource(QUrl::fromLocalFile("run.qlip")); |
| 59 | backendClip.cleanup(); |
| 60 | |
| 61 | // THEN |
| 62 | QCOMPARE(backendClip.source(), QUrl()); |
| 63 | QCOMPARE(backendClip.isEnabled(), false); |
| 64 | QCOMPARE(backendClip.duration(), 0.0f); |
| 65 | QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady); |
| 66 | } |
| 67 | |
| 68 | void checkPropertyChanges() |
| 69 | { |
| 70 | // GIVEN |
| 71 | Qt3DAnimation::QAnimationClipLoader clip; |
| 72 | AnimationClip backendClip; |
| 73 | Handler handler; |
| 74 | backendClip.setHandler(&handler); |
| 75 | simulateInitializationSync(&clip, &backendClip); |
| 76 | |
| 77 | // WHEN |
| 78 | clip.setEnabled(false); |
| 79 | backendClip.syncFromFrontEnd(&clip, false); |
| 80 | |
| 81 | // THEN |
| 82 | QCOMPARE(backendClip.isEnabled(), false); |
| 83 | |
| 84 | // WHEN |
| 85 | const QUrl newSource = QUrl::fromLocalFile("fallover.qlip"); |
| 86 | clip.setSource(newSource); |
| 87 | backendClip.syncFromFrontEnd(&clip, false); |
| 88 | |
| 89 | // THEN |
| 90 | QCOMPARE(backendClip.source(), newSource); |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | QTEST_APPLESS_MAIN(tst_AnimationClip) |
| 95 | |
| 96 | #include "tst_animationclip.moc" |