Debian Codegraph @

tests/auto/render/qmesh/tst_qmesh.cpp

raw symbols SCIP
1 // Copyright (C) 2016 Paul Lemire <[email protected]>
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 // TODO Remove in Qt6
5 #include <QtCore/qcompilerdetection.h>
6 QT_WARNING_DISABLE_DEPRECATED
7
8 #include <QtTest/QTest>
9 #include <Qt3DRender/qmesh.h>
10 #include <Qt3DRender/private/qmesh_p.h>
11 #include <Qt3DCore/qaspectengine.h>
12 #include <Qt3DCore/private/qaspectengine_p.h>
13 #include <QObject>
14 #include <QSignalSpy>
15 #include <Qt3DCore/private/qscene_p.h>
16 #include "testarbiter.h"
17
18 class MyQMesh : public Qt3DRender::QMesh
19 {
20 Q_OBJECT
21 public:
22 explicit MyQMesh(Qt3DCore::QNode *parent = nullptr)
23 : Qt3DRender::QMesh(parent)
24 {}
25 };
26
27 class tst_QMesh : public QObject
28 {
29 Q_OBJECT
30
31 private Q_SLOTS:
32
33 void checkDefaultConstruction()
34 {
35 // GIVEN
36 Qt3DRender::QMesh mesh;
37
38 // THEN
39 QCOMPARE(mesh.source(), QUrl());
40 QCOMPARE(mesh.meshName(), QString());
41 QCOMPARE(mesh.status(), Qt3DRender::QMesh::None);
42 }
43
44 void checkPropertyChanges()
45 {
46 // GIVEN
47 Qt3DRender::QMesh mesh;
48
49 {
50 // WHEN
51 QSignalSpy spy(&mesh, SIGNAL(sourceChanged(QUrl)));
52 const QUrl newValue(QStringLiteral("qrc:/mesh.obj"));
53 mesh.setSource(newValue);
54
55 // THEN
56 QVERIFY(spy.isValid());
57 QCOMPARE(mesh.source(), newValue);
58 QCOMPARE(spy.size(), 1);
59
60 // WHEN
61 spy.clear();
62 mesh.setSource(newValue);
63
64 // THEN
65 QCOMPARE(mesh.source(), newValue);
66 QCOMPARE(spy.size(), 0);
67 }
68 {
69 // WHEN
70 QSignalSpy spy(&mesh, SIGNAL(meshNameChanged(QString)));
71 const QString newValue = QStringLiteral("MainBody");
72 mesh.setMeshName(newValue);
73
74 // THEN
75 QVERIFY(spy.isValid());
76 QCOMPARE(mesh.meshName(), newValue);
77 QCOMPARE(spy.size(), 1);
78
79 // WHEN
80 spy.clear();
81 mesh.setMeshName(newValue);
82
83 // THEN
84 QCOMPARE(mesh.meshName(), newValue);
85 QCOMPARE(spy.size(), 0);
86 }
87 }
88
89 void checkSourceUpdate()
90 {
91 // GIVEN
92 TestArbiter arbiter;
93 Qt3DCore::QAspectEngine engine;
94 Qt3DCore::QScene *scene = Qt3DCore::QAspectEnginePrivate::get(&engine)->m_scene;
95 Qt3DRender::QMesh mesh;
96
97 arbiter.setArbiterOnNode(&mesh);
98 Qt3DCore::QNodePrivate *meshd = Qt3DCore::QNodePrivate::get(&mesh);
99 meshd->setScene(scene);
100 QCoreApplication::processEvents();
101 arbiter.clear();
102
103 {
104 // WHEN
105 mesh.setSource(QUrl(QStringLiteral("qrc:/toyplane.obj")));
106 QCoreApplication::processEvents();
107
108 // THEN
109 QCOMPARE(arbiter.dirtyNodes().size(), 1);
110 QCOMPARE(arbiter.dirtyNodes().front(), &mesh);
111
112 arbiter.clear();
113 }
114
115 {
116 // WHEN
117 mesh.setSource(QStringLiteral("qrc:/toyplane.obj"));
118 QCoreApplication::processEvents();
119
120 // THEN
121 QCOMPARE(arbiter.dirtyNodes().size(), 0);
122 }
123
124 }
125
126 void checkMeshNameUpdate()
127 {
128 // GIVEN
129 TestArbiter arbiter;
130 Qt3DCore::QAspectEngine engine;
131 Qt3DCore::QScene *scene = Qt3DCore::QAspectEnginePrivate::get(&engine)->m_scene;
132 Qt3DRender::QMesh mesh;
133
134 arbiter.setArbiterOnNode(&mesh);
135 Qt3DCore::QNodePrivate *meshd = Qt3DCore::QNodePrivate::get(&mesh);
136 meshd->setScene(scene);
137 QCoreApplication::processEvents();
138 arbiter.clear();
139
140 {
141 // WHEN
142 mesh.setMeshName(QStringLiteral("Phil"));
143 QCoreApplication::processEvents();
144
145 // THEN
146 QCOMPARE(arbiter.dirtyNodes().size(), 1);
147 QCOMPARE(arbiter.dirtyNodes().front(), &mesh);
148
149 arbiter.clear();
150 }
151
152 {
153 // WHEN
154 mesh.setMeshName(QStringLiteral("Phil"));
155 QCoreApplication::processEvents();
156
157 // THEN
158 QCOMPARE(arbiter.dirtyNodes().size(), 0);
159 }
160
161 }
162
163 void checkGeometryFactoryIsAccessibleEvenWithNoScene() // QTBUG-65506
164 {
165 // GIVEN
166 Qt3DRender::QMesh mesh;
167
168 // WHEN
169 mesh.setSource(QUrl(QStringLiteral("some_path")));
170
171 // THEN
172 QVERIFY(!Qt3DRender::QMeshPrivate::get(&mesh)->m_geometryFactory.isNull());
173 }
174 };
175
176 QTEST_MAIN(tst_QMesh)
177
178 #include "tst_qmesh.moc"