diff options
author | Guillermo A. Amaral <gamaral@kdab.com> | 2016-10-12 13:18:23 -0700 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-01-20 13:56:29 +0000 |
commit | b97213a2575b16717e1d7a0ca8235b8884a240bd (patch) | |
tree | 7a702bf07286edeab8cfa13b00530b286586d60e /tests/auto/render/geometryloaders/tst_geometryloaders.cpp | |
parent | 4338a85487788bb553cef0eaa5e5a3f929934eea (diff) |
Ported PLY and STL geometry loaders
Original implementation by Mauro Persano.
Change-Id: I3560fd15239f369de86e514985d0a39b0c6df671
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests/auto/render/geometryloaders/tst_geometryloaders.cpp')
-rw-r--r-- | tests/auto/render/geometryloaders/tst_geometryloaders.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/auto/render/geometryloaders/tst_geometryloaders.cpp b/tests/auto/render/geometryloaders/tst_geometryloaders.cpp index a51364e0e..61910c417 100644 --- a/tests/auto/render/geometryloaders/tst_geometryloaders.cpp +++ b/tests/auto/render/geometryloaders/tst_geometryloaders.cpp @@ -59,6 +59,8 @@ class tst_geometryloaders : public QObject private Q_SLOTS: void testOBJLoader(); + void testPLYLoader(); + void testSTLLoader(); }; void tst_geometryloaders::testOBJLoader() @@ -100,6 +102,77 @@ void tst_geometryloaders::testOBJLoader() file.close(); } +void tst_geometryloaders::testPLYLoader() +{ + QScopedPointer<QGeometryLoaderInterface> loader; + loader.reset(qLoadPlugin<QGeometryLoaderInterface, QGeometryLoaderFactory>(geometryLoader(), QStringLiteral("ply"))); + QVERIFY(loader); + if (!loader) + return; + + QFile file(QStringLiteral(":/cube.ply")); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug("Could not open test file for reading"); + return; + } + + bool loaded = loader->load(&file, QStringLiteral("Cube")); + QVERIFY(loaded); + if (!loaded) + return; + + QGeometry *geometry = loader->geometry(); + QVERIFY(geometry); + if (!geometry) + return; + + QCOMPARE(geometry->attributes().count(), 3); + for (QAttribute *attr : geometry->attributes()) { + switch (attr->attributeType()) { + case QAttribute::IndexAttribute: + QCOMPARE(attr->count(), 36u); + break; + case QAttribute::VertexAttribute: + QCOMPARE(attr->count(), 24u); + break; + } + } + + file.close(); +} + +void tst_geometryloaders::testSTLLoader() +{ + QScopedPointer<QGeometryLoaderInterface> loader; + loader.reset(qLoadPlugin<QGeometryLoaderInterface, QGeometryLoaderFactory>(geometryLoader(), QStringLiteral("stl"))); + QVERIFY(loader); + if (!loader) + return; + + QFile file(QStringLiteral(":/cube.stl")); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug("Could not open test file for reading"); + return; + } + + bool loaded = loader->load(&file, QStringLiteral("Cube")); + QVERIFY(loaded); + if (!loaded) + return; + + QGeometry *geometry = loader->geometry(); + QVERIFY(geometry); + if (!geometry) + return; + + QCOMPARE(geometry->attributes().count(), 3); + for (QAttribute *attr : geometry->attributes()) { + QCOMPARE(attr->count(), 36u); + } + + file.close(); +} + QTEST_MAIN(tst_geometryloaders) #include "tst_geometryloaders.moc" |