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 <Qt3DRender/private/setfence_p.h>
48#include <Qt3DCore/qpropertyupdatedchange.h>
49#include "qbackendnodetester.h"
50#include "testrenderer.h"
51#include "testpostmanarbiter.h"
52
53class tst_SetFence : public Qt3DCore::QBackendNodeTester
54{
55 Q_OBJECT
56
57private Q_SLOTS:
58
59 void checkInitialState()
60 {
61 // GIVEN
62 Qt3DRender::Render::SetFence backendSetFence;
63
64 // THEN
65 QCOMPARE(backendSetFence.isEnabled(), false);
66 QVERIFY(backendSetFence.peerId().isNull());
67 QCOMPARE(backendSetFence.nodeType(), Qt3DRender::Render::FrameGraphNode::SetFence);
68 }
69
70 void checkInitializeFromPeer()
71 {
72 // GIVEN
73 TestRenderer renderer;
74 Qt3DRender::QSetFence setFence;
75
76 {
77 // WHEN
78 Qt3DRender::Render::SetFence backendSetFence;
79 backendSetFence.setRenderer(&renderer);
80 simulateInitializationSync(frontend: &setFence, backend: &backendSetFence);
81
82 // THEN
83 QCOMPARE(backendSetFence.isEnabled(), true);
84 QCOMPARE(backendSetFence.peerId(), setFence.id());
85 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
86 }
87 renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty);
88 {
89 // WHEN
90 Qt3DRender::Render::SetFence backendSetFence;
91 setFence.setEnabled(false);
92 backendSetFence.setRenderer(&renderer);
93 simulateInitializationSync(frontend: &setFence, backend: &backendSetFence);
94
95 // THEN
96 QCOMPARE(backendSetFence.peerId(), setFence.id());
97 QCOMPARE(backendSetFence.isEnabled(), false);
98 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
99 }
100 }
101
102 void checkSceneChangeEvents()
103 {
104 // GIVEN
105 Qt3DRender::Render::SetFence backendSetFence;
106 Qt3DRender::QSetFence setFence;
107 TestRenderer renderer;
108 backendSetFence.setRenderer(&renderer);
109 simulateInitializationSync(frontend: &setFence, backend: &backendSetFence);
110
111 {
112 // WHEN
113 const bool newValue = false;
114 setFence.setEnabled(newValue);
115 backendSetFence.syncFromFrontEnd(frontEnd: &setFence, firstTime: false);
116
117 // THEN
118 QCOMPARE(backendSetFence.isEnabled(), newValue);
119 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
120 renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty);
121 }
122 }
123
124 void checkSetHandleType()
125 {
126 // GIVEN
127 Qt3DRender::Render::SetFence backendSetFence;
128 TestRenderer renderer;
129 TestArbiter arbiter;
130
131 Qt3DCore::QBackendNodePrivate::get(n: &backendSetFence)->setArbiter(&arbiter);
132 backendSetFence.setRenderer(&renderer);
133
134 // WHEN
135 backendSetFence.setHandleType(Qt3DRender::QSetFence::OpenGLFenceId);
136
137 // THEN
138 Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>();
139 QCOMPARE(arbiter.events.count(), 1);
140 QCOMPARE(change->propertyName(), "handleType");
141 QCOMPARE(change->value().value<Qt3DRender::QSetFence::HandleType>(), Qt3DRender::QSetFence::OpenGLFenceId);
142
143 arbiter.events.clear();
144 }
145
146 void checkSetHandle()
147 {
148 // GIVEN
149 Qt3DRender::Render::SetFence backendSetFence;
150 TestRenderer renderer;
151 TestArbiter arbiter;
152
153 Qt3DCore::QBackendNodePrivate::get(n: &backendSetFence)->setArbiter(&arbiter);
154 backendSetFence.setRenderer(&renderer);
155
156 // WHEN
157 backendSetFence.setHandle(QVariant(984));
158
159 // THEN
160 Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>();
161 QCOMPARE(arbiter.events.count(), 1);
162 QCOMPARE(change->propertyName(), "handle");
163 QCOMPARE(change->value(), QVariant(984));
164
165 arbiter.events.clear();
166 }
167};
168
169QTEST_MAIN(tst_SetFence)
170
171#include "tst_setfence.moc"
172

source code of qt3d/tests/auto/render/setfence/tst_setfence.cpp