You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

456 lines
18 KiB

/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <sstream>
Trade: refresh the AbstractImageConverter API. First and foremost I need to expand the interface to support 3D image conversion. But the interface was not great to begin with, so this takes the opportunity of an API break and does several things: * The `export*()` names were rather strange and I don't even remember why I chose that name (maybe because at first I wanted to have an "exporter" API as a counterpart to importers?) * In addition, there was no way to convert a compressed image to a compressed image (or to an uncompressed image) and adding the two missing variants would be a lot of combinations. So instead the new convert() returns an ImageData, which can be both, and thus also allows the converters to produce compressed or uncompressed output based on some runtime setting, without having to implement two (four?) separate functions for that and requiring users to know beforehand what type of an image will be created. * The ImageConverterFeature enum was named in a really strange way as well, with ConvertCompressedImage meaning "convert to a compressed image" while "ConvertCompressedData" instead meant "convert a compressed image to a data". Utter chaos. It also all implied 2D and on the other hand had a redundant `Image` in the name, so I went and remade the whole thing. As mentioned above, two of the enums now mean the same thing, and are both replaced with Convert2D. * Finally, similarly as changes elsewhere, I took this opportunity to get rid of std::string in the convertToFile() APIs.
5 years ago
#include <Corrade/Containers/StringStl.h>
#include <Corrade/PluginManager/Manager.h>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/TestSuite/Compare/File.h>
#include <Corrade/Utility/ConfigurationGroup.h>
#include <Corrade/Utility/Directory.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/FormatStl.h>
#include "Magnum/ImageView.h"
#include "Magnum/PixelFormat.h"
plugins: new testing workflow. The current testing workflow had quite a few major flaws and it was no longer possible after the move of Any* plugins to core. Among the flaws is: * Every plugin was basically built twice, once as the real plugin and once as a static testing library. Most of the build shared common object files, but nevertheless it inflated build times and made the buildsystem extremely complex. * Because the actual plugin binary was never actually loaded during the test, it couldn't spot problems like: - undefined references - errors in metadata files - mismatched plugin interface/version, missing entry points - broken static plugin import files * Tests that made use of independent plugins (such as TgaImageConverter test using TgaImporter to verify the output) had a hardcoded dependency on such plugins, making a minimal setup very hard. * Dynamic loading of plugins from the Any* proxies was always directed to the install location on the filesystem with no possibility to load these directly from the build tree. That caused random ABI mismatch crashes, or, on the other hand, if no plugins were installed, particular portions of the codebase weren't tested at all. Now the workflow is the following: * Every plugin is built exactly once, either as dynamic or as static. * The test always loads it via the plugin manager. If it's dynamic, it's loaded straight from the build directory; if it's static, it gets linked to the test executable directly. * Plugins used indirectly are always served from the build directory (if enabled) to ensure reproducibility and independence on what's installed on the filesystem. Missing presence of these plugins causes particular tests to be simply skipped. * Plugins that have extensive tests for internal functionality that's not exposed through the plugin interface are still built in two parts, but the internal tests are simply consuming the OBJECT files directly instead of linking to a static library.
8 years ago
#include "Magnum/Trade/AbstractImageConverter.h"
#include "Magnum/Trade/ImageData.h"
#include "configure.h"
namespace Magnum { namespace Trade { namespace Test { namespace {
struct AnyImageConverterTest: TestSuite::Tester {
explicit AnyImageConverterTest();
void convert1D();
void convert2D();
void convert3D();
void convertCompressed1D();
void convertCompressed2D();
void convertCompressed3D();
void detect1D();
void detect2D();
void detect3D();
void detectCompressed1D();
void detectCompressed2D();
void detectCompressed3D();
void unknown1D();
void unknown2D();
void unknown3D();
void unknownCompressed1D();
void unknownCompressed2D();
void unknownCompressed3D();
void propagateFlags1D();
void propagateFlags2D();
void propagateFlags3D();
void propagateFlagsCompressed1D();
void propagateFlagsCompressed2D();
void propagateFlagsCompressed3D();
void propagateConfiguration1D();
void propagateConfiguration2D();
void propagateConfiguration3D();
void propagateConfigurationUnknown1D();
void propagateConfigurationUnknown2D();
void propagateConfigurationUnknown3D();
void propagateConfigurationCompressed1D();
void propagateConfigurationCompressed2D();
void propagateConfigurationCompressed3D();
void propagateConfigurationCompressedUnknown1D();
void propagateConfigurationCompressedUnknown2D();
void propagateConfigurationCompressedUnknown3D();
/* configuration propagation fully tested in AnySceneImporter, as there the
plugins have configuration subgroups as well */
plugins: new testing workflow. The current testing workflow had quite a few major flaws and it was no longer possible after the move of Any* plugins to core. Among the flaws is: * Every plugin was basically built twice, once as the real plugin and once as a static testing library. Most of the build shared common object files, but nevertheless it inflated build times and made the buildsystem extremely complex. * Because the actual plugin binary was never actually loaded during the test, it couldn't spot problems like: - undefined references - errors in metadata files - mismatched plugin interface/version, missing entry points - broken static plugin import files * Tests that made use of independent plugins (such as TgaImageConverter test using TgaImporter to verify the output) had a hardcoded dependency on such plugins, making a minimal setup very hard. * Dynamic loading of plugins from the Any* proxies was always directed to the install location on the filesystem with no possibility to load these directly from the build tree. That caused random ABI mismatch crashes, or, on the other hand, if no plugins were installed, particular portions of the codebase weren't tested at all. Now the workflow is the following: * Every plugin is built exactly once, either as dynamic or as static. * The test always loads it via the plugin manager. If it's dynamic, it's loaded straight from the build directory; if it's static, it gets linked to the test executable directly. * Plugins used indirectly are always served from the build directory (if enabled) to ensure reproducibility and independence on what's installed on the filesystem. Missing presence of these plugins causes particular tests to be simply skipped. * Plugins that have extensive tests for internal functionality that's not exposed through the plugin interface are still built in two parts, but the internal tests are simply consuming the OBJECT files directly instead of linking to a static library.
8 years ago
/* Explicitly forbid system-wide plugin dependencies */
PluginManager::Manager<AbstractImageConverter> _manager{"nonexistent"};
};
constexpr struct {
const char* name;
const char* filename;
} Convert2DData[]{
{"TGA", "output.tga"}
};
constexpr struct {
const char* name;
const char* filename;
const char* plugin;
} Detect2DData[]{
{"BMP", "file.bmp", "BmpImageConverter"},
{"EXR", "file.exr", "OpenExrImageConverter"},
{"HDR", "file.hdr", "HdrImageConverter"},
{"JPEG", "file.jpg", "JpegImageConverter"},
{"JPEG weird extension", "file.jpe", "JpegImageConverter"},
{"JPEG uppercase", "output.JPG", "JpegImageConverter"},
{"PNG", "file.png", "PngImageConverter"}
};
plugins: new testing workflow. The current testing workflow had quite a few major flaws and it was no longer possible after the move of Any* plugins to core. Among the flaws is: * Every plugin was basically built twice, once as the real plugin and once as a static testing library. Most of the build shared common object files, but nevertheless it inflated build times and made the buildsystem extremely complex. * Because the actual plugin binary was never actually loaded during the test, it couldn't spot problems like: - undefined references - errors in metadata files - mismatched plugin interface/version, missing entry points - broken static plugin import files * Tests that made use of independent plugins (such as TgaImageConverter test using TgaImporter to verify the output) had a hardcoded dependency on such plugins, making a minimal setup very hard. * Dynamic loading of plugins from the Any* proxies was always directed to the install location on the filesystem with no possibility to load these directly from the build tree. That caused random ABI mismatch crashes, or, on the other hand, if no plugins were installed, particular portions of the codebase weren't tested at all. Now the workflow is the following: * Every plugin is built exactly once, either as dynamic or as static. * The test always loads it via the plugin manager. If it's dynamic, it's loaded straight from the build directory; if it's static, it gets linked to the test executable directly. * Plugins used indirectly are always served from the build directory (if enabled) to ensure reproducibility and independence on what's installed on the filesystem. Missing presence of these plugins causes particular tests to be simply skipped. * Plugins that have extensive tests for internal functionality that's not exposed through the plugin interface are still built in two parts, but the internal tests are simply consuming the OBJECT files directly instead of linking to a static library.
8 years ago
AnyImageConverterTest::AnyImageConverterTest() {
addTests({&AnyImageConverterTest::convert1D});
addInstancedTests({&AnyImageConverterTest::convert2D},
Containers::arraySize(Convert2DData));
addTests({&AnyImageConverterTest::convert3D,
&AnyImageConverterTest::convertCompressed1D,
&AnyImageConverterTest::convertCompressed2D,
&AnyImageConverterTest::convertCompressed3D,
&AnyImageConverterTest::detect1D});
addInstancedTests({&AnyImageConverterTest::detect2D},
Containers::arraySize(Detect2DData));
addTests({&AnyImageConverterTest::detect3D,
&AnyImageConverterTest::detectCompressed1D,
&AnyImageConverterTest::detectCompressed2D,
&AnyImageConverterTest::detectCompressed3D,
&AnyImageConverterTest::unknown1D,
&AnyImageConverterTest::unknown2D,
&AnyImageConverterTest::unknown3D,
&AnyImageConverterTest::unknownCompressed1D,
&AnyImageConverterTest::unknownCompressed2D,
&AnyImageConverterTest::unknownCompressed3D,
&AnyImageConverterTest::propagateFlags1D,
&AnyImageConverterTest::propagateFlags2D,
&AnyImageConverterTest::propagateFlags3D,
&AnyImageConverterTest::propagateFlagsCompressed1D,
&AnyImageConverterTest::propagateFlagsCompressed2D,
&AnyImageConverterTest::propagateFlagsCompressed3D,
&AnyImageConverterTest::propagateConfiguration1D,
&AnyImageConverterTest::propagateConfiguration2D,
&AnyImageConverterTest::propagateConfiguration3D,
&AnyImageConverterTest::propagateConfigurationUnknown1D,
&AnyImageConverterTest::propagateConfigurationUnknown2D,
&AnyImageConverterTest::propagateConfigurationUnknown3D,
&AnyImageConverterTest::propagateConfigurationCompressed1D,
&AnyImageConverterTest::propagateConfigurationCompressed2D,
&AnyImageConverterTest::propagateConfigurationCompressed3D,
&AnyImageConverterTest::propagateConfigurationCompressedUnknown1D,
&AnyImageConverterTest::propagateConfigurationCompressedUnknown2D,
&AnyImageConverterTest::propagateConfigurationCompressedUnknown3D});
plugins: new testing workflow. The current testing workflow had quite a few major flaws and it was no longer possible after the move of Any* plugins to core. Among the flaws is: * Every plugin was basically built twice, once as the real plugin and once as a static testing library. Most of the build shared common object files, but nevertheless it inflated build times and made the buildsystem extremely complex. * Because the actual plugin binary was never actually loaded during the test, it couldn't spot problems like: - undefined references - errors in metadata files - mismatched plugin interface/version, missing entry points - broken static plugin import files * Tests that made use of independent plugins (such as TgaImageConverter test using TgaImporter to verify the output) had a hardcoded dependency on such plugins, making a minimal setup very hard. * Dynamic loading of plugins from the Any* proxies was always directed to the install location on the filesystem with no possibility to load these directly from the build tree. That caused random ABI mismatch crashes, or, on the other hand, if no plugins were installed, particular portions of the codebase weren't tested at all. Now the workflow is the following: * Every plugin is built exactly once, either as dynamic or as static. * The test always loads it via the plugin manager. If it's dynamic, it's loaded straight from the build directory; if it's static, it gets linked to the test executable directly. * Plugins used indirectly are always served from the build directory (if enabled) to ensure reproducibility and independence on what's installed on the filesystem. Missing presence of these plugins causes particular tests to be simply skipped. * Plugins that have extensive tests for internal functionality that's not exposed through the plugin interface are still built in two parts, but the internal tests are simply consuming the OBJECT files directly instead of linking to a static library.
8 years ago
/* Load the plugin directly from the build tree. Otherwise it's static and
already loaded. */
#ifdef ANYIMAGECONVERTER_PLUGIN_FILENAME
CORRADE_INTERNAL_ASSERT_OUTPUT(_manager.load(ANYIMAGECONVERTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded);
plugins: new testing workflow. The current testing workflow had quite a few major flaws and it was no longer possible after the move of Any* plugins to core. Among the flaws is: * Every plugin was basically built twice, once as the real plugin and once as a static testing library. Most of the build shared common object files, but nevertheless it inflated build times and made the buildsystem extremely complex. * Because the actual plugin binary was never actually loaded during the test, it couldn't spot problems like: - undefined references - errors in metadata files - mismatched plugin interface/version, missing entry points - broken static plugin import files * Tests that made use of independent plugins (such as TgaImageConverter test using TgaImporter to verify the output) had a hardcoded dependency on such plugins, making a minimal setup very hard. * Dynamic loading of plugins from the Any* proxies was always directed to the install location on the filesystem with no possibility to load these directly from the build tree. That caused random ABI mismatch crashes, or, on the other hand, if no plugins were installed, particular portions of the codebase weren't tested at all. Now the workflow is the following: * Every plugin is built exactly once, either as dynamic or as static. * The test always loads it via the plugin manager. If it's dynamic, it's loaded straight from the build directory; if it's static, it gets linked to the test executable directly. * Plugins used indirectly are always served from the build directory (if enabled) to ensure reproducibility and independence on what's installed on the filesystem. Missing presence of these plugins causes particular tests to be simply skipped. * Plugins that have extensive tests for internal functionality that's not exposed through the plugin interface are still built in two parts, but the internal tests are simply consuming the OBJECT files directly instead of linking to a static library.
8 years ago
#endif
/* Optional plugins that don't have to be here */
#ifdef TGAIMAGECONVERTER_PLUGIN_FILENAME
CORRADE_INTERNAL_ASSERT_OUTPUT(_manager.load(TGAIMAGECONVERTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded);
plugins: new testing workflow. The current testing workflow had quite a few major flaws and it was no longer possible after the move of Any* plugins to core. Among the flaws is: * Every plugin was basically built twice, once as the real plugin and once as a static testing library. Most of the build shared common object files, but nevertheless it inflated build times and made the buildsystem extremely complex. * Because the actual plugin binary was never actually loaded during the test, it couldn't spot problems like: - undefined references - errors in metadata files - mismatched plugin interface/version, missing entry points - broken static plugin import files * Tests that made use of independent plugins (such as TgaImageConverter test using TgaImporter to verify the output) had a hardcoded dependency on such plugins, making a minimal setup very hard. * Dynamic loading of plugins from the Any* proxies was always directed to the install location on the filesystem with no possibility to load these directly from the build tree. That caused random ABI mismatch crashes, or, on the other hand, if no plugins were installed, particular portions of the codebase weren't tested at all. Now the workflow is the following: * Every plugin is built exactly once, either as dynamic or as static. * The test always loads it via the plugin manager. If it's dynamic, it's loaded straight from the build directory; if it's static, it gets linked to the test executable directly. * Plugins used indirectly are always served from the build directory (if enabled) to ensure reproducibility and independence on what's installed on the filesystem. Missing presence of these plugins causes particular tests to be simply skipped. * Plugins that have extensive tests for internal functionality that's not exposed through the plugin interface are still built in two parts, but the internal tests are simply consuming the OBJECT files directly instead of linking to a static library.
8 years ago
#endif
/* Create the output directory if it doesn't exist yet */
CORRADE_INTERNAL_ASSERT_OUTPUT(Utility::Directory::mkpath(ANYIMAGECONVERTER_TEST_OUTPUT_DIR));
}
/* 2*3*2 RGB pixels with four-byte row padding, or 3 16-byte blocks */
constexpr const char Data[] = {
1, 2, 3, 2, 3, 4, 0, 0,
3, 4, 5, 4, 5, 6, 0, 0,
5, 6, 7, 6, 7, 8, 0, 0,
7, 8, 9, 8, 9, 0, 0, 0,
9, 0, 1, 0, 1, 2, 0, 0,
1, 2, 3, 2, 3, 4, 0, 0
};
const ImageView1D Image1D{PixelFormat::RGB8Unorm, 2, Data};
const ImageView2D Image2D{PixelFormat::RGB8Unorm, {2, 3}, Data};
const ImageView3D Image3D{PixelFormat::RGB8Unorm, {2, 3, 2}, Data};
const CompressedImageView1D CompressedImage1D{CompressedPixelFormat::Bc1RGBAUnorm, 3, Data};
const CompressedImageView2D CompressedImage2D{CompressedPixelFormat::Bc1RGBAUnorm, {1, 3}, Data};
const CompressedImageView3D CompressedImage3D{CompressedPixelFormat::Bc1RGBAUnorm, {1, 1, 3}, Data};
void AnyImageConverterTest::convert1D() {
CORRADE_SKIP("No file formats to store 1D data yet.");
}
void AnyImageConverterTest::convert2D() {
auto&& data = Convert2DData[testCaseInstanceId()];
setTestCaseDescription(data.name);
plugins: new testing workflow. The current testing workflow had quite a few major flaws and it was no longer possible after the move of Any* plugins to core. Among the flaws is: * Every plugin was basically built twice, once as the real plugin and once as a static testing library. Most of the build shared common object files, but nevertheless it inflated build times and made the buildsystem extremely complex. * Because the actual plugin binary was never actually loaded during the test, it couldn't spot problems like: - undefined references - errors in metadata files - mismatched plugin interface/version, missing entry points - broken static plugin import files * Tests that made use of independent plugins (such as TgaImageConverter test using TgaImporter to verify the output) had a hardcoded dependency on such plugins, making a minimal setup very hard. * Dynamic loading of plugins from the Any* proxies was always directed to the install location on the filesystem with no possibility to load these directly from the build tree. That caused random ABI mismatch crashes, or, on the other hand, if no plugins were installed, particular portions of the codebase weren't tested at all. Now the workflow is the following: * Every plugin is built exactly once, either as dynamic or as static. * The test always loads it via the plugin manager. If it's dynamic, it's loaded straight from the build directory; if it's static, it gets linked to the test executable directly. * Plugins used indirectly are always served from the build directory (if enabled) to ensure reproducibility and independence on what's installed on the filesystem. Missing presence of these plugins causes particular tests to be simply skipped. * Plugins that have extensive tests for internal functionality that's not exposed through the plugin interface are still built in two parts, but the internal tests are simply consuming the OBJECT files directly instead of linking to a static library.
8 years ago
if(!(_manager.loadState("TgaImageConverter") & PluginManager::LoadState::Loaded))
CORRADE_SKIP("TgaImageConverter plugin not enabled, cannot test");
const std::string filename = Utility::Directory::join(ANYIMAGECONVERTER_TEST_OUTPUT_DIR, data.filename);
if(Utility::Directory::exists(filename))
CORRADE_VERIFY(Utility::Directory::rm(filename));
/* Just test that the exported file exists */
Containers::Pointer<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
CORRADE_VERIFY(converter->convertToFile(Image2D, filename));
CORRADE_VERIFY(Utility::Directory::exists(filename));
}
void AnyImageConverterTest::convert3D() {
CORRADE_SKIP("No file formats to store 3D data yet.");
}
void AnyImageConverterTest::convertCompressed1D() {
CORRADE_SKIP("No file formats to store compressed 1D data yet.");
}
void AnyImageConverterTest::convertCompressed2D() {
CORRADE_SKIP("No file formats to store compressed 2D data yet.");
}
void AnyImageConverterTest::convertCompressed3D() {
CORRADE_SKIP("No file formats to store compressed 3D data yet.");
}
void AnyImageConverterTest::detect1D() {
CORRADE_SKIP("No file formats to store 1D data yet.");
}
void AnyImageConverterTest::detect2D() {
auto&& data = Detect2DData[testCaseInstanceId()];
setTestCaseDescription(data.name);
Containers::Pointer<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!converter->convertToFile(Image2D, 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(
Trade: refresh the AbstractImageConverter API. First and foremost I need to expand the interface to support 3D image conversion. But the interface was not great to begin with, so this takes the opportunity of an API break and does several things: * The `export*()` names were rather strange and I don't even remember why I chose that name (maybe because at first I wanted to have an "exporter" API as a counterpart to importers?) * In addition, there was no way to convert a compressed image to a compressed image (or to an uncompressed image) and adding the two missing variants would be a lot of combinations. So instead the new convert() returns an ImageData, which can be both, and thus also allows the converters to produce compressed or uncompressed output based on some runtime setting, without having to implement two (four?) separate functions for that and requiring users to know beforehand what type of an image will be created. * The ImageConverterFeature enum was named in a really strange way as well, with ConvertCompressedImage meaning "convert to a compressed image" while "ConvertCompressedData" instead meant "convert a compressed image to a data". Utter chaos. It also all implied 2D and on the other hand had a redundant `Image` in the name, so I went and remade the whole thing. As mentioned above, two of the enums now mean the same thing, and are both replaced with Convert2D. * Finally, similarly as changes elsewhere, I took this opportunity to get rid of std::string in the convertToFile() APIs.
5 years ago
"PluginManager::Manager::load(): plugin {0} is not static and was not found in nonexistent\nTrade::AnyImageConverter::convertToFile(): cannot load the {0} plugin\n", data.plugin));
#else
CORRADE_COMPARE(out.str(), Utility::formatString(
Trade: refresh the AbstractImageConverter API. First and foremost I need to expand the interface to support 3D image conversion. But the interface was not great to begin with, so this takes the opportunity of an API break and does several things: * The `export*()` names were rather strange and I don't even remember why I chose that name (maybe because at first I wanted to have an "exporter" API as a counterpart to importers?) * In addition, there was no way to convert a compressed image to a compressed image (or to an uncompressed image) and adding the two missing variants would be a lot of combinations. So instead the new convert() returns an ImageData, which can be both, and thus also allows the converters to produce compressed or uncompressed output based on some runtime setting, without having to implement two (four?) separate functions for that and requiring users to know beforehand what type of an image will be created. * The ImageConverterFeature enum was named in a really strange way as well, with ConvertCompressedImage meaning "convert to a compressed image" while "ConvertCompressedData" instead meant "convert a compressed image to a data". Utter chaos. It also all implied 2D and on the other hand had a redundant `Image` in the name, so I went and remade the whole thing. As mentioned above, two of the enums now mean the same thing, and are both replaced with Convert2D. * Finally, similarly as changes elsewhere, I took this opportunity to get rid of std::string in the convertToFile() APIs.
5 years ago
"PluginManager::Manager::load(): plugin {0} was not found\nTrade::AnyImageConverter::convertToFile(): cannot load the {0} plugin\n", data.plugin));
#endif
}
void AnyImageConverterTest::detect3D() {
CORRADE_SKIP("No file formats to store 3D data yet.");
}
void AnyImageConverterTest::detectCompressed1D() {
CORRADE_SKIP("No file formats to store compressed 1D data yet.");
}
void AnyImageConverterTest::detectCompressed2D() {
CORRADE_SKIP("No file formats to store compressed 2D data yet.");
}
void AnyImageConverterTest::detectCompressed3D() {
CORRADE_SKIP("No file formats to store compressed 3D data yet.");
}
void AnyImageConverterTest::unknown1D() {
Containers::Pointer<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!converter->convertToFile(Image1D, "image.ktx2"));
CORRADE_COMPARE(out.str(), "Trade::AnyImageConverter::convertToFile(): cannot determine the format of image.ktx2 for a 1D image\n");
}
void AnyImageConverterTest::unknown2D() {
Containers::Pointer<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!converter->convertToFile(Image2D, "image.xcf"));
CORRADE_COMPARE(out.str(), "Trade::AnyImageConverter::convertToFile(): cannot determine the format of image.xcf for a 2D image\n");
}
void AnyImageConverterTest::unknown3D() {
Containers::Pointer<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!converter->convertToFile(Image3D, "image.ktx2"));
CORRADE_COMPARE(out.str(), "Trade::AnyImageConverter::convertToFile(): cannot determine the format of image.ktx2 for a 3D image\n");
}
void AnyImageConverterTest::unknownCompressed1D() {
Containers::Pointer<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!converter->convertToFile(CompressedImage1D, "image.ktx2"));
CORRADE_COMPARE(out.str(), "Trade::AnyImageConverter::convertToFile(): cannot determine the format of image.ktx2 for a compressed 1D image\n");
}
void AnyImageConverterTest::unknownCompressed2D() {
Containers::Pointer<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!converter->convertToFile(CompressedImage2D, "image.ktx2"));
CORRADE_COMPARE(out.str(), "Trade::AnyImageConverter::convertToFile(): cannot determine the format of image.ktx2 for a compressed 2D image\n");
}
void AnyImageConverterTest::unknownCompressed3D() {
Containers::Pointer<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!converter->convertToFile(CompressedImage3D, "image.ktx2"));
CORRADE_COMPARE(out.str(), "Trade::AnyImageConverter::convertToFile(): cannot determine the format of image.ktx2 for a compressed 3D image\n");
}
void AnyImageConverterTest::propagateFlags1D() {
CORRADE_SKIP("No file formats to store 1D data yet.");
}
void AnyImageConverterTest::propagateFlags2D() {
if(!(_manager.loadState("TgaImageConverter") & PluginManager::LoadState::Loaded))
CORRADE_SKIP("TgaImageConverter plugin not enabled, cannot test");
const std::string filename = Utility::Directory::join(ANYIMAGECONVERTER_TEST_OUTPUT_DIR, "output.tga");
if(Utility::Directory::exists(filename))
CORRADE_VERIFY(Utility::Directory::rm(filename));
/* Just test that the exported file exists */
Containers::Pointer<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
converter->setFlags(ImageConverterFlag::Verbose);
std::ostringstream out;
{
Debug redirectOutput{&out};
CORRADE_VERIFY(converter->convertToFile(Image2D, filename));
}
CORRADE_VERIFY(Utility::Directory::exists(filename));
CORRADE_COMPARE(out.str(),
Trade: refresh the AbstractImageConverter API. First and foremost I need to expand the interface to support 3D image conversion. But the interface was not great to begin with, so this takes the opportunity of an API break and does several things: * The `export*()` names were rather strange and I don't even remember why I chose that name (maybe because at first I wanted to have an "exporter" API as a counterpart to importers?) * In addition, there was no way to convert a compressed image to a compressed image (or to an uncompressed image) and adding the two missing variants would be a lot of combinations. So instead the new convert() returns an ImageData, which can be both, and thus also allows the converters to produce compressed or uncompressed output based on some runtime setting, without having to implement two (four?) separate functions for that and requiring users to know beforehand what type of an image will be created. * The ImageConverterFeature enum was named in a really strange way as well, with ConvertCompressedImage meaning "convert to a compressed image" while "ConvertCompressedData" instead meant "convert a compressed image to a data". Utter chaos. It also all implied 2D and on the other hand had a redundant `Image` in the name, so I went and remade the whole thing. As mentioned above, two of the enums now mean the same thing, and are both replaced with Convert2D. * Finally, similarly as changes elsewhere, I took this opportunity to get rid of std::string in the convertToFile() APIs.
5 years ago
"Trade::AnyImageConverter::convertToFile(): using TgaImageConverter\n"
"Trade::TgaImageConverter::convertToData(): converting from RGB to BGR\n");
}
void AnyImageConverterTest::propagateFlags3D() {
CORRADE_SKIP("No file formats to store 3D data yet.");
}
void AnyImageConverterTest::propagateFlagsCompressed1D() {
CORRADE_SKIP("No file formats to store compressed 1D data yet.");
}
void AnyImageConverterTest::propagateFlagsCompressed2D() {
CORRADE_SKIP("No file formats to store compressed 2D data yet.");
}
void AnyImageConverterTest::propagateFlagsCompressed3D() {
CORRADE_SKIP("No file formats to store compressed 3D data yet.");
}
void AnyImageConverterTest::propagateConfiguration1D() {
CORRADE_SKIP("No file formats to store 1D data yet.");
}
void AnyImageConverterTest::propagateConfiguration2D() {
PluginManager::Manager<AbstractImageConverter> manager{MAGNUM_PLUGINS_IMAGECONVERTER_INSTALL_DIR};
#ifdef ANYIMAGECONVERTER_PLUGIN_FILENAME
CORRADE_VERIFY(manager.load(ANYIMAGECONVERTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded);
#endif
if(manager.loadState("OpenExrImageConverter") < PluginManager::LoadState::Loaded)
CORRADE_SKIP("OpenExrImageConverter plugin can't be loaded.");
const std::string filename = Utility::Directory::join(ANYIMAGECONVERTER_TEST_OUTPUT_DIR, "depth32f-custom-channels.exr");
if(Utility::Directory::exists(filename))
CORRADE_VERIFY(Utility::Directory::rm(filename));
const Float Depth32fData[] = {
0.125f, 0.250f, 0.375f,
0.500f, 0.625f, 0.750f
};
const ImageView2D Depth32f{PixelFormat::Depth32F, {3, 2}, Depth32fData};
Containers::Pointer<AbstractImageConverter> converter = manager.instantiate("AnyImageConverter");
converter->configuration().setValue("layer", "left");
converter->configuration().setValue("depth", "height");
CORRADE_VERIFY(converter->convertToFile(Depth32f, filename));
/* Compare to an expected output to ensure the custom channels names were
used */
CORRADE_COMPARE_AS(filename, EXR_FILE, TestSuite::Compare::File);
}
void AnyImageConverterTest::propagateConfiguration3D() {
CORRADE_SKIP("No file formats to store 3D data yet.");
}
void AnyImageConverterTest::propagateConfigurationUnknown1D() {
CORRADE_SKIP("No file formats to store 1D data yet.");
}
void AnyImageConverterTest::propagateConfigurationUnknown2D() {
if(!(_manager.loadState("TgaImageConverter") & PluginManager::LoadState::Loaded))
CORRADE_SKIP("TgaImageConverter plugin not enabled, cannot test");
/* Just test that the exported file exists */
Containers::Pointer<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
converter->configuration().setValue("noSuchOption", "isHere");
std::ostringstream out;
Warning redirectWarning{&out};
CORRADE_VERIFY(converter->convertToFile(Image2D, Utility::Directory::join(ANYIMAGECONVERTER_TEST_OUTPUT_DIR, "output.tga")));
CORRADE_COMPARE(out.str(), "Trade::AnyImageConverter::convertToFile(): option noSuchOption not recognized by TgaImageConverter\n");
}
void AnyImageConverterTest::propagateConfigurationUnknown3D() {
CORRADE_SKIP("No file formats to store 3D data yet.");
}
void AnyImageConverterTest::propagateConfigurationCompressed1D() {
CORRADE_SKIP("No file formats to store compressed 1D data yet.");
}
void AnyImageConverterTest::propagateConfigurationCompressed2D() {
CORRADE_SKIP("No file formats to store compressed 2D data yet.");
}
void AnyImageConverterTest::propagateConfigurationCompressed3D() {
CORRADE_SKIP("No file formats to store compressed 3D data yet.");
}
void AnyImageConverterTest::propagateConfigurationCompressedUnknown1D() {
CORRADE_SKIP("No file formats to store compressed 1D data yet.");
}
void AnyImageConverterTest::propagateConfigurationCompressedUnknown2D() {
CORRADE_SKIP("No file formats to store compressed 2D data yet.");
}
void AnyImageConverterTest::propagateConfigurationCompressedUnknown3D() {
CORRADE_SKIP("No file formats to store compressed 3D data yet.");
}
}}}}
CORRADE_TEST_MAIN(Magnum::Trade::Test::AnyImageConverterTest)