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 <qbackendnodetester.h> |
31 | #include <Qt3DAnimation/private/handler_p.h> |
32 | #include <Qt3DAnimation/private/channelmapper_p.h> |
33 | #include <Qt3DAnimation/private/channelmapping_p.h> |
34 | #include <Qt3DAnimation/private/managers_p.h> |
35 | #include <Qt3DAnimation/qchannelmapper.h> |
36 | #include <Qt3DAnimation/qchannelmapping.h> |
37 | #include <Qt3DAnimation/private/qchannelmapper_p.h> |
38 | #include <Qt3DCore/private/qnode_p.h> |
39 | #include <Qt3DCore/private/qscene_p.h> |
40 | #include <Qt3DCore/private/qbackendnode_p.h> |
41 | #include "testpostmanarbiter.h" |
42 | |
43 | class tst_ChannelMapper : public Qt3DCore::QBackendNodeTester |
44 | { |
45 | Q_OBJECT |
46 | |
47 | private Q_SLOTS: |
48 | void checkPeerPropertyMirroring() |
49 | { |
50 | // GIVEN |
51 | Qt3DAnimation::Animation::Handler handler; |
52 | Qt3DAnimation::Animation::ChannelMapper backendMapper; |
53 | backendMapper.setHandler(&handler); |
54 | Qt3DAnimation::QChannelMapper mapper; |
55 | |
56 | mapper.addMapping(mapping: new Qt3DAnimation::QChannelMapping); |
57 | mapper.addMapping(mapping: new Qt3DAnimation::QChannelMapping); |
58 | |
59 | // WHEN |
60 | simulateInitializationSync(frontend: &mapper, backend: &backendMapper); |
61 | |
62 | // THEN |
63 | QCOMPARE(backendMapper.peerId(), mapper.id()); |
64 | QCOMPARE(backendMapper.isEnabled(), mapper.isEnabled()); |
65 | |
66 | const int mappingCount = backendMapper.mappingIds().size(); |
67 | if (mappingCount > 0) { |
68 | for (int i = 0; i < mappingCount; ++i) |
69 | QCOMPARE(backendMapper.mappingIds().at(i), mapper.mappings().at(i)->id()); |
70 | } |
71 | } |
72 | |
73 | void checkInitialAndCleanedUpState() |
74 | { |
75 | // GIVEN |
76 | Qt3DAnimation::Animation::Handler handler; |
77 | Qt3DAnimation::Animation::ChannelMapper backendMapper; |
78 | backendMapper.setHandler(&handler); |
79 | |
80 | // THEN |
81 | QVERIFY(backendMapper.peerId().isNull()); |
82 | QCOMPARE(backendMapper.isEnabled(), false); |
83 | QCOMPARE(backendMapper.mappingIds(), QVector<Qt3DCore::QNodeId>()); |
84 | |
85 | // GIVEN |
86 | Qt3DAnimation::QChannelMapper mapper; |
87 | mapper.addMapping(mapping: new Qt3DAnimation::QChannelMapping()); |
88 | |
89 | // WHEN |
90 | simulateInitializationSync(frontend: &mapper, backend: &backendMapper); |
91 | backendMapper.cleanup(); |
92 | |
93 | // THEN |
94 | QCOMPARE(backendMapper.isEnabled(), false); |
95 | QCOMPARE(backendMapper.mappingIds(), QVector<Qt3DCore::QNodeId>()); |
96 | } |
97 | |
98 | void checkPropertyChanges() |
99 | { |
100 | // GIVEN |
101 | Qt3DAnimation::QChannelMapper mapper; |
102 | Qt3DAnimation::Animation::Handler handler; |
103 | Qt3DAnimation::Animation::ChannelMapper backendMapper; |
104 | backendMapper.setHandler(&handler); |
105 | simulateInitializationSync(frontend: &mapper, backend: &backendMapper); |
106 | |
107 | // WHEN |
108 | mapper.setEnabled(false); |
109 | backendMapper.syncFromFrontEnd(frontEnd: &mapper, firstTime: false); |
110 | |
111 | // THEN |
112 | QCOMPARE(backendMapper.isEnabled(), false); |
113 | |
114 | // WHEN |
115 | Qt3DAnimation::QChannelMapping mapping; |
116 | const Qt3DCore::QNodeId mappingId = mapping.id(); |
117 | Qt3DAnimation::Animation::ChannelMapping *backendMapping |
118 | = handler.channelMappingManager()->getOrCreateResource(id: mappingId); |
119 | backendMapping->setHandler(&handler); |
120 | simulateInitializationSync(frontend: &mapping, backend: backendMapping); |
121 | |
122 | mapper.addMapping(mapping: &mapping); |
123 | backendMapper.syncFromFrontEnd(frontEnd: &mapper, firstTime: false); |
124 | |
125 | // THEN |
126 | QCOMPARE(backendMapper.mappingIds().size(), 1); |
127 | QCOMPARE(backendMapper.mappingIds().first(), mappingId); |
128 | QCOMPARE(backendMapper.mappings().size(), 1); |
129 | QCOMPARE(backendMapper.mappings().first(), backendMapping); |
130 | |
131 | // WHEN |
132 | Qt3DAnimation::QChannelMapping mapping2; |
133 | const Qt3DCore::QNodeId mappingId2 = mapping2.id(); |
134 | Qt3DAnimation::Animation::ChannelMapping *backendMapping2 |
135 | = handler.channelMappingManager()->getOrCreateResource(id: mappingId2); |
136 | backendMapping2->setHandler(&handler); |
137 | simulateInitializationSync(frontend: &mapping2, backend: backendMapping2); |
138 | |
139 | mapper.addMapping(mapping: &mapping2); |
140 | backendMapper.syncFromFrontEnd(frontEnd: &mapper, firstTime: false); |
141 | |
142 | // THEN |
143 | QCOMPARE(backendMapper.mappingIds().size(), 2); |
144 | QCOMPARE(backendMapper.mappingIds().first(), mappingId); |
145 | QCOMPARE(backendMapper.mappingIds().last(), mappingId2); |
146 | QCOMPARE(backendMapper.mappings().size(), 2); |
147 | QCOMPARE(backendMapper.mappings().first(), backendMapping); |
148 | QCOMPARE(backendMapper.mappings().last(), backendMapping2); |
149 | |
150 | // WHEN |
151 | mapper.removeMapping(mapping: &mapping); |
152 | backendMapper.syncFromFrontEnd(frontEnd: &mapper, firstTime: false); |
153 | |
154 | // THEN |
155 | QCOMPARE(backendMapper.mappingIds().size(), 1); |
156 | QCOMPARE(backendMapper.mappingIds().first(), mappingId2); |
157 | QCOMPARE(backendMapper.mappings().size(), 1); |
158 | QCOMPARE(backendMapper.mappings().first(), backendMapping2); |
159 | } |
160 | }; |
161 | |
162 | QTEST_MAIN(tst_ChannelMapper) |
163 | |
164 | #include "tst_channelmapper.moc" |
165 | |