| 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 <Qt3DCore/qskeletonloader.h> |
| 7 | #include <Qt3DCore/qjoint.h> |
| 8 | #include <Qt3DCore/private/qskeletonloader_p.h> |
| 9 | #include <QObject> |
| 10 | #include <QSignalSpy> |
| 11 | #include <testarbiter.h> |
| 12 | |
| 13 | using namespace Qt3DCore; |
| 14 | |
| 15 | class tst_QSkeletonLoader : public QSkeletonLoader |
| 16 | { |
| 17 | Q_OBJECT |
| 18 | |
| 19 | private Q_SLOTS: |
| 20 | void checkDefaultConstruction() |
| 21 | { |
| 22 | // GIVEN |
| 23 | QSkeletonLoader skeleton; |
| 24 | |
| 25 | // THEN |
| 26 | QCOMPARE(skeleton.source(), QUrl()); |
| 27 | QCOMPARE(skeleton.status(), QSkeletonLoader::NotReady); |
| 28 | QCOMPARE(skeleton.isCreateJointsEnabled(), false); |
| 29 | } |
| 30 | |
| 31 | void checkPropertyChanges() |
| 32 | { |
| 33 | // GIVEN |
| 34 | QSkeletonLoader skeleton; |
| 35 | |
| 36 | { |
| 37 | // WHEN |
| 38 | QSignalSpy spy(&skeleton, SIGNAL(sourceChanged(QUrl))); |
| 39 | const QUrl newValue(QStringLiteral("qrc:/zergling.skel")); |
| 40 | skeleton.setSource(newValue); |
| 41 | |
| 42 | // THEN |
| 43 | QVERIFY(spy.isValid()); |
| 44 | QCOMPARE(skeleton.source(), newValue); |
| 45 | QCOMPARE(spy.size(), 1); |
| 46 | |
| 47 | // WHEN |
| 48 | spy.clear(); |
| 49 | skeleton.setSource(newValue); |
| 50 | |
| 51 | // THEN |
| 52 | QCOMPARE(skeleton.source(), newValue); |
| 53 | QCOMPARE(spy.size(), 0); |
| 54 | } |
| 55 | |
| 56 | { |
| 57 | // WHEN |
| 58 | QSignalSpy spy(&skeleton, SIGNAL(createJointsEnabledChanged(bool))); |
| 59 | const bool newValue(true); |
| 60 | skeleton.setCreateJointsEnabled(newValue); |
| 61 | |
| 62 | // THEN |
| 63 | QVERIFY(spy.isValid()); |
| 64 | QCOMPARE(skeleton.isCreateJointsEnabled(), newValue); |
| 65 | QCOMPARE(spy.size(), 1); |
| 66 | |
| 67 | // WHEN |
| 68 | spy.clear(); |
| 69 | skeleton.setCreateJointsEnabled(newValue); |
| 70 | |
| 71 | // THEN |
| 72 | QCOMPARE(skeleton.isCreateJointsEnabled(), newValue); |
| 73 | QCOMPARE(spy.size(), 0); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void checkPropertyUpdates() |
| 78 | { |
| 79 | // GIVEN |
| 80 | TestArbiter arbiter; |
| 81 | QSkeletonLoader skeleton; |
| 82 | arbiter.setArbiterOnNode(&skeleton); |
| 83 | |
| 84 | { |
| 85 | // WHEN |
| 86 | skeleton.setSource(QUrl(QStringLiteral("qrc:/hydralisk.skel"))); |
| 87 | QCoreApplication::processEvents(); |
| 88 | |
| 89 | // THEN |
| 90 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 91 | QCOMPARE(arbiter.dirtyNodes()[0], &skeleton); |
| 92 | |
| 93 | arbiter.clear(); |
| 94 | } |
| 95 | |
| 96 | { |
| 97 | // WHEN |
| 98 | skeleton.setSource(QStringLiteral("qrc:/hydralisk.skel")); |
| 99 | QCoreApplication::processEvents(); |
| 100 | |
| 101 | // THEN |
| 102 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 103 | } |
| 104 | |
| 105 | { |
| 106 | // WHEN |
| 107 | skeleton.setCreateJointsEnabled(true); |
| 108 | QCoreApplication::processEvents(); |
| 109 | |
| 110 | // THEN |
| 111 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 112 | QCOMPARE(arbiter.dirtyNodes()[0], &skeleton); |
| 113 | |
| 114 | arbiter.clear(); |
| 115 | } |
| 116 | |
| 117 | { |
| 118 | // WHEN |
| 119 | skeleton.setCreateJointsEnabled(true); |
| 120 | QCoreApplication::processEvents(); |
| 121 | |
| 122 | // THEN |
| 123 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 124 | } |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | QTEST_MAIN(tst_QSkeletonLoader) |
| 129 | |
| 130 | #include "tst_qskeletonloader.moc" |