1/****************************************************************************
2**
3** Copyright (C) 2016 Paul Lemire <paul.lemire350@gmail.com>
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/qeffect.h>
32#include <Qt3DRender/qtechnique.h>
33#include <Qt3DRender/qparameter.h>
34#include <Qt3DRender/private/qeffect_p.h>
35#include <Qt3DRender/private/effect_p.h>
36#include "qbackendnodetester.h"
37#include "testrenderer.h"
38
39
40class tst_Effect : public Qt3DCore::QBackendNodeTester
41{
42 Q_OBJECT
43
44private Q_SLOTS:
45
46 void checkInitialState()
47 {
48 // GIVEN
49 Qt3DRender::Render::Effect backendEffect;
50
51 // THEN
52 QCOMPARE(backendEffect.isEnabled(), false);
53 QVERIFY(backendEffect.peerId().isNull());
54 QVERIFY(backendEffect.techniques().empty());
55 }
56
57 void checkCleanupState()
58 {
59 // GIVEN
60 Qt3DRender::Render::Effect backendEffect;
61
62 // WHEN
63 backendEffect.setEnabled(true);
64
65 {
66 Qt3DRender::QEffect effect;
67 Qt3DRender::QTechnique technique;
68 Qt3DRender::QParameter parameter;
69 effect.addTechnique(t: &technique);
70 effect.addParameter(parameter: &parameter);
71 simulateInitializationSync(frontend: &effect, backend: &backendEffect);
72 }
73
74 backendEffect.cleanup();
75
76 // THEN
77 QCOMPARE(backendEffect.isEnabled(), false);
78 QCOMPARE(backendEffect.techniques().size(), 0);
79 }
80
81 void checkInitializeFromPeer()
82 {
83 // GIVEN
84 Qt3DRender::QEffect effect;
85 Qt3DRender::QTechnique technique;
86 Qt3DRender::QParameter parameter;
87
88 effect.addTechnique(t: &technique);
89 effect.addParameter(parameter: &parameter);
90
91 {
92 // WHEN
93 Qt3DRender::Render::Effect backendEffect;
94 simulateInitializationSync(frontend: &effect, backend: &backendEffect);
95
96 // THEN
97 QCOMPARE(backendEffect.isEnabled(), true);
98 QCOMPARE(backendEffect.peerId(), effect.id());
99 QCOMPARE(backendEffect.techniques().size(), 1);
100 QCOMPARE(backendEffect.techniques().first(), technique.id());
101 QCOMPARE(backendEffect.parameters().size(), 1);
102 QCOMPARE(backendEffect.parameters().first(), parameter.id());
103 }
104 {
105 // WHEN
106 Qt3DRender::Render::Effect backendEffect;
107 effect.setEnabled(false);
108 simulateInitializationSync(frontend: &effect, backend: &backendEffect);
109
110 // THEN
111 QCOMPARE(backendEffect.peerId(), effect.id());
112 QCOMPARE(backendEffect.isEnabled(), false);
113 }
114 }
115
116 void checkSceneChangeEvents()
117 {
118 // GIVEN
119 Qt3DRender::QEffect effect;
120 Qt3DRender::Render::Effect backendEffect;
121 TestRenderer renderer;
122 backendEffect.setRenderer(&renderer);
123 simulateInitializationSync(frontend: &effect, backend: &backendEffect);
124
125 {
126 // WHEN
127 const bool newValue = false;
128 effect.setEnabled(newValue);
129 backendEffect.syncFromFrontEnd(frontEnd: &effect, firstTime: false);
130
131 // THEN
132 QCOMPARE(backendEffect.isEnabled(), newValue);
133 }
134 {
135 Qt3DRender::QTechnique technique;
136 {
137 // WHEN
138 effect.addTechnique(t: &technique);
139 backendEffect.syncFromFrontEnd(frontEnd: &effect, firstTime: false);
140
141 // THEN
142 QCOMPARE(backendEffect.techniques().size(), 1);
143 QCOMPARE(backendEffect.techniques().first(), technique.id());
144 }
145 {
146 // WHEN
147 effect.removeTechnique(t: &technique);
148 backendEffect.syncFromFrontEnd(frontEnd: &effect, firstTime: false);
149
150 // THEN
151 QCOMPARE(backendEffect.techniques().size(), 0);
152 }
153 }
154 {
155 Qt3DRender::QParameter parameter;
156
157 {
158 // WHEN
159 effect.addParameter(parameter: &parameter);
160 backendEffect.syncFromFrontEnd(frontEnd: &effect, firstTime: false);
161
162 // THEN
163 QCOMPARE(backendEffect.parameters().size(), 1);
164 QCOMPARE(backendEffect.parameters().first(), parameter.id());
165 }
166 {
167 // WHEN
168 effect.removeParameter(parameter: &parameter);
169 backendEffect.syncFromFrontEnd(frontEnd: &effect, firstTime: false);
170
171 // THEN
172 QCOMPARE(backendEffect.parameters().size(), 0);
173 }
174 }
175 }
176
177};
178
179QTEST_MAIN(tst_Effect)
180
181#include "tst_effect.moc"
182

source code of qt3d/tests/auto/render/effect/tst_effect.cpp