From 35c02023a09ad671f6ba4f48228ff9d059fbebdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 15 Jan 2023 17:53:53 +0100 Subject: [PATCH] TgaImageConverter: properly test also the single-channel case. For some reason I never tested this, although code coverage says it was called from ... somewhere. --- .../Test/TgaImageConverterTest.cpp | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index b99098eb7..09276f112 100644 --- a/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -51,6 +51,7 @@ struct TgaImageConverterTest: TestSuite::Tester { void rgb(); void rgba(); + void r(); void unsupportedMetadata(); @@ -88,6 +89,8 @@ TgaImageConverterTest::TgaImageConverterTest() { &TgaImageConverterTest::rgba}, Containers::arraySize(VerboseData)); + addTests({&TgaImageConverterTest::r}); + addInstancedTests({&TgaImageConverterTest::unsupportedMetadata}, Containers::arraySize(UnsupportedMetadataData)); @@ -203,6 +206,35 @@ void TgaImageConverterTest::rgba() { CORRADE_COMPARE(out.str(), data.message32); } +/* Padding / skip tested in rgb() */ +constexpr char OriginalDataR[] = { + 1, 2, + 3, 4, + 5, 6, +}; +const ImageView2D OriginalR{PixelStorage{}.setAlignment(1), PixelFormat::R8Unorm, {2, 3}, OriginalDataR}; + +void TgaImageConverterTest::r() { + Containers::Pointer converter = _converterManager.instantiate("TgaImageConverter"); + + Containers::Optional> array = converter->convertToData(OriginalR); + CORRADE_VERIFY(array); + + if(!(_importerManager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) + CORRADE_SKIP("TgaImporter plugin not enabled, can't test the result"); + + Containers::Pointer importer = _importerManager.instantiate("TgaImporter"); + CORRADE_VERIFY(importer->openData(*array)); + Containers::Optional converted = importer->image2D(0); + CORRADE_VERIFY(converted); + + CORRADE_COMPARE(converted->storage().alignment(), 1); + CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); + CORRADE_COMPARE(converted->format(), PixelFormat::R8Unorm); + CORRADE_COMPARE_AS(converted->data(), Containers::arrayView(OriginalDataR), + TestSuite::Compare::Container); +} + void TgaImageConverterTest::unsupportedMetadata() { auto&& data = UnsupportedMetadataData[testCaseInstanceId()]; setTestCaseDescription(data.name);