Debian Codegraph @

tests/auto/render/qenvironmentlight/tst_qenvironmentlight.cpp

raw symbols SCIP
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QtTest/QTest>
5 #include <QSignalSpy>
6
7 #include <Qt3DRender/qtexture.h>
8 #include <Qt3DRender/qenvironmentlight.h>
9 #include <Qt3DRender/private/qenvironmentlight_p.h>
10 #include <Qt3DRender/private/qshaderdata_p.h>
11
12 #include "testarbiter.h"
13
14 class tst_QEnvironmentLight: public QObject
15 {
16 Q_OBJECT
17 private Q_SLOTS:
18 void checkDefaultConstruction()
19 {
20 // GIVEN
21 Qt3DRender::QEnvironmentLight light;
22
23 // THEN
24 QVERIFY(light.findChild<Qt3DRender::QShaderData*>());
25 QCOMPARE(light.irradiance(), nullptr);
26 QCOMPARE(light.specular(), nullptr);
27 }
28
29 void shouldTakeOwnershipOfParentlessTextures()
30 {
31 // GIVEN
32 Qt3DRender::QEnvironmentLight light;
33 auto irradiance = new Qt3DRender::QTexture2D;
34 auto specular = new Qt3DRender::QTexture2D;
35
36 // WHEN
37 light.setIrradiance(irradiance);
38 light.setSpecular(specular);
39
40 // THEN
41 QCOMPARE(irradiance->parent(), &light);
42 QCOMPARE(specular->parent(), &light);
43 }
44
45 void shouldNotChangeOwnershipOfParentedTextures()
46 {
47 // GIVEN
48 Qt3DCore::QNode node;
49 Qt3DRender::QEnvironmentLight light;
50 auto irradiance = new Qt3DRender::QTexture2D(&node);
51 auto specular = new Qt3DRender::QTexture2D(&node);
52
53 // WHEN
54 light.setIrradiance(irradiance);
55 light.setSpecular(specular);
56
57 // WHEN
58 delete irradiance;
59 delete specular;
60
61 // THEN
62 }
63
64 void checkPropertyChanges()
65 {
66 // GIVEN
67 Qt3DRender::QEnvironmentLight light;
68 auto shaderData = light.findChild<Qt3DRender::QShaderData*>();
69
70 {
71 auto texture = new Qt3DRender::QTexture2D(&light);
72 QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::irradianceChanged);
73
74 // WHEN
75 light.setIrradiance(texture);
76
77 // THEN
78 QCOMPARE(light.irradiance(), texture);
79 QCOMPARE(shaderData->property("irradiance").value<Qt3DRender::QAbstractTexture*>(), texture);
80 QCOMPARE(spy.size(), 1);
81 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), texture);
82
83 // WHEN
84 light.setIrradiance(texture);
85
86 // THEN
87 QCOMPARE(light.irradiance(), texture);
88 QCOMPARE(shaderData->property("irradiance").value<Qt3DRender::QAbstractTexture*>(), texture);
89 QCOMPARE(spy.size(), 0);
90
91 // WHEN
92 light.setIrradiance(nullptr);
93
94 // THEN
95 QCOMPARE(light.irradiance(), nullptr);
96 QCOMPARE(shaderData->property("irradiance").value<Qt3DRender::QAbstractTexture*>(), nullptr);
97 QCOMPARE(spy.size(), 1);
98 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), nullptr);
99 }
100 {
101 auto texture = new Qt3DRender::QTexture2D(&light);
102 QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::irradianceChanged);
103
104 // WHEN
105 light.setIrradiance(texture);
106
107 // THEN
108 QCOMPARE(light.irradiance(), texture);
109 QCOMPARE(shaderData->property("irradiance").value<Qt3DRender::QAbstractTexture*>(), texture);
110 QCOMPARE(spy.size(), 1);
111 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), texture);
112
113 // WHEN
114 delete texture;
115
116 // THEN
117 QCOMPARE(light.irradiance(), nullptr);
118 QCOMPARE(shaderData->property("irradiance").value<Qt3DRender::QAbstractTexture*>(), nullptr);
119 QCOMPARE(spy.size(), 1);
120 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), nullptr);
121 }
122 {
123 auto texture = new Qt3DRender::QTexture2D;
124 QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::irradianceChanged);
125
126 // WHEN
127 light.setIrradiance(texture);
128
129 // THEN
130 QCOMPARE(light.irradiance(), texture);
131 QCOMPARE(shaderData->property("irradiance").value<Qt3DRender::QAbstractTexture*>(), texture);
132 QCOMPARE(spy.size(), 1);
133 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), texture);
134
135 // WHEN
136 delete texture;
137
138 // THEN
139 QCOMPARE(light.irradiance(), nullptr);
140 QCOMPARE(shaderData->property("irradiance").value<Qt3DRender::QAbstractTexture*>(), nullptr);
141 QCOMPARE(spy.size(), 1);
142 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), nullptr);
143 }
144 {
145 auto texture = new Qt3DRender::QTexture2D(&light);
146 QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::irradianceChanged);
147
148 // WHEN
149 light.setIrradiance(texture);
150
151 // THEN
152 QCOMPARE(light.irradiance(), texture);
153 QCOMPARE(shaderData->property("irradiance").value<Qt3DRender::QAbstractTexture*>(), texture);
154 QCOMPARE(shaderData->property("irradianceSize").value<QVector3D>(),
155 QVector3D(texture->width(), texture->height(), texture->depth()));
156 QCOMPARE(spy.size(), 1);
157 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), texture);
158
159 // WHEN
160 texture->setWidth(883);
161
162 // THEN
163 QCOMPARE(shaderData->property("irradianceSize").value<QVector3D>(),
164 QVector3D(883.0f, texture->height(), texture->depth()));
165
166 // WHEN
167 texture->setHeight(1340);
168
169 // THEN
170 QCOMPARE(shaderData->property("irradianceSize").value<QVector3D>(),
171 QVector3D(883.0f, 1340.0f, texture->depth()));
172
173 // WHEN
174 texture->setDepth(1584);
175
176 // THEN
177 QCOMPARE(shaderData->property("irradianceSize").value<QVector3D>(),
178 QVector3D(883.0f, 1340.0f, 1584.0f));
179
180 // WHEN
181 delete texture;
182
183 // THEN
184 QCOMPARE(light.irradiance(), nullptr);
185 QCOMPARE(shaderData->property("irradiance").value<Qt3DRender::QAbstractTexture*>(), nullptr);
186 QCOMPARE(spy.size(), 1);
187 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), nullptr);
188
189 // THEN
190 QCOMPARE(shaderData->property("irradianceSize").value<QVector3D>(),
191 QVector3D());
192 }
193 {
194 auto texture = new Qt3DRender::QTexture2D(&light);
195 QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::specularChanged);
196
197 // WHEN
198 light.setSpecular(texture);
199
200 // THEN
201 QCOMPARE(light.specular(), texture);
202 QCOMPARE(shaderData->property("specular").value<Qt3DRender::QAbstractTexture*>(), texture);
203 QCOMPARE(spy.size(), 1);
204 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), texture);
205
206 // WHEN
207 light.setSpecular(texture);
208
209 // THEN
210 QCOMPARE(light.specular(), texture);
211 QCOMPARE(shaderData->property("specular").value<Qt3DRender::QAbstractTexture*>(), texture);
212 QCOMPARE(spy.size(), 0);
213
214 // WHEN
215 light.setSpecular(nullptr);
216
217 // THEN
218 QCOMPARE(light.specular(), nullptr);
219 QCOMPARE(shaderData->property("specular").value<Qt3DRender::QAbstractTexture*>(), nullptr);
220 QCOMPARE(spy.size(), 1);
221 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), nullptr);
222 }
223 {
224 auto texture = new Qt3DRender::QTexture2D(&light);
225 QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::specularChanged);
226
227 // WHEN
228 light.setSpecular(texture);
229
230 // THEN
231 QCOMPARE(light.specular(), texture);
232 QCOMPARE(shaderData->property("specular").value<Qt3DRender::QAbstractTexture*>(), texture);
233 QCOMPARE(spy.size(), 1);
234 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), texture);
235
236 // WHEN
237 delete texture;
238
239 // THEN
240 QCOMPARE(light.specular(), nullptr);
241 QCOMPARE(shaderData->property("specular").value<Qt3DRender::QAbstractTexture*>(), nullptr);
242 QCOMPARE(spy.size(), 1);
243 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), nullptr);
244 }
245 {
246 auto texture = new Qt3DRender::QTexture2D;
247 QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::specularChanged);
248
249 // WHEN
250 light.setSpecular(texture);
251
252 // THEN
253 QCOMPARE(light.specular(), texture);
254 QCOMPARE(shaderData->property("specular").value<Qt3DRender::QAbstractTexture*>(), texture);
255 QCOMPARE(spy.size(), 1);
256 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), texture);
257
258 // WHEN
259 delete texture;
260
261 // THEN
262 QCOMPARE(light.specular(), nullptr);
263 QCOMPARE(shaderData->property("specular").value<Qt3DRender::QAbstractTexture*>(), nullptr);
264 QCOMPARE(spy.size(), 1);
265 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), nullptr);
266 }
267 {
268 auto texture = new Qt3DRender::QTexture2D(&light);
269 QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::specularChanged);
270
271 // WHEN
272 light.setSpecular(texture);
273
274 // THEN
275 QCOMPARE(light.specular(), texture);
276 QCOMPARE(shaderData->property("specular").value<Qt3DRender::QAbstractTexture*>(), texture);
277 QCOMPARE(shaderData->property("specularSize").value<QVector3D>(),
278 QVector3D(texture->width(), texture->height(), texture->depth()));
279 QCOMPARE(spy.size(), 1);
280 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), texture);
281
282 // WHEN
283 texture->setWidth(883);
284
285 // THEN
286 QCOMPARE(shaderData->property("specularSize").value<QVector3D>(),
287 QVector3D(883.0f, texture->height(), texture->depth()));
288
289 // WHEN
290 texture->setHeight(1340);
291
292 // THEN
293 QCOMPARE(shaderData->property("specularSize").value<QVector3D>(),
294 QVector3D(883.0f, 1340.0f, texture->depth()));
295
296 // WHEN
297 texture->setDepth(1584);
298
299 // THEN
300 QCOMPARE(shaderData->property("specularSize").value<QVector3D>(),
301 QVector3D(883.0f, 1340.0f, 1584.0f));
302
303 // WHEN
304 delete texture;
305
306 // THEN
307 QCOMPARE(light.specular(), nullptr);
308 QCOMPARE(shaderData->property("specular").value<Qt3DRender::QAbstractTexture*>(), nullptr);
309 QCOMPARE(spy.size(), 1);
310 QCOMPARE(spy.takeFirst().first().value<Qt3DRender::QAbstractTexture*>(), nullptr);
311
312 // THEN
313 QCOMPARE(shaderData->property("specularSize").value<QVector3D>(),
314 QVector3D());
315 }
316 }
317 };
318
319 QTEST_MAIN(tst_QEnvironmentLight)
320
321 #include "tst_qenvironmentlight.moc"