1/****************************************************************************
2**
3** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QTest>
30#include <Qt3DAnimation/qskeletonmapping.h>
31#include <Qt3DAnimation/private/qskeletonmapping_p.h>
32#include <Qt3DCore/qskeleton.h>
33#include <Qt3DCore/qentity.h>
34#include <Qt3DCore/qnodecreatedchange.h>
35#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h>
36#include <QObject>
37#include <QSignalSpy>
38#include <testpostmanarbiter.h>
39
40class tst_QSkeletonMapping : public QObject
41{
42 Q_OBJECT
43
44private Q_SLOTS:
45 void initTestCase()
46 {
47 qRegisterMetaType<Qt3DCore::QAbstractSkeleton*>();
48 }
49
50 void checkDefaultConstruction()
51 {
52 // GIVEN
53 Qt3DAnimation::QSkeletonMapping mapping;
54
55 // THEN
56 QCOMPARE(mapping.skeleton(), static_cast<Qt3DCore::QAbstractSkeleton *>(nullptr));
57 }
58
59 void checkPropertyChanges()
60 {
61 // GIVEN
62 Qt3DAnimation::QSkeletonMapping mapping;
63
64 {
65 // WHEN
66 QSignalSpy spy(&mapping, SIGNAL(skeletonChanged(Qt3DCore::QAbstractSkeleton*)));
67 auto newValue = new Qt3DCore::QSkeleton();
68 mapping.setSkeleton(newValue);
69
70 // THEN
71 QVERIFY(spy.isValid());
72 QCOMPARE(mapping.skeleton(), newValue);
73 QCOMPARE(spy.count(), 1);
74
75 // WHEN
76 spy.clear();
77 mapping.setSkeleton(newValue);
78
79 // THEN
80 QCOMPARE(mapping.skeleton(), newValue);
81 QCOMPARE(spy.count(), 0);
82 }
83 }
84
85 void checkCreationData()
86 {
87 // GIVEN
88 Qt3DAnimation::QSkeletonMapping mapping;
89 auto target = new Qt3DCore::QSkeleton;
90
91 mapping.setSkeleton(target);
92
93 // WHEN
94 QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges;
95
96 {
97 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&mapping);
98 creationChanges = creationChangeGenerator.creationChanges();
99 }
100
101 // THEN
102 {
103 QCOMPARE(creationChanges.size(), 2); // 1 for mapping, 1 for skeleton
104
105 const auto creationChangeData = qSharedPointerCast<Qt3DAnimation::QChannelMappingCreatedChange<Qt3DAnimation::QSkeletonMappingData>>(src: creationChanges.first());
106 const Qt3DAnimation::QSkeletonMappingData data = creationChangeData->data;
107
108 QCOMPARE(mapping.id(), creationChangeData->subjectId());
109 QCOMPARE(mapping.isEnabled(), true);
110 QCOMPARE(mapping.isEnabled(), creationChangeData->isNodeEnabled());
111 QCOMPARE(mapping.metaObject(), creationChangeData->metaObject());
112 QCOMPARE(creationChangeData->type(), Qt3DAnimation::QChannelMappingCreatedChangeBase::SkeletonMapping);
113 QCOMPARE(mapping.skeleton()->id(), data.skeletonId);
114 }
115
116 // WHEN
117 mapping.setEnabled(false);
118
119 {
120 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&mapping);
121 creationChanges = creationChangeGenerator.creationChanges();
122 }
123
124 // THEN
125 {
126 QCOMPARE(creationChanges.size(), 2); // 1 for mapping, 1 for skeleton
127
128 const auto creationChangeData = qSharedPointerCast<Qt3DAnimation::QChannelMappingCreatedChange<Qt3DAnimation::QSkeletonMappingData>>(src: creationChanges.first());
129 const Qt3DAnimation::QSkeletonMappingData data = creationChangeData->data;
130
131 QCOMPARE(mapping.id(), creationChangeData->subjectId());
132 QCOMPARE(mapping.isEnabled(), false);
133 QCOMPARE(mapping.isEnabled(), creationChangeData->isNodeEnabled());
134 QCOMPARE(mapping.metaObject(), creationChangeData->metaObject());
135 QCOMPARE(creationChangeData->type(), Qt3DAnimation::QChannelMappingCreatedChangeBase::SkeletonMapping);
136 QCOMPARE(mapping.skeleton()->id(), data.skeletonId);
137 }
138 }
139
140 void checkPropertyUpdateChanges()
141 {
142 // GIVEN
143 TestArbiter arbiter;
144 Qt3DAnimation::QSkeletonMapping mapping;
145 arbiter.setArbiterOnNode(&mapping);
146
147 {
148 // WHEN
149 auto target = new Qt3DCore::QSkeleton();
150 mapping.setSkeleton(target);
151
152 // THEN
153 QCOMPARE(arbiter.dirtyNodes.size(), 1);
154 QCOMPARE(arbiter.dirtyNodes.front(), &mapping);
155
156 arbiter.dirtyNodes.clear();
157
158 // WHEN
159 mapping.setSkeleton(target);
160
161 // THEN
162 QCOMPARE(arbiter.dirtyNodes.size(), 0);
163 }
164 }
165};
166
167QTEST_MAIN(tst_QSkeletonMapping)
168
169#include "tst_qskeletonmapping.moc"
170

source code of qt3d/tests/auto/animation/qskeletonmapping/tst_qskeletonmapping.cpp