| 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/qskeletonmapping.h> |
| 6 | #include <Qt3DAnimation/private/qskeletonmapping_p.h> |
| 7 | #include <Qt3DCore/qskeleton.h> |
| 8 | #include <Qt3DCore/qentity.h> |
| 9 | #include <QObject> |
| 10 | #include <QSignalSpy> |
| 11 | #include <testarbiter.h> |
| 12 | |
| 13 | class tst_QSkeletonMapping : public QObject |
| 14 | { |
| 15 | Q_OBJECT |
| 16 | |
| 17 | private Q_SLOTS: |
| 18 | void initTestCase() |
| 19 | { |
| 20 | qRegisterMetaType<Qt3DCore::QAbstractSkeleton*>(); |
| 21 | } |
| 22 | |
| 23 | void checkDefaultConstruction() |
| 24 | { |
| 25 | // GIVEN |
| 26 | Qt3DAnimation::QSkeletonMapping mapping; |
| 27 | |
| 28 | // THEN |
| 29 | QCOMPARE(mapping.skeleton(), static_cast<Qt3DCore::QAbstractSkeleton *>(nullptr)); |
| 30 | } |
| 31 | |
| 32 | void checkPropertyChanges() |
| 33 | { |
| 34 | // GIVEN |
| 35 | Qt3DAnimation::QSkeletonMapping mapping; |
| 36 | |
| 37 | { |
| 38 | // WHEN |
| 39 | QSignalSpy spy(&mapping, SIGNAL(skeletonChanged(Qt3DCore::QAbstractSkeleton*))); |
| 40 | auto newValue = new Qt3DCore::QSkeleton(); |
| 41 | mapping.setSkeleton(newValue); |
| 42 | |
| 43 | // THEN |
| 44 | QVERIFY(spy.isValid()); |
| 45 | QCOMPARE(mapping.skeleton(), newValue); |
| 46 | QCOMPARE(spy.size(), 1); |
| 47 | |
| 48 | // WHEN |
| 49 | spy.clear(); |
| 50 | mapping.setSkeleton(newValue); |
| 51 | |
| 52 | // THEN |
| 53 | QCOMPARE(mapping.skeleton(), newValue); |
| 54 | QCOMPARE(spy.size(), 0); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void checkPropertyUpdateChanges() |
| 59 | { |
| 60 | // GIVEN |
| 61 | TestArbiter arbiter; |
| 62 | Qt3DAnimation::QSkeletonMapping mapping; |
| 63 | arbiter.setArbiterOnNode(&mapping); |
| 64 | |
| 65 | { |
| 66 | // WHEN |
| 67 | auto target = new Qt3DCore::QSkeleton(); |
| 68 | mapping.setSkeleton(target); |
| 69 | |
| 70 | // THEN |
| 71 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 72 | QCOMPARE(arbiter.dirtyNodes().front(), &mapping); |
| 73 | |
| 74 | arbiter.clear(); |
| 75 | |
| 76 | // WHEN |
| 77 | mapping.setSkeleton(target); |
| 78 | |
| 79 | // THEN |
| 80 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 81 | } |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | QTEST_MAIN(tst_QSkeletonMapping) |
| 86 | |
| 87 | #include "tst_qskeletonmapping.moc" |