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 <Qt3DRender/private/armature_p.h>
31#include <Qt3DCore/qarmature.h>
32#include <Qt3DCore/qskeleton.h>
33#include <Qt3DCore/private/qnode_p.h>
34#include <Qt3DCore/private/qscene_p.h>
35#include <Qt3DCore/private/qbackendnode_p.h>
36#include <qbackendnodetester.h>
37#include <testpostmanarbiter.h>
38
39using namespace Qt3DCore;
40using namespace Qt3DRender;
41using namespace Qt3DRender::Render;
42
43class tst_Armature: public Qt3DCore::QBackendNodeTester
44{
45 Q_OBJECT
46
47private Q_SLOTS:
48 void checkPeerPropertyMirroring()
49 {
50 // GIVEN
51 Armature backendArmature;
52 QArmature armature;
53 auto skeleton = new QSkeleton;
54
55 armature.setSkeleton(skeleton);
56
57 // WHEN
58 simulateInitializationSync(frontend: &armature, backend: &backendArmature);
59
60 // THEN
61 QCOMPARE(backendArmature.peerId(), armature.id());
62 QCOMPARE(backendArmature.isEnabled(), armature.isEnabled());
63 QCOMPARE(backendArmature.skeletonId(), skeleton->id());
64 }
65
66 void checkInitialAndCleanedUpState()
67 {
68 // GIVEN
69 Armature backendArmature;
70
71 // THEN
72 QVERIFY(backendArmature.peerId().isNull());
73 QCOMPARE(backendArmature.isEnabled(), false);
74 QCOMPARE(backendArmature.skeletonId(), Qt3DCore::QNodeId());
75
76 // GIVEN
77 QArmature armature;
78 auto skeleton = new QSkeleton();
79 armature.setSkeleton(skeleton);
80
81 // WHEN
82 simulateInitializationSync(frontend: &armature, backend: &backendArmature);
83 backendArmature.cleanup();
84
85 // THEN
86 QCOMPARE(backendArmature.skeletonId(), Qt3DCore::QNodeId());
87 QCOMPARE(backendArmature.isEnabled(), false);
88 }
89
90 void checkPropertyChanges()
91 {
92 // GIVEN
93 QArmature armature;
94 Armature backendArmature;
95 simulateInitializationSync(frontend: &armature, backend: &backendArmature);
96
97 // WHEN
98 armature.setEnabled(false);
99 backendArmature.syncFromFrontEnd(frontEnd: &armature, firstTime: false);
100
101 // THEN
102 QCOMPARE(backendArmature.isEnabled(), false);
103
104 // WHEN
105 auto newSkeleton = new QSkeleton();
106 armature.setSkeleton(newSkeleton);
107 backendArmature.syncFromFrontEnd(frontEnd: &armature, firstTime: false);
108
109 // THEN
110 QCOMPARE(backendArmature.skeletonId(), newSkeleton->id());
111 }
112};
113
114QTEST_APPLESS_MAIN(tst_Armature)
115
116#include "tst_armature.moc"
117

source code of qt3d/tests/auto/render/armature/tst_armature.cpp