1/****************************************************************************
2**
3** Copyright (C) 2018 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:LGPL$
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 Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40// TODO Remove in Qt6
41#include <QtCore/qcompilerdetection.h>
42QT_WARNING_DISABLE_DEPRECATED
43
44#include <QtTest/QTest>
45#include <Qt3DRender/qsetfence.h>
46#include <Qt3DRender/private/qsetfence_p.h>
47#include <QObject>
48#include <QSignalSpy>
49#include <Qt3DCore/qpropertyupdatedchange.h>
50#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h>
51#include <Qt3DCore/qnodecreatedchange.h>
52#include <Qt3DCore/private/qscene_p.h>
53#include "testpostmanarbiter.h"
54
55class MySetFence : public Qt3DRender::QSetFence
56{
57public:
58 using Qt3DRender::QSetFence::sceneChangeEvent;
59};
60
61class tst_QSetFence : public QObject
62{
63 Q_OBJECT
64
65private Q_SLOTS:
66
67 void initTestCase()
68 {
69 qRegisterMetaType<Qt3DRender::QSetFence::HandleType>(typeName: "HandleType");
70 }
71
72 void checkDefaultConstruction()
73 {
74 // GIVEN
75 Qt3DRender::QSetFence setFence;
76
77 // THEN
78 QCOMPARE(setFence.handleType(), Qt3DRender::QSetFence::NoHandle);
79 QCOMPARE(setFence.handle(), QVariant());
80 }
81
82 void checkPropertyChanges()
83 {
84 // GIVEN
85 Qt3DCore::QScene scene;
86 MySetFence setFence;
87
88 Qt3DCore::QNodePrivate::get(q: &setFence)->setScene(&scene);
89
90 {
91 // WHEN
92 QSignalSpy spy(&setFence, SIGNAL(handleTypeChanged(HandleType)));
93
94 // THEN
95 QVERIFY(spy.isValid());
96
97 // THEN
98 Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
99 valueChange->setPropertyName("handleType");
100 valueChange->setValue(QVariant::fromValue(value: Qt3DRender::QSetFence::OpenGLFenceId));
101 setFence.sceneChangeEvent(change: valueChange);
102
103 // THEN
104 QCOMPARE(setFence.handleType(), Qt3DRender::QSetFence::OpenGLFenceId);
105 QCOMPARE(spy.count(), 1);
106
107 // WHEN
108 spy.clear();
109 setFence.sceneChangeEvent(change: valueChange);
110
111 // THEN
112 QCOMPARE(spy.count(), 0);
113 }
114
115 {
116 // WHEN
117 QSignalSpy spy(&setFence, SIGNAL(handleChanged(QVariant)));
118
119 // THEN
120 QVERIFY(spy.isValid());
121
122 // WHEN
123 Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
124 valueChange->setPropertyName("handle");
125 valueChange->setValue(QVariant(984));
126 setFence.sceneChangeEvent(change: valueChange);
127
128 // THEN
129 QCOMPARE(setFence.handle(),QVariant(984));
130 QCOMPARE(spy.count(), 1);
131
132 // WHEN
133 spy.clear();
134 setFence.sceneChangeEvent(change: valueChange);
135
136 // THEN
137 QCOMPARE(spy.count(), 0);
138 }
139 }
140
141 void checkCreationData()
142 {
143 // GIVEN
144 Qt3DRender::QSetFence setFence;
145
146
147 // WHEN
148 QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges;
149
150 {
151 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&setFence);
152 creationChanges = creationChangeGenerator.creationChanges();
153 }
154
155 // THEN
156 {
157 QCOMPARE(creationChanges.size(), 1);
158
159 const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QSetFenceData>>(src: creationChanges.first());
160
161 QCOMPARE(setFence.id(), creationChangeData->subjectId());
162 QCOMPARE(setFence.isEnabled(), true);
163 QCOMPARE(setFence.isEnabled(), creationChangeData->isNodeEnabled());
164 QCOMPARE(setFence.metaObject(), creationChangeData->metaObject());
165 }
166
167 // WHEN
168 setFence.setEnabled(false);
169
170 {
171 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&setFence);
172 creationChanges = creationChangeGenerator.creationChanges();
173 }
174
175 // THEN
176 {
177 QCOMPARE(creationChanges.size(), 1);
178
179 const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QSetFenceData>>(src: creationChanges.first());
180
181 QCOMPARE(setFence.id(), creationChangeData->subjectId());
182 QCOMPARE(setFence.isEnabled(), false);
183 QCOMPARE(setFence.isEnabled(), creationChangeData->isNodeEnabled());
184 QCOMPARE(setFence.metaObject(), creationChangeData->metaObject());
185 }
186 }
187
188};
189
190QTEST_MAIN(tst_QSetFence)
191
192#include "tst_qsetfence.moc"
193

source code of qt3d/tests/auto/render/qsetfence/tst_qsetfence.cpp