1/****************************************************************************
2**
3** Copyright (C) 2016 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
30#include <QtTest/QTest>
31#include <Qt3DRender/qdispatchcompute.h>
32#include <Qt3DRender/private/qdispatchcompute_p.h>
33#include <QObject>
34#include <QSignalSpy>
35#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h>
36#include <Qt3DCore/qnodecreatedchange.h>
37#include "testpostmanarbiter.h"
38
39class tst_QDispatchCompute : public QObject
40{
41 Q_OBJECT
42
43private Q_SLOTS:
44
45 void checkDefaultConstruction()
46 {
47 // GIVEN
48 Qt3DRender::QDispatchCompute dispatchCompute;
49
50 // THEN
51 QCOMPARE(dispatchCompute.workGroupX(), 1);
52 QCOMPARE(dispatchCompute.workGroupY(), 1);
53 QCOMPARE(dispatchCompute.workGroupZ(), 1);
54 }
55
56 void checkPropertyChanges()
57 {
58 // GIVEN
59 Qt3DRender::QDispatchCompute dispatchCompute;
60
61 {
62 // WHEN
63 QSignalSpy spy(&dispatchCompute, SIGNAL(workGroupXChanged()));
64 const int newValue = 128;
65 dispatchCompute.setWorkGroupX(newValue);
66
67 // THEN
68 QVERIFY(spy.isValid());
69 QCOMPARE(dispatchCompute.workGroupX(), newValue);
70 QCOMPARE(spy.count(), 1);
71
72 // WHEN
73 spy.clear();
74 dispatchCompute.setWorkGroupX(newValue);
75
76 // THEN
77 QCOMPARE(dispatchCompute.workGroupX(), newValue);
78 QCOMPARE(spy.count(), 0);
79 }
80 {
81 // WHEN
82 QSignalSpy spy(&dispatchCompute, SIGNAL(workGroupYChanged()));
83 const int newValue = 1024;
84 dispatchCompute.setWorkGroupY(newValue);
85
86 // THEN
87 QVERIFY(spy.isValid());
88 QCOMPARE(dispatchCompute.workGroupY(), newValue);
89 QCOMPARE(spy.count(), 1);
90
91 // WHEN
92 spy.clear();
93 dispatchCompute.setWorkGroupY(newValue);
94
95 // THEN
96 QCOMPARE(dispatchCompute.workGroupY(), newValue);
97 QCOMPARE(spy.count(), 0);
98 }
99 {
100 // WHEN
101 QSignalSpy spy(&dispatchCompute, SIGNAL(workGroupZChanged()));
102 const int newValue = 32;
103 dispatchCompute.setWorkGroupZ(newValue);
104
105 // THEN
106 QVERIFY(spy.isValid());
107 QCOMPARE(dispatchCompute.workGroupZ(), newValue);
108 QCOMPARE(spy.count(), 1);
109
110 // WHEN
111 spy.clear();
112 dispatchCompute.setWorkGroupZ(newValue);
113
114 // THEN
115 QCOMPARE(dispatchCompute.workGroupZ(), newValue);
116 QCOMPARE(spy.count(), 0);
117 }
118 }
119
120 void checkCreationData()
121 {
122 // GIVEN
123 Qt3DRender::QDispatchCompute dispatchCompute;
124
125 dispatchCompute.setWorkGroupX(427);
126 dispatchCompute.setWorkGroupY(454);
127 dispatchCompute.setWorkGroupZ(383);
128
129 // WHEN
130 QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges;
131
132 {
133 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&dispatchCompute);
134 creationChanges = creationChangeGenerator.creationChanges();
135 }
136
137 // THEN
138 {
139 QCOMPARE(creationChanges.size(), 1);
140
141 const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QDispatchComputeData>>(src: creationChanges.first());
142 const Qt3DRender::QDispatchComputeData cloneData = creationChangeData->data;
143
144 QCOMPARE(dispatchCompute.workGroupX(), cloneData.workGroupX);
145 QCOMPARE(dispatchCompute.workGroupY(), cloneData.workGroupY);
146 QCOMPARE(dispatchCompute.workGroupZ(), cloneData.workGroupZ);
147 QCOMPARE(dispatchCompute.id(), creationChangeData->subjectId());
148 QCOMPARE(dispatchCompute.isEnabled(), true);
149 QCOMPARE(dispatchCompute.isEnabled(), creationChangeData->isNodeEnabled());
150 QCOMPARE(dispatchCompute.metaObject(), creationChangeData->metaObject());
151 }
152
153 // WHEN
154 dispatchCompute.setEnabled(false);
155
156 {
157 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&dispatchCompute);
158 creationChanges = creationChangeGenerator.creationChanges();
159 }
160
161 // THEN
162 {
163 QCOMPARE(creationChanges.size(), 1);
164
165 const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QDispatchComputeData>>(src: creationChanges.first());
166 const Qt3DRender::QDispatchComputeData cloneData = creationChangeData->data;
167
168 QCOMPARE(dispatchCompute.workGroupX(), cloneData.workGroupX);
169 QCOMPARE(dispatchCompute.workGroupY(), cloneData.workGroupY);
170 QCOMPARE(dispatchCompute.workGroupZ(), cloneData.workGroupZ);
171 QCOMPARE(dispatchCompute.id(), creationChangeData->subjectId());
172 QCOMPARE(dispatchCompute.isEnabled(), false);
173 QCOMPARE(dispatchCompute.isEnabled(), creationChangeData->isNodeEnabled());
174 QCOMPARE(dispatchCompute.metaObject(), creationChangeData->metaObject());
175 }
176 }
177
178 void checkWorkGroupXUpdate()
179 {
180 // GIVEN
181 TestArbiter arbiter;
182 Qt3DRender::QDispatchCompute dispatchCompute;
183 arbiter.setArbiterOnNode(&dispatchCompute);
184
185 {
186 // WHEN
187 dispatchCompute.setWorkGroupX(883);
188 QCoreApplication::processEvents();
189
190 // THEN
191 QCOMPARE(arbiter.events.size(), 0);
192 QCOMPARE(arbiter.dirtyNodes.size(), 1);
193 QCOMPARE(arbiter.dirtyNodes.front(), &dispatchCompute);
194
195 arbiter.dirtyNodes.clear();
196 }
197
198 {
199 // WHEN
200 dispatchCompute.setWorkGroupX(883);
201 QCoreApplication::processEvents();
202
203 // THEN
204 QCOMPARE(arbiter.events.size(), 0);
205 QCOMPARE(arbiter.dirtyNodes.size(), 0);
206 }
207
208 }
209
210 void checkWorkGroupYUpdate()
211 {
212 // GIVEN
213 TestArbiter arbiter;
214 Qt3DRender::QDispatchCompute dispatchCompute;
215 arbiter.setArbiterOnNode(&dispatchCompute);
216
217 {
218 // WHEN
219 dispatchCompute.setWorkGroupY(1340);
220 QCoreApplication::processEvents();
221
222 // THEN
223 QCOMPARE(arbiter.events.size(), 0);
224 QCOMPARE(arbiter.dirtyNodes.size(), 1);
225 QCOMPARE(arbiter.dirtyNodes.front(), &dispatchCompute);
226
227 arbiter.dirtyNodes.clear();
228 }
229
230 {
231 // WHEN
232 dispatchCompute.setWorkGroupY(1340);
233 QCoreApplication::processEvents();
234
235 // THEN
236 QCOMPARE(arbiter.events.size(), 0);
237 QCOMPARE(arbiter.dirtyNodes.size(), 0);
238 }
239
240 }
241
242 void checkWorkGroupZUpdate()
243 {
244 // GIVEN
245 TestArbiter arbiter;
246 Qt3DRender::QDispatchCompute dispatchCompute;
247 arbiter.setArbiterOnNode(&dispatchCompute);
248
249 {
250 // WHEN
251 dispatchCompute.setWorkGroupZ(1584);
252 QCoreApplication::processEvents();
253
254 // THEN
255 QCOMPARE(arbiter.events.size(), 0);
256 QCOMPARE(arbiter.dirtyNodes.size(), 1);
257 QCOMPARE(arbiter.dirtyNodes.front(), &dispatchCompute);
258
259 arbiter.dirtyNodes.clear();
260 }
261
262 {
263 // WHEN
264 dispatchCompute.setWorkGroupZ(1584);
265 QCoreApplication::processEvents();
266
267 // THEN
268 QCOMPARE(arbiter.events.size(), 0);
269 QCOMPARE(arbiter.dirtyNodes.size(), 0);
270 }
271
272 }
273
274};
275
276QTEST_MAIN(tst_QDispatchCompute)
277
278#include "tst_qdispatchcompute.moc"
279

source code of qt3d/tests/auto/render/qdispatchcompute/tst_qdispatchcompute.cpp