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// TODO Remove in Qt6
30#include <QtCore/qcompilerdetection.h>
31QT_WARNING_DISABLE_DEPRECATED
32
33#include <QtTest/QTest>
34
35#include <Qt3DRender/qgeometryrenderer.h>
36#include <Qt3DRender/qgeometryfactory.h>
37#include <Qt3DRender/qgeometry.h>
38#include <Qt3DRender/qattribute.h>
39#include <Qt3DRender/qbuffer.h>
40#include <Qt3DRender/qbufferdatagenerator.h>
41#include <Qt3DRender/private/qgeometryrenderer_p.h>
42#include <Qt3DRender/private/qgeometry_p.h>
43#include <Qt3DRender/private/qattribute_p.h>
44#include <Qt3DRender/private/qbuffer_p.h>
45#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h>
46
47#include <Qt3DExtras/qspheremesh.h>
48#include <Qt3DExtras/qcylindermesh.h>
49#include <Qt3DExtras/qtorusmesh.h>
50#include <Qt3DExtras/qcuboidmesh.h>
51#include <Qt3DExtras/qplanemesh.h>
52
53
54class tst_QDefaultMeshes: public QObject
55{
56 Q_OBJECT
57
58public:
59 tst_QDefaultMeshes()
60 {
61 qRegisterMetaType<Qt3DCore::QNode*>();
62 }
63
64private Q_SLOTS:
65
66 void checkCloning_data()
67 {
68 QTest::addColumn<Qt3DRender::QGeometryRenderer *>(name: "geomRenderer");
69 QTest::newRow(dataTag: "QSphereMesh") << static_cast<Qt3DRender::QGeometryRenderer *>(new Qt3DExtras::QSphereMesh);
70 QTest::newRow(dataTag: "QCylinderMesh") << static_cast<Qt3DRender::QGeometryRenderer *>(new Qt3DExtras::QCylinderMesh);
71 QTest::newRow(dataTag: "QTorusMesh") << static_cast<Qt3DRender::QGeometryRenderer *>(new Qt3DExtras::QTorusMesh);
72 QTest::newRow(dataTag: "QCuboidMesh") << static_cast<Qt3DRender::QGeometryRenderer *>(new Qt3DExtras::QCuboidMesh);
73 QTest::newRow(dataTag: "QPlaneMesh") << static_cast<Qt3DRender::QGeometryRenderer *>(new Qt3DExtras::QPlaneMesh);
74 }
75
76 void checkCloning()
77 {
78 // GIVEN
79 QFETCH(Qt3DRender::QGeometryRenderer *, geomRenderer);
80
81 // WHEN
82 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(geomRenderer);
83 QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges = creationChangeGenerator.creationChanges();
84
85 // THEN
86 QVERIFY(creationChanges.size() >= 1);
87
88 const Qt3DCore::QNodeCreatedChangePtr<Qt3DRender::QGeometryRendererData> creationChangeData =
89 qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QGeometryRendererData>>(src: creationChanges.first());
90 const Qt3DRender::QGeometryRendererData &cloneData = creationChangeData->data;
91
92 QCOMPARE(creationChangeData->subjectId(), geomRenderer->id());
93 QCOMPARE(cloneData.instanceCount, geomRenderer->instanceCount());
94 QCOMPARE(cloneData.vertexCount, geomRenderer->vertexCount());
95 QCOMPARE(cloneData.indexOffset, geomRenderer->indexOffset());
96 QCOMPARE(cloneData.firstInstance, geomRenderer->firstInstance());
97 QCOMPARE(cloneData.restartIndexValue, geomRenderer->restartIndexValue());
98 QCOMPARE(cloneData.primitiveRestart, geomRenderer->primitiveRestartEnabled());
99 QCOMPARE(cloneData.primitiveType, geomRenderer->primitiveType());
100 QCOMPARE(cloneData.geometryFactory, geomRenderer->geometryFactory());
101
102 if (geomRenderer->geometryFactory()) {
103 QVERIFY(cloneData.geometryFactory);
104 QVERIFY(*cloneData.geometryFactory == *geomRenderer->geometryFactory());
105 }
106 }
107};
108
109QTEST_MAIN(tst_QDefaultMeshes)
110
111#include "tst_qdefaultmeshes.moc"
112

source code of qt3d/tests/auto/render/qdefaultmeshes/tst_qdefaultmeshes.cpp