Debian Codegraph @

tests/auto/render/meshfunctors/tst_meshfunctors.cpp

raw symbols SCIP
1 // Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QtTest/QTest>
5 #include <Qt3DCore/qcomponent.h>
6 #include <Qt3DCore/qgeometry.h>
7 #include <Qt3DRender/qmesh.h>
8 #include <Qt3DRender/private/qmesh_p.h>
9 #include <Qt3DCore/qaspectengine.h>
10
11 class MeshFunctorA : public Qt3DCore::QGeometryFactory
12 {
13 public:
14 MeshFunctorA()
15 {}
16
17 ~MeshFunctorA()
18 {}
19
20 Qt3DCore::QGeometry *operator ()() override
21 {
22 return nullptr;
23 }
24
25 bool equals(const Qt3DCore::QGeometryFactory &other) const override
26 {
27 return Qt3DCore::functor_cast<MeshFunctorA>(&other);
28 }
29
30 QT3D_FUNCTOR(MeshFunctorA)
31 };
32
33 class MeshFunctorB : public Qt3DCore::QGeometryFactory
34 {
35 public:
36 MeshFunctorB()
37 {}
38
39 ~MeshFunctorB()
40 {}
41
42 Qt3DCore::QGeometry *operator ()() override
43 {
44 return nullptr;
45 }
46
47 bool equals(const Qt3DCore::QGeometryFactory &other) const override
48 {
49 return Qt3DCore::functor_cast<MeshFunctorB>(&other);
50 }
51
52 QT3D_FUNCTOR(MeshFunctorB)
53 };
54
55 class MeshFunctorASub : public MeshFunctorA
56 {
57 public:
58 MeshFunctorASub()
59 {}
60
61 ~MeshFunctorASub()
62 {}
63
64 bool equals(const Qt3DCore::QGeometryFactory &other) const override
65 {
66 return Qt3DCore::functor_cast<MeshFunctorASub>(&other);
67 }
68
69 QT3D_FUNCTOR(MeshFunctorASub)
70 };
71
72
73 class tst_MeshFunctors : public QObject
74 {
75 Q_OBJECT
76 private Q_SLOTS:
77
78 void checkInitialState()
79 {
80 // GIVEN
81 Qt3DRender::QMesh mesh;
82 mesh.setSource(QUrl(QStringLiteral("./some_path.obj")));
83
84 // WHEN
85 const Qt3DRender::MeshLoaderFunctor functor(&mesh);
86
87 // THEN
88 QVERIFY(functor.nodeManagers() == nullptr);
89 QVERIFY(functor.downloaderService() == nullptr);
90 QVERIFY(functor.sourceData().isEmpty());
91 QCOMPARE(functor.mesh(), mesh.id());
92 QCOMPARE(functor.sourcePath(), mesh.source());
93 QCOMPARE(functor.status(), Qt3DRender::QMesh::None);
94 }
95
96 void functorComparison()
97 {
98 // GIVEN
99 QScopedPointer<MeshFunctorA> functorA(new MeshFunctorA);
100 QScopedPointer<MeshFunctorB> functorB(new MeshFunctorB);
101 QScopedPointer<MeshFunctorASub> functorASub(new MeshFunctorASub);
102
103 // THEN
104 QVERIFY(!(*functorA == *functorB));
105 QVERIFY(!(*functorA == *functorASub));
106
107 QVERIFY(!(*functorB == *functorA));
108 QVERIFY(!(*functorB == *functorASub));
109
110 QVERIFY(!(*functorASub == *functorA));
111 QVERIFY(!(*functorASub == *functorB));
112
113 QVERIFY(*functorA == *functorA);
114 QVERIFY(*functorB == *functorB);
115 QVERIFY(*functorASub == *functorASub);
116 }
117
118 void checkMeshFunctorEquality()
119 {
120 // GIVEN
121 auto meshA = new Qt3DRender::QMesh();
122 meshA->setSource(QUrl::fromLocalFile(QLatin1String("/foo")));
123 meshA->setMeshName(QLatin1String("bar"));
124
125 auto meshB = new Qt3DRender::QMesh();
126 meshB->setSource(QUrl::fromLocalFile(QLatin1String("/foo")));
127 meshB->setMeshName(QLatin1String("baz"));
128
129 auto meshC = new Qt3DRender::QMesh();
130 meshC->setSource(QUrl::fromLocalFile(QLatin1String("/baz")));
131 meshC->setMeshName(QLatin1String("bar"));
132
133 auto meshD = new Qt3DRender::QMesh();
134 meshD->setSource(QUrl::fromLocalFile(QLatin1String("/foo")));
135 meshD->setMeshName(QLatin1String("bar"));
136
137 const Qt3DRender::MeshLoaderFunctor functorA(meshA);
138 const Qt3DRender::MeshLoaderFunctor functorB(meshB);
139 const Qt3DRender::MeshLoaderFunctor functorC(meshC);
140 const Qt3DRender::MeshLoaderFunctor functorD(meshD);
141
142 // WHEN
143 const bool selfEquality = (functorA == functorA);
144 const bool sameSource = (functorA == functorB);
145 const bool sameMeshName = (functorA == functorC);
146 const bool perfectMatch = (functorA == functorD);
147
148 // THEN
149 QCOMPARE(selfEquality, true);
150 QCOMPARE(sameSource, false);
151 QCOMPARE(sameMeshName, false);
152 QCOMPARE(perfectMatch, true);
153 }
154
155 void checkExecution()
156 {
157 {
158 // GIVEN
159 Qt3DRender::QMesh mesh;
160 Qt3DRender::MeshLoaderFunctor functor(&mesh);
161
162 // WHEN
163 const Qt3DCore::QGeometry *g = functor();
164
165 // THEN
166 QVERIFY(g == nullptr);
167 QCOMPARE(functor.status(), Qt3DRender::QMesh::Error);
168 }
169
170 {
171 // GIVEN
172 Qt3DRender::QMesh mesh;
173 mesh.setSource(QUrl(QStringLiteral("./non_existing.obj")));
174 Qt3DRender::MeshLoaderFunctor functor(&mesh);
175
176 // WHEN
177 const Qt3DCore::QGeometry *g = functor();
178
179 // THEN
180 QVERIFY(g == nullptr);
181 QCOMPARE(functor.status(), Qt3DRender::QMesh::Error);
182 }
183
184 {
185 // GIVEN
186 Qt3DRender::QMesh mesh;
187 mesh.setSource(QUrl(QStringLiteral("http://www.somedomain.org/non_exisiting.obj")));
188 Qt3DRender::MeshLoaderFunctor functor(&mesh);
189
190 // WHEN
191 const Qt3DCore::QGeometry *g = functor();
192
193 // THEN
194 QVERIFY(g == nullptr);
195 QCOMPARE(functor.status(), Qt3DRender::QMesh::Error);
196 }
197 }
198 };
199
200 QTEST_MAIN(tst_MeshFunctors)
201
202 #include "tst_meshfunctors.moc"