From 603f87fadc74a81add0dc241da5b4e3833e0e880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 3 Jun 2026 23:34:56 +0200 Subject: [PATCH] ShaderTools,Text,Trade: improve construction tests. In some cases the plugin manager constructor was not tested at all, leading to an uncovered line. For importers also verify that calling close() on a non-opened instance doesn't call into doClose(). Again, the Audio importer isn't touched at all, as that interface is scheduled for mergin into Trade. --- .../Test/AbstractConverterTest.cpp | 36 +++++++++++++++++++ .../Text/Test/AbstractFontConverterTest.cpp | 16 ++++++++- src/Magnum/Text/Test/AbstractFontTest.cpp | 5 ++- .../Trade/Test/AbstractImporterTest.cpp | 5 ++- .../Trade/Test/AbstractSceneConverterTest.cpp | 32 +++++++++++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) diff --git a/src/Magnum/ShaderTools/Test/AbstractConverterTest.cpp b/src/Magnum/ShaderTools/Test/AbstractConverterTest.cpp index 4ebde3294..ca6310bb8 100644 --- a/src/Magnum/ShaderTools/Test/AbstractConverterTest.cpp +++ b/src/Magnum/ShaderTools/Test/AbstractConverterTest.cpp @@ -47,6 +47,9 @@ namespace Magnum { namespace ShaderTools { namespace Test { namespace { struct AbstractConverterTest: TestSuite::Tester { explicit AbstractConverterTest(); + void construct(); + void constructWithPluginManagerReference(); + void featuresNone(); void setFlags(); @@ -204,6 +207,9 @@ struct AbstractConverterTest: TestSuite::Tester { AbstractConverterTest::AbstractConverterTest() { addTests({&AbstractConverterTest::featuresNone, + &AbstractConverterTest::construct, + &AbstractConverterTest::constructWithPluginManagerReference, + &AbstractConverterTest::setFlags, &AbstractConverterTest::setFlagsBothQuietAndVerbose, &AbstractConverterTest::setFlagsPreprocessNotSupported, @@ -359,6 +365,36 @@ AbstractConverterTest::AbstractConverterTest() { Utility::Path::make(SHADERTOOLS_TEST_OUTPUT_DIR); } +void AbstractConverterTest::construct() { + struct: AbstractConverter { + ConverterFeatures doFeatures() const override { + return ConverterFeature::ValidateData; + } + void doSetInputFormat(Format, Containers::StringView) override {} + void doSetOutputFormat(Format, Containers::StringView) override {} + } converter; + + CORRADE_COMPARE(converter.features(), ConverterFeature::ValidateData); + CORRADE_COMPARE(converter.flags(), ConverterFlags{}); +} + +void AbstractConverterTest::constructWithPluginManagerReference() { + PluginManager::Manager manager; + + struct Converter: AbstractConverter { + explicit Converter(PluginManager::Manager& manager): AbstractConverter{manager} {} + + ConverterFeatures doFeatures() const override { + return ConverterFeature::ValidateFile; + } + void doSetInputFormat(Format, Containers::StringView) override {} + void doSetOutputFormat(Format, Containers::StringView) override {} + } converter{manager}; + + CORRADE_COMPARE(converter.features(), ConverterFeature::ValidateFile); + CORRADE_COMPARE(converter.flags(), ConverterFlags{}); +} + void AbstractConverterTest::featuresNone() { CORRADE_SKIP_IF_NO_ASSERT(); diff --git a/src/Magnum/Text/Test/AbstractFontConverterTest.cpp b/src/Magnum/Text/Test/AbstractFontConverterTest.cpp index a1c790356..d835c2099 100644 --- a/src/Magnum/Text/Test/AbstractFontConverterTest.cpp +++ b/src/Magnum/Text/Test/AbstractFontConverterTest.cpp @@ -48,6 +48,8 @@ namespace Magnum { namespace Text { namespace Test { namespace { struct AbstractFontConverterTest: TestSuite::Tester { explicit AbstractFontConverterTest(); + void construct(); + void convertGlyphs(); void thingNotSupported(); @@ -112,7 +114,9 @@ struct AbstractFontConverterTest: TestSuite::Tester { }; AbstractFontConverterTest::AbstractFontConverterTest() { - addTests({&AbstractFontConverterTest::convertGlyphs, + addTests({&AbstractFontConverterTest::construct, + + &AbstractFontConverterTest::convertGlyphs, &AbstractFontConverterTest::thingNotSupported, @@ -178,6 +182,16 @@ AbstractFontConverterTest::AbstractFontConverterTest() { Utility::Path::make(TEXT_TEST_OUTPUT_DIR); } +void AbstractFontConverterTest::construct() { + struct: AbstractFontConverter { + FontConverterFeatures doFeatures() const override { + return FontConverterFeature::ConvertData; + } + } converter; + + CORRADE_COMPARE(converter.features(), FontConverterFeature::ConvertData); +} + struct DummyFont: AbstractFont { FontFeatures doFeatures() const override { return {}; } bool doIsOpened() const override { return false; } diff --git a/src/Magnum/Text/Test/AbstractFontTest.cpp b/src/Magnum/Text/Test/AbstractFontTest.cpp index 35f6721a1..b9a1d97ad 100644 --- a/src/Magnum/Text/Test/AbstractFontTest.cpp +++ b/src/Magnum/Text/Test/AbstractFontTest.cpp @@ -222,7 +222,9 @@ void AbstractFontTest::construct() { struct: AbstractFont { FontFeatures doFeatures() const override { return {}; } bool doIsOpened() const override { return false; } - void doClose() override {} + void doClose() override { + CORRADE_FAIL("This should not be called"); + } void doGlyphIdsInto(const Containers::StridedArrayView1D&, const Containers::StridedArrayView1D&) override {} Vector2 doGlyphSize(UnsignedInt) override { return {}; } @@ -233,6 +235,7 @@ void AbstractFontTest::construct() { CORRADE_COMPARE(font.features(), FontFeatures{}); CORRADE_VERIFY(!font.isOpened()); + /* This should be a no-op with doClose() not called at all */ font.close(); CORRADE_VERIFY(!font.isOpened()); } diff --git a/src/Magnum/Trade/Test/AbstractImporterTest.cpp b/src/Magnum/Trade/Test/AbstractImporterTest.cpp index 29ec6a013..c912d5b9f 100644 --- a/src/Magnum/Trade/Test/AbstractImporterTest.cpp +++ b/src/Magnum/Trade/Test/AbstractImporterTest.cpp @@ -733,12 +733,15 @@ void AbstractImporterTest::construct() { struct: AbstractImporter { ImporterFeatures doFeatures() const override { return {}; } bool doIsOpened() const override { return false; } - void doClose() override {} + void doClose() override { + CORRADE_FAIL("This should not be called"); + } } importer; CORRADE_COMPARE(importer.features(), ImporterFeatures{}); CORRADE_VERIFY(!importer.isOpened()); + /* This should be a no-op with doClose() not called at all */ importer.close(); CORRADE_VERIFY(!importer.isOpened()); } diff --git a/src/Magnum/Trade/Test/AbstractSceneConverterTest.cpp b/src/Magnum/Trade/Test/AbstractSceneConverterTest.cpp index b601626a2..852233820 100644 --- a/src/Magnum/Trade/Test/AbstractSceneConverterTest.cpp +++ b/src/Magnum/Trade/Test/AbstractSceneConverterTest.cpp @@ -67,6 +67,9 @@ struct AbstractSceneConverterTest: TestSuite::Tester { void sceneContentsForConverterSingleMesh(); void sceneContentsForConverterAll(); + void construct(); + void constructWithPluginManagerReference(); + void featuresNone(); void setFlags(); @@ -636,6 +639,9 @@ AbstractSceneConverterTest::AbstractSceneConverterTest() { &AbstractSceneConverterTest::sceneContentsForConverterSingleMesh, &AbstractSceneConverterTest::sceneContentsForConverterAll, + &AbstractSceneConverterTest::construct, + &AbstractSceneConverterTest::constructWithPluginManagerReference, + &AbstractSceneConverterTest::featuresNone, &AbstractSceneConverterTest::setFlags, @@ -1014,6 +1020,32 @@ void AbstractSceneConverterTest::sceneContentsForConverterAll() { SceneContent::Names); } +void AbstractSceneConverterTest::construct() { + struct: AbstractSceneConverter { + SceneConverterFeatures doFeatures() const override { + return SceneConverterFeature::ConvertMeshInPlace; + } + } converter; + + CORRADE_COMPARE(converter.features(), SceneConverterFeature::ConvertMeshInPlace); + CORRADE_COMPARE(converter.flags(), SceneConverterFlags{}); +} + +void AbstractSceneConverterTest::constructWithPluginManagerReference() { + PluginManager::Manager manager; + + struct Converter: AbstractSceneConverter { + explicit Converter(PluginManager::Manager& manager): AbstractSceneConverter{manager} {} + + SceneConverterFeatures doFeatures() const override { + return SceneConverterFeature::ConvertMesh; + } + } converter{manager}; + + CORRADE_COMPARE(converter.features(), SceneConverterFeature::ConvertMesh); + CORRADE_COMPARE(converter.flags(), SceneConverterFlags{}); +} + void AbstractSceneConverterTest::featuresNone() { CORRADE_SKIP_IF_NO_ASSERT();