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/qfilterkey.h>
32#include <Qt3DRender/private/qfilterkey_p.h>
33#include <Qt3DRender/private/filterkey_p.h>
34#include "qbackendnodetester.h"
35#include "testrenderer.h"
36
37class tst_FilterKey : public Qt3DCore::QBackendNodeTester
38{
39 Q_OBJECT
40
41private Q_SLOTS:
42
43 void checkInitialState()
44 {
45 // GIVEN
46 Qt3DRender::Render::FilterKey backendFilterKey;
47
48 // THEN
49 QCOMPARE(backendFilterKey.isEnabled(), false);
50 QVERIFY(backendFilterKey.peerId().isNull());
51 QCOMPARE(backendFilterKey.value(), QVariant());
52 QCOMPARE(backendFilterKey.name(), QString());
53 }
54
55 void checkCleanupState()
56 {
57 // GIVEN
58 TestRenderer renderer;
59 Qt3DRender::Render::FilterKey backendFilterKey;
60
61 // WHEN
62 backendFilterKey.setRenderer(&renderer);
63 backendFilterKey.setEnabled(true);
64
65 {
66 Qt3DRender::QFilterKey filterKey;
67 filterKey.setName(QStringLiteral("Tim"));
68 filterKey.setValue(QVariant(QStringLiteral("McGraw")));
69 simulateInitializationSync(frontend: &filterKey, backend: &backendFilterKey);
70 }
71
72 backendFilterKey.cleanup();
73
74 // THEN
75 QCOMPARE(backendFilterKey.isEnabled(), false);
76 QCOMPARE(backendFilterKey.value(), QVariant());
77 QCOMPARE(backendFilterKey.name(), QString());
78 }
79
80 void checkInitializeFromPeer()
81 {
82 // GIVEN
83 TestRenderer renderer;
84 Qt3DRender::QFilterKey filterKey;
85 filterKey.setName(QStringLiteral("Dallas"));
86 filterKey.setValue(QVariant(QStringLiteral("Smith")));
87
88 {
89 // WHEN
90 Qt3DRender::Render::FilterKey backendFilterKey;
91 backendFilterKey.setRenderer(&renderer);
92 simulateInitializationSync(frontend: &filterKey, backend: &backendFilterKey);
93
94 // THEN
95 QCOMPARE(backendFilterKey.isEnabled(), true);
96 QCOMPARE(backendFilterKey.peerId(), filterKey.id());
97 QCOMPARE(backendFilterKey.value(), QVariant(QStringLiteral("Smith")));
98 QCOMPARE(backendFilterKey.name(), QStringLiteral("Dallas"));
99 }
100 {
101 // WHEN
102 Qt3DRender::Render::FilterKey backendFilterKey;
103 backendFilterKey.setRenderer(&renderer);
104 filterKey.setEnabled(false);
105 simulateInitializationSync(frontend: &filterKey, backend: &backendFilterKey);
106
107 // THEN
108 QCOMPARE(backendFilterKey.peerId(), filterKey.id());
109 QCOMPARE(backendFilterKey.isEnabled(), false);
110 }
111 }
112
113 void checkSceneChangeEvents()
114 {
115 // GIVEN
116 Qt3DRender::Render::FilterKey backendFilterKey;
117 Qt3DRender::QFilterKey frontend;
118 TestRenderer renderer;
119 backendFilterKey.setRenderer(&renderer);
120 simulateInitializationSync(frontend: &frontend, backend: &backendFilterKey);
121
122 {
123 // WHEN
124 const bool newValue = false;
125 frontend.setEnabled(newValue);
126 backendFilterKey.syncFromFrontEnd(frontEnd: &frontend, firstTime: false);
127
128 // THEN
129 QCOMPARE(backendFilterKey.isEnabled(), newValue);
130 }
131 {
132 // WHEN
133 const QVariant newValue(383.0f);
134 frontend.setValue(newValue);
135 backendFilterKey.syncFromFrontEnd(frontEnd: &frontend, firstTime: false);
136
137 // THEN
138 QCOMPARE(backendFilterKey.value(), newValue);
139 }
140 {
141 // WHEN
142 const QString newValue = QStringLiteral("Alan");
143 frontend.setName(newValue);
144 backendFilterKey.syncFromFrontEnd(frontEnd: &frontend, firstTime: false);
145
146 // THEN
147 QCOMPARE(backendFilterKey.name(), newValue);
148 }
149 }
150
151 void checkComparison()
152 {
153 // GIVEN
154 TestRenderer renderer;
155 Qt3DRender::Render::FilterKey backendFilterKey1;
156 Qt3DRender::Render::FilterKey backendFilterKey2;
157 Qt3DRender::Render::FilterKey backendFilterKey3;
158 Qt3DRender::Render::FilterKey backendFilterKey4;
159 backendFilterKey1.setRenderer(&renderer);
160 backendFilterKey2.setRenderer(&renderer);
161 backendFilterKey3.setRenderer(&renderer);
162 backendFilterKey4.setRenderer(&renderer);
163
164 // WHEN
165 {
166 Qt3DRender::QFilterKey filterKey1;
167 filterKey1.setName(QStringLiteral("Dallas"));
168 filterKey1.setValue(QVariant(QStringLiteral("Smith")));
169
170 simulateInitializationSync(frontend: &filterKey1, backend: &backendFilterKey1);
171 simulateInitializationSync(frontend: &filterKey1, backend: &backendFilterKey4);
172
173 Qt3DRender::QFilterKey filterKey2;
174 filterKey2.setName(QStringLiteral("Tim"));
175 filterKey2.setValue(QVariant(QStringLiteral("Smith")));
176
177 simulateInitializationSync(frontend: &filterKey2, backend: &backendFilterKey2);
178
179 Qt3DRender::QFilterKey filterKey3;
180 filterKey3.setName(QStringLiteral("Dallas"));
181 filterKey3.setValue(QVariant(QStringLiteral("McGraw")));
182
183 simulateInitializationSync(frontend: &filterKey3, backend: &backendFilterKey3);
184 }
185
186 // THEN
187 QVERIFY(backendFilterKey1 == backendFilterKey4);
188 QVERIFY(backendFilterKey4 == backendFilterKey1);
189 QVERIFY(backendFilterKey1 != backendFilterKey2);
190 QVERIFY(backendFilterKey2 != backendFilterKey1);
191 QVERIFY(backendFilterKey1 != backendFilterKey3);
192 QVERIFY(backendFilterKey3 != backendFilterKey2);
193 }
194
195};
196
197QTEST_MAIN(tst_FilterKey)
198
199#include "tst_filterkey.moc"
200

source code of qt3d/tests/auto/render/filterkey/tst_filterkey.cpp