1/****************************************************************************
2**
3** Copyright (C) 2017 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/qlevelofdetail.h>
35#include <Qt3DRender/private/qlevelofdetail_p.h>
36
37#include "testpostmanarbiter.h"
38
39class tst_QLevelOfDetail: public QObject
40{
41 Q_OBJECT
42
43private Q_SLOTS:
44
45 void checkCloning_data()
46 {
47 QTest::addColumn<Qt3DRender::QLevelOfDetail *>(name: "lod");
48
49 Qt3DRender::QLevelOfDetail *defaultConstructed = new Qt3DRender::QLevelOfDetail();
50 QTest::newRow(dataTag: "defaultConstructed") << defaultConstructed;
51
52 Qt3DRender::QLevelOfDetail *lodDst = new Qt3DRender::QLevelOfDetail();
53 QTest::newRow(dataTag: "distLod") << lodDst;
54
55 Qt3DRender::QLevelOfDetail *lodPx = new Qt3DRender::QLevelOfDetail();
56 QTest::newRow(dataTag: "pxLod") << lodPx;
57 }
58
59 void checkCloning()
60 {
61 // GIVEN
62 QFETCH(Qt3DRender::QLevelOfDetail *, lod);
63
64 // WHEN
65 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(lod);
66 QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges = creationChangeGenerator.creationChanges();
67
68 // THEN
69 QCOMPARE(creationChanges.size(), 1);
70
71 const Qt3DCore::QNodeCreatedChangePtr<Qt3DRender::QLevelOfDetailData> creationChangeData =
72 qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QLevelOfDetailData>>(src: creationChanges.first());
73 const Qt3DRender::QLevelOfDetailData &cloneData = creationChangeData->data;
74
75 QCOMPARE(lod->id(), creationChangeData->subjectId());
76 QCOMPARE(lod->isEnabled(), creationChangeData->isNodeEnabled());
77 QCOMPARE(lod->metaObject(), creationChangeData->metaObject());
78 QCOMPARE(lod->currentIndex(), cloneData.currentIndex);
79 QCOMPARE(lod->thresholdType(), cloneData.thresholdType);
80 QCOMPARE(lod->thresholds(), cloneData.thresholds);
81 }
82
83 void checkPropertyUpdates()
84 {
85 // GIVEN
86 TestArbiter arbiter;
87 QScopedPointer<Qt3DRender::QLevelOfDetail> lod(new Qt3DRender::QLevelOfDetail());
88 arbiter.setArbiterOnNode(lod.data());
89
90 {
91 // WHEN
92 lod->setThresholdType(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold);
93 QCoreApplication::processEvents();
94
95 // THEN
96 QCOMPARE(arbiter.events.size(), 0);
97 QCOMPARE(arbiter.dirtyNodes.size(), 1);
98 QCOMPARE(arbiter.dirtyNodes.front(), lod.data());
99
100 arbiter.dirtyNodes.clear();
101 }
102
103 {
104 // WHEN
105 QVector<qreal> thresholds = {10., 20., 30.};
106 lod->setThresholds(thresholds);
107 QCoreApplication::processEvents();
108
109 // THEN
110 QCOMPARE(arbiter.events.size(), 0);
111 QCOMPARE(arbiter.dirtyNodes.size(), 1);
112 QCOMPARE(arbiter.dirtyNodes.front(), lod.data());
113
114 arbiter.dirtyNodes.clear();
115 }
116 }
117};
118
119QTEST_MAIN(tst_QLevelOfDetail)
120
121#include "tst_qlevelofdetail.moc"
122

source code of qt3d/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp