From b7335e92649a9c6e022ec562a28b22f60122cad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Oct 2021 00:22:11 +0200 Subject: [PATCH] ObjImporter: test double opening and double import. Like with all other plugins. --- .../ObjImporter/Test/ObjImporterTest.cpp | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/MagnumPlugins/ObjImporter/Test/ObjImporterTest.cpp b/src/MagnumPlugins/ObjImporter/Test/ObjImporterTest.cpp index 8800b8e6d..b2c85addb 100644 --- a/src/MagnumPlugins/ObjImporter/Test/ObjImporterTest.cpp +++ b/src/MagnumPlugins/ObjImporter/Test/ObjImporterTest.cpp @@ -92,6 +92,9 @@ struct ObjImporterTest: TestSuite::Tester { void unsupportedKeyword(); void unknownKeyword(); + void openTwice(); + void importTwice(); + /* Explicitly forbid system-wide plugin dependencies */ PluginManager::Manager _manager{"nonexistent"}; }; @@ -145,7 +148,10 @@ ObjImporterTest::ObjImporterTest() { &ObjImporterTest::wrongNormalIndexCount, &ObjImporterTest::unsupportedKeyword, - &ObjImporterTest::unknownKeyword}); + &ObjImporterTest::unknownKeyword, + + &ObjImporterTest::openTwice, + &ObjImporterTest::importTwice}); #ifdef OBJIMPORTER_PLUGIN_FILENAME CORRADE_INTERNAL_ASSERT_OUTPUT(_manager.load(OBJIMPORTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded); @@ -797,6 +803,31 @@ void ObjImporterTest::unknownKeyword() { CORRADE_COMPARE(out.str(), "Trade::ObjImporter::mesh(): unknown keyword bleh\n"); } +void ObjImporterTest::openTwice() { + Containers::Pointer importer = _manager.instantiate("ObjImporter"); + + CORRADE_VERIFY(importer->openFile(Utility::Directory::join(OBJIMPORTER_TEST_DIR, "pointMesh.obj"))); + CORRADE_VERIFY(importer->openFile(Utility::Directory::join(OBJIMPORTER_TEST_DIR, "pointMesh.obj"))); + + /* Shouldn't crash, leak or anything */ +} + +void ObjImporterTest::importTwice() { + Containers::Pointer importer = _manager.instantiate("ObjImporter"); + CORRADE_VERIFY(importer->openFile(Utility::Directory::join(OBJIMPORTER_TEST_DIR, "pointMesh.obj"))); + + /* Verify that everything is working the same way on second use */ + { + Containers::Optional mesh = importer->mesh(0); + CORRADE_VERIFY(mesh); + CORRADE_COMPARE(mesh->vertexCount(), 3); + } { + Containers::Optional mesh = importer->mesh(0); + CORRADE_VERIFY(mesh); + CORRADE_COMPARE(mesh->vertexCount(), 3); + } +} + }}}} CORRADE_TEST_MAIN(Magnum::Trade::Test::ObjImporterTest)