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 <Qt3DExtras/qforwardrenderer.h>
32#include <Qt3DCore/qentity.h>
33#include <QObject>
34#include <QSignalSpy>
35
36class tst_QForwardRenderer : public QObject
37{
38 Q_OBJECT
39
40private Q_SLOTS:
41
42 void initTestCase()
43 {
44 qRegisterMetaType<Qt3DCore::QEntity*>();
45 }
46
47 void checkDefaultConstruction()
48 {
49 // GIVEN
50 Qt3DExtras::QForwardRenderer forwardRenderer;
51
52 // THEN
53 QVERIFY(forwardRenderer.surface() == nullptr);
54 QCOMPARE(forwardRenderer.viewportRect(), QRectF(0.0f, 0.0f, 1.0f, 1.0f));
55 QCOMPARE(forwardRenderer.clearColor(), QColor(Qt::white));
56 QVERIFY(forwardRenderer.camera() == nullptr);
57 QCOMPARE(forwardRenderer.externalRenderTargetSize(), QSize());
58 QVERIFY(forwardRenderer.isFrustumCullingEnabled());
59 QCOMPARE(forwardRenderer.gamma(), 2.2f);
60 }
61
62 void checkPropertyChanges()
63 {
64 // GIVEN
65 Qt3DExtras::QForwardRenderer forwardRenderer;
66
67 {
68 // WHEN
69 QSignalSpy spy(&forwardRenderer, SIGNAL(surfaceChanged(QObject *)));
70 QWindow newValue;
71 forwardRenderer.setSurface(&newValue);
72
73 // THEN
74 QCOMPARE(forwardRenderer.surface(), &newValue);
75 QCOMPARE(spy.count(), 1);
76
77 // WHEN
78 spy.clear();
79 forwardRenderer.setSurface(&newValue);
80
81 // THEN
82 QCOMPARE(forwardRenderer.surface(), &newValue);
83 QCOMPARE(spy.count(), 0);
84
85 // WHEN
86 forwardRenderer.setSurface(nullptr);
87
88 // THEN
89 QVERIFY(forwardRenderer.surface() == nullptr);
90 QCOMPARE(spy.count(), 1);
91 }
92 {
93 // WHEN
94 QSignalSpy spy(&forwardRenderer, SIGNAL(viewportRectChanged(QRectF)));
95 const QRectF newValue = QRectF(0.5, 0.5, 0.5, 0.5);
96 forwardRenderer.setViewportRect(newValue);
97
98 // THEN
99 QCOMPARE(forwardRenderer.viewportRect(), newValue);
100 QCOMPARE(spy.count(), 1);
101
102 // WHEN
103 spy.clear();
104 forwardRenderer.setViewportRect(newValue);
105
106 // THEN
107 QCOMPARE(forwardRenderer.viewportRect(), newValue);
108 QCOMPARE(spy.count(), 0);
109
110 }
111 {
112 // WHEN
113 QSignalSpy spy(&forwardRenderer, SIGNAL(clearColorChanged(QColor)));
114 const QColor newValue = QColor(Qt::red);
115 forwardRenderer.setClearColor(newValue);
116
117 // THEN
118 QCOMPARE(forwardRenderer.clearColor(), newValue);
119 QCOMPARE(spy.count(), 1);
120
121 // WHEN
122 spy.clear();
123 forwardRenderer.setClearColor(newValue);
124
125 // THEN
126 QCOMPARE(forwardRenderer.clearColor(), newValue);
127 QCOMPARE(spy.count(), 0);
128
129 }
130 {
131 // WHEN
132 QSignalSpy spy(&forwardRenderer, SIGNAL(cameraChanged(Qt3DCore::QEntity *)));
133 Qt3DCore::QEntity newValue;
134 forwardRenderer.setCamera(&newValue);
135
136 // THEN
137 QCOMPARE(forwardRenderer.camera(), &newValue);
138 QCOMPARE(spy.count(), 1);
139
140 // WHEN
141 spy.clear();
142 forwardRenderer.setCamera(&newValue);
143
144 // THEN
145 QCOMPARE(forwardRenderer.camera(), &newValue);
146 QCOMPARE(spy.count(), 0);
147
148 }
149 {
150 // WHEN
151 QSignalSpy spy(&forwardRenderer, SIGNAL(externalRenderTargetSizeChanged(QSize)));
152 const QSize newValue = QSize(454, 427);
153 forwardRenderer.setExternalRenderTargetSize(newValue);
154
155 // THEN
156 QCOMPARE(forwardRenderer.externalRenderTargetSize(), newValue);
157 QCOMPARE(spy.count(), 1);
158
159 // WHEN
160 spy.clear();
161 forwardRenderer.setExternalRenderTargetSize(newValue);
162
163 // THEN
164 QCOMPARE(forwardRenderer.externalRenderTargetSize(), newValue);
165 QCOMPARE(spy.count(), 0);
166
167 }
168 {
169 // WHEN
170 QSignalSpy spy(&forwardRenderer, SIGNAL(frustumCullingEnabledChanged(bool)));
171 forwardRenderer.setFrustumCullingEnabled(false);
172
173 // THEN
174 QVERIFY(!forwardRenderer.isFrustumCullingEnabled());
175 QCOMPARE(spy.count(), 1);
176 QVERIFY(!spy.takeFirst().takeFirst().toBool());
177
178 // WHEN
179 forwardRenderer.setFrustumCullingEnabled(false);
180
181 // THEN
182 QVERIFY(!forwardRenderer.isFrustumCullingEnabled());
183 QCOMPARE(spy.count(), 0);
184
185 // WHEN
186 forwardRenderer.setFrustumCullingEnabled(true);
187
188 // THEN
189 QVERIFY(forwardRenderer.isFrustumCullingEnabled());
190 QCOMPARE(spy.count(), 1);
191 QVERIFY(spy.takeFirst().takeFirst().toBool());
192 }
193 {
194 // WHEN
195 QSignalSpy spy(&forwardRenderer, SIGNAL(gammaChanged(float)));
196 const float newValue = 1.8f;
197 forwardRenderer.setGamma(newValue);
198
199 // THEN
200 QCOMPARE(forwardRenderer.gamma(), newValue);
201 QCOMPARE(spy.count(), 1);
202 QCOMPARE(spy.takeFirst().first().toFloat(), 1.8f);
203
204 // WHEN
205 spy.clear();
206 forwardRenderer.setClearColor(newValue);
207
208 // THEN
209 QCOMPARE(forwardRenderer.gamma(), newValue);
210 QCOMPARE(spy.count(), 0);
211
212 }
213 }
214
215};
216
217QTEST_MAIN(tst_QForwardRenderer)
218
219#include "tst_qforwardrenderer.moc"
220

source code of qt3d/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp