1/****************************************************************************
2**
3** Copyright (C) 2015 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#include <QtTest/QTest>
30#include <Qt3DCore/private/qnode_p.h>
31#include <Qt3DCore/private/qscene_p.h>
32#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h>
33
34#include <Qt3DRender/qclearbuffers.h>
35#include <Qt3DRender/private/qclearbuffers_p.h>
36
37#include "testpostmanarbiter.h"
38
39class tst_QClearBuffers: public QObject
40{
41 Q_OBJECT
42
43private Q_SLOTS:
44
45 void checkCloning_data()
46 {
47 QTest::addColumn<Qt3DRender::QClearBuffers *>(name: "clearBuffers");
48 QTest::addColumn<Qt3DRender::QClearBuffers::BufferType>(name: "bufferType");
49
50 Qt3DRender::QClearBuffers *defaultConstructed = new Qt3DRender::QClearBuffers();
51 QTest::newRow(dataTag: "defaultConstructed") << defaultConstructed << Qt3DRender::QClearBuffers::None;
52
53 Qt3DRender::QClearBuffers *allBuffers = new Qt3DRender::QClearBuffers();
54 allBuffers->setBuffers(Qt3DRender::QClearBuffers::AllBuffers);
55 QTest::newRow(dataTag: "allBuffers") << allBuffers << Qt3DRender::QClearBuffers::AllBuffers;
56
57 Qt3DRender::QClearBuffers *depthBuffer = new Qt3DRender::QClearBuffers();
58 depthBuffer->setBuffers(Qt3DRender::QClearBuffers::DepthBuffer);
59 QTest::newRow(dataTag: "depthBuffer") << depthBuffer << Qt3DRender::QClearBuffers::DepthBuffer;
60
61 Qt3DRender::QClearBuffers *colorDepthBuffer = new Qt3DRender::QClearBuffers();
62 colorDepthBuffer->setBuffers(Qt3DRender::QClearBuffers::ColorDepthBuffer);
63 QTest::newRow(dataTag: "colorDepthBuffer") << colorDepthBuffer << Qt3DRender::QClearBuffers::ColorDepthBuffer;
64 }
65
66 void checkCloning()
67 {
68 // GIVEN
69 QFETCH(Qt3DRender::QClearBuffers *, clearBuffers);
70 QFETCH(Qt3DRender::QClearBuffers::BufferType, bufferType);
71
72 // THEN
73 QCOMPARE(clearBuffers->buffers(), bufferType);
74
75 // WHEN
76 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(clearBuffers);
77 QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges = creationChangeGenerator.creationChanges();
78
79 // THEN
80 QCOMPARE(creationChanges.size(), 1);
81
82 const Qt3DCore::QNodeCreatedChangePtr<Qt3DRender::QClearBuffersData> creationChangeData =
83 qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QClearBuffersData>>(src: creationChanges.first());
84 const Qt3DRender::QClearBuffersData &cloneData = creationChangeData->data;
85
86 // THEN
87 QCOMPARE(clearBuffers->id(), creationChangeData->subjectId());
88 QCOMPARE(clearBuffers->isEnabled(), creationChangeData->isNodeEnabled());
89 QCOMPARE(clearBuffers->metaObject(), creationChangeData->metaObject());
90 QCOMPARE(clearBuffers->buffers(), cloneData.buffersType);
91 QCOMPARE(clearBuffers->clearColor(), cloneData.clearColor);
92 QCOMPARE(clearBuffers->clearDepthValue(), cloneData.clearDepthValue);
93 QCOMPARE(clearBuffers->clearStencilValue(), cloneData.clearStencilValue);
94
95 delete clearBuffers;
96 }
97
98 void checkPropertyUpdates()
99 {
100 // GIVEN
101 TestArbiter arbiter;
102 QScopedPointer<Qt3DRender::QClearBuffers> clearBuffer(new Qt3DRender::QClearBuffers());
103 arbiter.setArbiterOnNode(clearBuffer.data());
104
105 // WHEN
106 clearBuffer->setBuffers(Qt3DRender::QClearBuffers::AllBuffers);
107
108 // THEN
109 QCOMPARE(arbiter.events.size(), 0);
110 QCOMPARE(arbiter.dirtyNodes.size(), 1);
111 QCOMPARE(arbiter.dirtyNodes.front(), clearBuffer.data());
112
113 arbiter.dirtyNodes.clear();
114
115 // WHEN
116 clearBuffer->setBuffers(Qt3DRender::QClearBuffers::AllBuffers);
117
118 // THEN
119 QCOMPARE(arbiter.events.size(), 0);
120 QCOMPARE(arbiter.dirtyNodes.size(), 0);
121
122 // WHEN
123 clearBuffer->setBuffers(Qt3DRender::QClearBuffers::ColorDepthBuffer);
124
125 // THEN
126 QCOMPARE(arbiter.events.size(), 0);
127 QCOMPARE(arbiter.dirtyNodes.size(), 1);
128 QCOMPARE(arbiter.dirtyNodes.front(), clearBuffer.data());
129
130 arbiter.dirtyNodes.clear();
131 }
132};
133
134QTEST_MAIN(tst_QClearBuffers)
135
136#include "tst_qclearbuffers.moc"
137

source code of qt3d/tests/auto/render/qclearbuffers/tst_qclearbuffers.cpp