diff --git a/src/MagnumPlugins/AnyAudioImporter/Test/AnyAudioImporterTest.cpp b/src/MagnumPlugins/AnyAudioImporter/Test/AnyAudioImporterTest.cpp index 1076fd43f..8a9b731c6 100644 --- a/src/MagnumPlugins/AnyAudioImporter/Test/AnyAudioImporterTest.cpp +++ b/src/MagnumPlugins/AnyAudioImporter/Test/AnyAudioImporterTest.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "Magnum/Audio/AbstractImporter.h" @@ -36,7 +37,8 @@ namespace Magnum { namespace Audio { namespace Test { namespace { struct AnyImporterTest: TestSuite::Tester { explicit AnyImporterTest(); - void wav(); + void load(); + void detect(); void unknown(); @@ -44,10 +46,30 @@ struct AnyImporterTest: TestSuite::Tester { PluginManager::Manager _manager{"nonexistent"}; }; +constexpr struct { + const char* name; + const char* filename; +} LoadData[]{ + {"WAV", WAV_FILE} +}; + +constexpr struct { + const char* name; + const char* filename; + const char* plugin; +} DetectData[]{ + {"OGG", "thunder.ogg", "VorbisAudioImporter"}, + {"FLAC", "symphony.flac", "FlacAudioImporter"} +}; + AnyImporterTest::AnyImporterTest() { - addTests({&AnyImporterTest::wav, + addInstancedTests({&AnyImporterTest::load}, + Containers::arraySize(LoadData)); + + addInstancedTests({&AnyImporterTest::detect}, + Containers::arraySize(DetectData)); - &AnyImporterTest::unknown}); + addTests({&AnyImporterTest::unknown}); /* Load the plugin directly from the build tree. Otherwise it's static and already loaded. */ @@ -60,18 +82,40 @@ AnyImporterTest::AnyImporterTest() { #endif } -void AnyImporterTest::wav() { +void AnyImporterTest::load() { + auto&& data = LoadData[testCaseInstanceId()]; + setTestCaseDescription(data.name); + if(!(_manager.loadState("WavAudioImporter") & PluginManager::LoadState::Loaded)) CORRADE_SKIP("WavAudioImporter plugin not enabled, cannot test"); Containers::Pointer importer = _manager.instantiate("AnyAudioImporter"); - CORRADE_VERIFY(importer->openFile(WAV_FILE)); + CORRADE_VERIFY(importer->openFile(data.filename)); /* Check only parameters, as it is good enough proof that it is working */ CORRADE_COMPARE(importer->format(), BufferFormat::Stereo8); CORRADE_COMPARE(importer->frequency(), 96000); } +void AnyImporterTest::detect() { + auto&& data = DetectData[testCaseInstanceId()]; + setTestCaseDescription(data.name); + + Containers::Pointer importer = _manager.instantiate("AnyAudioImporter"); + + std::ostringstream out; + Error redirectError{&out}; + CORRADE_VERIFY(!importer->openFile(data.filename)); + /* Can't use raw string literals in macros on GCC 4.8 */ + #ifndef CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT + CORRADE_COMPARE(out.str(), Utility::formatString( +"PluginManager::Manager::load(): plugin {0} is not static and was not found in nonexistent\nAudio::AnyImporter::openFile(): cannot load {0} plugin\n", data.plugin)); + #else + CORRADE_COMPARE(out.str(), Utility::formatString( +"PluginManager::Manager::load(): plugin {0} was not found\nAudio::AnyImporter::openFile(): cannot load {0} plugin\n", data.plugin)); + #endif +} + void AnyImporterTest::unknown() { std::ostringstream output; Error redirectError{&output}; diff --git a/src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp b/src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp index 565a411eb..31fad7f32 100644 --- a/src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp +++ b/src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp @@ -24,9 +24,10 @@ */ #include +#include #include #include -#include +#include #include "Magnum/PixelFormat.h" #include "Magnum/Trade/AbstractImageConverter.h" @@ -39,7 +40,8 @@ namespace Magnum { namespace Trade { namespace Test { namespace { struct AnyImageConverterTest: TestSuite::Tester { explicit AnyImageConverterTest(); - void tga(); + void convert(); + void detect(); void unknown(); @@ -47,10 +49,34 @@ struct AnyImageConverterTest: TestSuite::Tester { PluginManager::Manager _manager{"nonexistent"}; }; +constexpr struct { + const char* name; + const char* filename; +} ConvertData[]{ + {"TGA", "output.tga"} +}; + +constexpr struct { + const char* name; + const char* filename; + const char* plugin; +} DetectData[]{ + {"BMP", "file.bmp", "BmpImageConverter"}, + {"EXR", "file.exr", "OpenExrImageConverter"}, + {"HDR", "file.hdr", "HdrImageConverter"}, + {"JPEG", "file.jpg", "JpegImageConverter"}, + {"JPEG weird extension", "file.jpe", "JpegImageConverter"}, + {"PNG", "file.png", "PngImageConverter"} +}; + AnyImageConverterTest::AnyImageConverterTest() { - addTests({&AnyImageConverterTest::tga, + addInstancedTests({&AnyImageConverterTest::convert}, + Containers::arraySize(ConvertData)); + + addInstancedTests({&AnyImageConverterTest::detect}, + Containers::arraySize(DetectData)); - &AnyImageConverterTest::unknown}); + addTests({&AnyImageConverterTest::unknown}); /* Load the plugin directly from the build tree. Otherwise it's static and already loaded. */ @@ -74,11 +100,14 @@ constexpr const char Data[] = { const ImageView2D Image{PixelFormat::RGB8Unorm, {2, 3}, Data}; -void AnyImageConverterTest::tga() { +void AnyImageConverterTest::convert() { + auto&& data = ConvertData[testCaseInstanceId()]; + setTestCaseDescription(data.name); + if(!(_manager.loadState("TgaImageConverter") & PluginManager::LoadState::Loaded)) CORRADE_SKIP("TgaImageConverter plugin not enabled, cannot test"); - const std::string filename = Utility::Directory::join(ANYIMAGECONVERTER_TEST_DIR, "output.tga"); + const std::string filename = Utility::Directory::join(ANYIMAGECONVERTER_TEST_DIR, data.filename); if(Utility::Directory::fileExists(filename)) CORRADE_VERIFY(Utility::Directory::rm(filename)); @@ -89,6 +118,25 @@ void AnyImageConverterTest::tga() { CORRADE_VERIFY(Utility::Directory::fileExists(filename)); } +void AnyImageConverterTest::detect() { + auto&& data = DetectData[testCaseInstanceId()]; + setTestCaseDescription(data.name); + + Containers::Pointer converter = _manager.instantiate("AnyImageConverter"); + + std::ostringstream out; + Error redirectError{&out}; + CORRADE_VERIFY(!converter->exportToFile(Image, data.filename)); + /* Can't use raw string literals in macros on GCC 4.8 */ + #ifndef CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT + CORRADE_COMPARE(out.str(), Utility::formatString( +"PluginManager::Manager::load(): plugin {0} is not static and was not found in nonexistent\nTrade::AnyImageConverter::exportToFile(): cannot load {0} plugin\n", data.plugin)); + #else + CORRADE_COMPARE(out.str(), Utility::formatString( +"PluginManager::Manager::load(): plugin {0} was not found\nTrade::AnyImageConverter::exportToFile(): cannot load {0} plugin\n", data.plugin)); + #endif +} + void AnyImageConverterTest::unknown() { std::ostringstream output; Error redirectError{&output}; diff --git a/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp b/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp index b89224179..92b42fac1 100644 --- a/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp +++ b/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp @@ -41,7 +41,6 @@ struct AnyImageImporterTest: TestSuite::Tester { explicit AnyImageImporterTest(); void load(); - void detect(); void unknownExtension(); diff --git a/src/MagnumPlugins/AnySceneImporter/Test/AnySceneImporterTest.cpp b/src/MagnumPlugins/AnySceneImporter/Test/AnySceneImporterTest.cpp index ec24030bc..bb857e0b4 100644 --- a/src/MagnumPlugins/AnySceneImporter/Test/AnySceneImporterTest.cpp +++ b/src/MagnumPlugins/AnySceneImporter/Test/AnySceneImporterTest.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "Magnum/Math/Vector3.h" #include "Magnum/Trade/AbstractImporter.h" @@ -39,7 +40,8 @@ namespace Magnum { namespace Trade { namespace Test { namespace { struct AnySceneImporterTest: TestSuite::Tester { explicit AnySceneImporterTest(); - void obj(); + void load(); + void detect(); void unknown(); @@ -47,10 +49,37 @@ struct AnySceneImporterTest: TestSuite::Tester { PluginManager::Manager _manager{"nonexistent"}; }; +constexpr struct { + const char* name; + const char* filename; +} LoadData[]{ + {"OBJ", OBJ_FILE}, +}; + +constexpr struct { + const char* name; + const char* filename; + const char* plugin; +} DetectData[]{ + {"Blender", "suzanne.blend", "BlenderImporter"}, + {"COLLADA", "xml.dae", "ColladaImporter"}, + {"FBX", "autodesk.fbx", "FbxImporter"}, + {"glTF", "khronos.gltf", "GltfImporter"}, + {"glTF binary", "khronos.glb", "GlbImporter"}, + {"OpenGEX", "eric.ogex", "OpenGexImporter"}, + {"Stanford PLY", "bunny.ply", "StanfordImporter"}, + {"STL", "robot.stl", "StlImporter"}, + /* Not testing everything, only the most important ones */ +}; + AnySceneImporterTest::AnySceneImporterTest() { - addTests({&AnySceneImporterTest::obj, + addInstancedTests({&AnySceneImporterTest::load}, + Containers::arraySize(LoadData)); + + addInstancedTests({&AnySceneImporterTest::detect}, + Containers::arraySize(DetectData)); - &AnySceneImporterTest::unknown}); + addTests({&AnySceneImporterTest::unknown}); /* Load the plugin directly from the build tree. Otherwise it's static and already loaded. */ @@ -63,12 +92,15 @@ AnySceneImporterTest::AnySceneImporterTest() { #endif } -void AnySceneImporterTest::obj() { +void AnySceneImporterTest::load() { + auto&& data = LoadData[testCaseInstanceId()]; + setTestCaseDescription(data.name); + if(!(_manager.loadState("ObjImporter") & PluginManager::LoadState::Loaded)) CORRADE_SKIP("ObjImporter plugin not enabled, cannot test"); Containers::Pointer importer = _manager.instantiate("AnySceneImporter"); - CORRADE_VERIFY(importer->openFile(OBJ_FILE)); + CORRADE_VERIFY(importer->openFile(data.filename)); /* Check only size, as it is good enough proof that it is working */ Containers::Optional mesh = importer->mesh3D(0); @@ -76,6 +108,25 @@ void AnySceneImporterTest::obj() { CORRADE_COMPARE(mesh->positions(0).size(), 3); } +void AnySceneImporterTest::detect() { + auto&& data = DetectData[testCaseInstanceId()]; + setTestCaseDescription(data.name); + + Containers::Pointer importer = _manager.instantiate("AnySceneImporter"); + + std::ostringstream out; + Error redirectError{&out}; + CORRADE_VERIFY(!importer->openFile(data.filename)); + /* Can't use raw string literals in macros on GCC 4.8 */ + #ifndef CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT + CORRADE_COMPARE(out.str(), Utility::formatString( +"PluginManager::Manager::load(): plugin {0} is not static and was not found in nonexistent\nTrade::AnySceneImporter::openFile(): cannot load {0} plugin\n", data.plugin)); + #else + CORRADE_COMPARE(out.str(), Utility::formatString( +"PluginManager::Manager::load(): plugin {0} was not found\nTrade::AnySceneImporter::openFile(): cannot load {0} plugin\n", data.plugin)); + #endif +} + void AnySceneImporterTest::unknown() { std::ostringstream output; Error redirectError{&output};