|
|
|
|
@ -49,23 +49,21 @@ class AbstractImageConverterTest: public TestSuite::Tester {
|
|
|
|
|
void construct(); |
|
|
|
|
void constructWithPluginManagerReference(); |
|
|
|
|
|
|
|
|
|
void thingNotSupported(); |
|
|
|
|
|
|
|
|
|
void exportToImage(); |
|
|
|
|
void exportToImageNotSupported(); |
|
|
|
|
void exportToImageNotImplemented(); |
|
|
|
|
void exportToImageCustomDeleter(); |
|
|
|
|
|
|
|
|
|
void exportToCompressedImage(); |
|
|
|
|
void exportToCompressedImageNotSupported(); |
|
|
|
|
void exportToCompressedImageNotImplemented(); |
|
|
|
|
void exportToCompressedImageCustomDeleter(); |
|
|
|
|
|
|
|
|
|
void exportToData(); |
|
|
|
|
void exportToDataNotSupported(); |
|
|
|
|
void exportToDataNotImplemented(); |
|
|
|
|
void exportToDataCustomDeleter(); |
|
|
|
|
|
|
|
|
|
void exportCompressedToData(); |
|
|
|
|
void exportCompressedToDataNotSupported(); |
|
|
|
|
void exportCompressedToDataNotImplemented(); |
|
|
|
|
void exportCompressedToDataCustomDeleter(); |
|
|
|
|
|
|
|
|
|
@ -74,13 +72,11 @@ class AbstractImageConverterTest: public TestSuite::Tester {
|
|
|
|
|
void exportToFile(); |
|
|
|
|
void exportToFileThroughData(); |
|
|
|
|
void exportToFileThroughDataNotWritable(); |
|
|
|
|
void exportToFileNotSupported(); |
|
|
|
|
void exportToFileNotImplemented(); |
|
|
|
|
|
|
|
|
|
void exportCompressedToFile(); |
|
|
|
|
void exportCompressedToFileThroughData(); |
|
|
|
|
void exportCompressedToFileThroughDataNotWritable(); |
|
|
|
|
void exportCompressedToFileNotSupported(); |
|
|
|
|
void exportCompressedToFileNotImplemented(); |
|
|
|
|
|
|
|
|
|
void exportImageDataToFile(); |
|
|
|
|
@ -93,23 +89,21 @@ AbstractImageConverterTest::AbstractImageConverterTest() {
|
|
|
|
|
addTests({&AbstractImageConverterTest::construct, |
|
|
|
|
&AbstractImageConverterTest::constructWithPluginManagerReference, |
|
|
|
|
|
|
|
|
|
&AbstractImageConverterTest::thingNotSupported, |
|
|
|
|
|
|
|
|
|
&AbstractImageConverterTest::exportToImage, |
|
|
|
|
&AbstractImageConverterTest::exportToImageNotSupported, |
|
|
|
|
&AbstractImageConverterTest::exportToImageNotImplemented, |
|
|
|
|
&AbstractImageConverterTest::exportToImageCustomDeleter, |
|
|
|
|
|
|
|
|
|
&AbstractImageConverterTest::exportToCompressedImage, |
|
|
|
|
&AbstractImageConverterTest::exportToCompressedImageNotSupported, |
|
|
|
|
&AbstractImageConverterTest::exportToCompressedImageNotImplemented, |
|
|
|
|
&AbstractImageConverterTest::exportToCompressedImageCustomDeleter, |
|
|
|
|
|
|
|
|
|
&AbstractImageConverterTest::exportToData, |
|
|
|
|
&AbstractImageConverterTest::exportToDataNotSupported, |
|
|
|
|
&AbstractImageConverterTest::exportToDataNotImplemented, |
|
|
|
|
&AbstractImageConverterTest::exportToDataCustomDeleter, |
|
|
|
|
|
|
|
|
|
&AbstractImageConverterTest::exportCompressedToData, |
|
|
|
|
&AbstractImageConverterTest::exportCompressedToDataNotSupported, |
|
|
|
|
&AbstractImageConverterTest::exportCompressedToDataNotImplemented, |
|
|
|
|
&AbstractImageConverterTest::exportCompressedToDataCustomDeleter, |
|
|
|
|
|
|
|
|
|
@ -118,13 +112,11 @@ AbstractImageConverterTest::AbstractImageConverterTest() {
|
|
|
|
|
&AbstractImageConverterTest::exportToFile, |
|
|
|
|
&AbstractImageConverterTest::exportToFileThroughData, |
|
|
|
|
&AbstractImageConverterTest::exportToFileThroughDataNotWritable, |
|
|
|
|
&AbstractImageConverterTest::exportToFileNotSupported, |
|
|
|
|
&AbstractImageConverterTest::exportToFileNotImplemented, |
|
|
|
|
|
|
|
|
|
&AbstractImageConverterTest::exportCompressedToFile, |
|
|
|
|
&AbstractImageConverterTest::exportCompressedToFileThroughData, |
|
|
|
|
&AbstractImageConverterTest::exportCompressedToFileThroughDataNotWritable, |
|
|
|
|
&AbstractImageConverterTest::exportCompressedToFileNotSupported, |
|
|
|
|
&AbstractImageConverterTest::exportCompressedToFileNotImplemented, |
|
|
|
|
|
|
|
|
|
&AbstractImageConverterTest::exportImageDataToFile, |
|
|
|
|
@ -137,472 +129,369 @@ AbstractImageConverterTest::AbstractImageConverterTest() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::construct() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return {}; } |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
CORRADE_COMPARE(converter.features(), ImageConverterFeatures{}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::constructWithPluginManagerReference() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
public: |
|
|
|
|
explicit Converter(PluginManager::Manager<AbstractImageConverter>& manager): AbstractImageConverter{manager} {} |
|
|
|
|
PluginManager::Manager<AbstractImageConverter> manager; |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return {}; } |
|
|
|
|
}; |
|
|
|
|
struct Converter: AbstractImageConverter { |
|
|
|
|
explicit Converter(PluginManager::Manager<AbstractImageConverter>& manager): AbstractImageConverter{manager} {} |
|
|
|
|
|
|
|
|
|
ImageConverterFeatures doFeatures() const override { return {}; } |
|
|
|
|
} converter{manager}; |
|
|
|
|
|
|
|
|
|
PluginManager::Manager<AbstractImageConverter> manager; |
|
|
|
|
Converter converter{manager}; |
|
|
|
|
CORRADE_COMPARE(converter.features(), ImageConverterFeatures{}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::thingNotSupported() { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return {}; } |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
converter.exportToImage(ImageView2D{PixelFormat::R8Unorm, {4, 6}, Containers::ArrayView<char>{nullptr, 24}}); |
|
|
|
|
converter.exportToCompressedImage(ImageView2D{PixelFormat::R8Unorm, {16, 8}, Containers::ArrayView<char>{nullptr, 128}}); |
|
|
|
|
converter.exportToData(ImageView2D{PixelFormat::RGBA8Unorm, {4, 6}, Containers::ArrayView<char>{nullptr, 96}}); |
|
|
|
|
converter.exportToData(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {16, 8}, Containers::ArrayView<char>{nullptr, 64}}); |
|
|
|
|
converter.exportToFile(ImageView2D{PixelFormat::RGBA8Unorm, {4, 6}, {nullptr, 96}}, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")); |
|
|
|
|
converter.exportToFile(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {16, 8}, {nullptr, 64}}, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")); |
|
|
|
|
CORRADE_COMPARE(out.str(), |
|
|
|
|
"Trade::AbstractImageConverter::exportToImage(): feature not supported\n" |
|
|
|
|
"Trade::AbstractImageConverter::exportToCompressedImage(): feature not supported\n" |
|
|
|
|
"Trade::AbstractImageConverter::exportToData(): feature not supported\n" |
|
|
|
|
"Trade::AbstractImageConverter::exportToData(): feature not supported\n" |
|
|
|
|
"Trade::AbstractImageConverter::exportToFile(): feature not supported\n" |
|
|
|
|
"Trade::AbstractImageConverter::exportToFile(): feature not supported\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToImage() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertImage; } |
|
|
|
|
Containers::Optional<Image2D> doExportToImage(const ImageView2D& image) override { |
|
|
|
|
return Image2D{PixelFormat::RGBA8Unorm, image.size(), Containers::Array<char>{96}}; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
Containers::Optional<Image2D> actual = converter.exportToImage(ImageView2D{PixelFormat::R8Unorm, {4, 6}, Containers::ArrayView<char>{nullptr, 24}}); |
|
|
|
|
CORRADE_VERIFY(actual); |
|
|
|
|
CORRADE_COMPARE(actual->data().size(), 96); |
|
|
|
|
CORRADE_COMPARE(actual->size(), (Vector2i{4, 6})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToImageNotSupported() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return {}; } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToImage(ImageView2D{PixelFormat::R8Unorm, {4, 6}, Containers::ArrayView<char>{nullptr, 24}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToImage(): feature not supported\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToImageNotImplemented() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertImage; } |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToImage(ImageView2D{PixelFormat::R8Unorm, {4, 6}, Containers::ArrayView<char>{nullptr, 128}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToImage(): feature advertised but not implemented\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToImageCustomDeleter() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertImage; } |
|
|
|
|
Containers::Optional<Image2D> doExportToImage(const ImageView2D&) override { |
|
|
|
|
return Image2D{PixelFormat::RGBA8Unorm, {}, Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}}}; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToImage(ImageView2D{PixelFormat::R8Unorm, {}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToImage(): implementation is not allowed to use a custom Array deleter\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToCompressedImage() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedImage; } |
|
|
|
|
Containers::Optional<CompressedImage2D> doExportToCompressedImage(const ImageView2D& image) override { |
|
|
|
|
return CompressedImage2D{CompressedPixelFormat::Bc1RGBAUnorm, image.size(), Containers::Array<char>{64}}; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
Containers::Optional<CompressedImage2D> actual = converter.exportToCompressedImage(ImageView2D{PixelFormat::R8Unorm, {16, 8}, Containers::ArrayView<char>{nullptr, 128}}); |
|
|
|
|
CORRADE_VERIFY(actual); |
|
|
|
|
CORRADE_COMPARE(actual->data().size(), 64); |
|
|
|
|
CORRADE_COMPARE(actual->size(), (Vector2i{16, 8})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToCompressedImageNotSupported() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return {}; } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToCompressedImage(ImageView2D{PixelFormat::R8Unorm, {16, 8}, Containers::ArrayView<char>{nullptr, 128}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToCompressedImage(): feature not supported\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToCompressedImageNotImplemented() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedImage; } |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToCompressedImage(ImageView2D{PixelFormat::R8Unorm, {16, 8}, Containers::ArrayView<char>{nullptr, 128}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToCompressedImage(): feature advertised but not implemented\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToCompressedImageCustomDeleter() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedImage; } |
|
|
|
|
Containers::Optional<CompressedImage2D> doExportToCompressedImage(const ImageView2D&) override { |
|
|
|
|
return CompressedImage2D{CompressedPixelFormat::Bc1RGBAUnorm, {}, Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}}}; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToCompressedImage(ImageView2D{PixelFormat::R8Unorm, {}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToCompressedImage(): implementation is not allowed to use a custom Array deleter\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToData() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; } |
|
|
|
|
Containers::Array<char> doExportToData(const ImageView2D& image) override { |
|
|
|
|
return Containers::Array<char>{nullptr, std::size_t(image.size().product())}; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
Containers::Array<char> actual = converter.exportToData(ImageView2D{PixelFormat::RGBA8Unorm, {4, 6}, Containers::ArrayView<char>{nullptr, 96}}); |
|
|
|
|
CORRADE_COMPARE(actual.size(), 24); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToDataNotSupported() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return {}; } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToData(ImageView2D{PixelFormat::RGBA8Unorm, {4, 6}, Containers::ArrayView<char>{nullptr, 96}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToData(): feature not supported\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToDataNotImplemented() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; } |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToData(ImageView2D{PixelFormat::RGBA8Unorm, {4, 6}, Containers::ArrayView<char>{nullptr, 96}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToData(): feature advertised but not implemented\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToDataCustomDeleter() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; } |
|
|
|
|
Containers::Array<char> doExportToData(const ImageView2D&) override { |
|
|
|
|
return Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}}; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToData(ImageView2D{PixelFormat::RGBA8Unorm, {}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToData(): implementation is not allowed to use a custom Array deleter\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportCompressedToData() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedData; } |
|
|
|
|
Containers::Array<char> doExportToData(const CompressedImageView2D& image) override { |
|
|
|
|
return Containers::Array<char>{nullptr, std::size_t(image.size().product())}; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
Containers::Array<char> actual = converter.exportToData(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {16, 8}, Containers::ArrayView<char>{nullptr, 64}}); |
|
|
|
|
CORRADE_COMPARE(actual.size(), 128); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportCompressedToDataNotSupported() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return {}; } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToData(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {16, 8}, Containers::ArrayView<char>{nullptr, 64}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToData(): feature not supported\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportCompressedToDataNotImplemented() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; } |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToData(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {16, 8}, Containers::ArrayView<char>{nullptr, 64}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToData(): feature advertised but not implemented\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportCompressedToDataCustomDeleter() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedData; } |
|
|
|
|
Containers::Array<char> doExportToData(const CompressedImageView2D&) override { |
|
|
|
|
return Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}}; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToData(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {}}); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToData(): implementation is not allowed to use a custom Array deleter\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class ImageDataExporter: public Trade::AbstractImageConverter { |
|
|
|
|
class ImageDataConverter: public Trade::AbstractImageConverter { |
|
|
|
|
private: |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData|ImageConverterFeature::ConvertCompressedData; } |
|
|
|
|
|
|
|
|
|
Containers::Array<char> doExportToData(const ImageView2D&) override { |
|
|
|
|
/* DirectInit / InPlaceInit is unfortunately causing a custom
|
|
|
|
|
deleter right now */ |
|
|
|
|
/** @todo clean up when fixed */ |
|
|
|
|
Containers::Array<char> out{1}; |
|
|
|
|
out[0] = 'B'; |
|
|
|
|
Containers::Array<char> out{Containers::InPlaceInit, {'B'}}; |
|
|
|
|
return out; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Containers::Array<char> doExportToData(const CompressedImageView2D&) override { |
|
|
|
|
/* DirectInit / InPlaceInit is unfortunately causing a custom
|
|
|
|
|
deleter right now */ |
|
|
|
|
/** @todo clean up when fixed */ |
|
|
|
|
Containers::Array<char> out{1}; |
|
|
|
|
out[0] = 'C'; |
|
|
|
|
Containers::Array<char> out{Containers::InPlaceInit, {'C'}}; |
|
|
|
|
return out; |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportImageDataToData() { |
|
|
|
|
ImageDataExporter exporter; |
|
|
|
|
ImageDataConverter converter; |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
/* Should get "B" when converting uncompressed */ |
|
|
|
|
ImageData2D image{PixelFormat::RGBA8Unorm, {}, nullptr}; |
|
|
|
|
CORRADE_COMPARE_AS(exporter.exportToData(image), |
|
|
|
|
CORRADE_COMPARE_AS(converter.exportToData(image), |
|
|
|
|
(Containers::Array<char>{Containers::InPlaceInit, {'B'}}), |
|
|
|
|
TestSuite::Compare::Container); |
|
|
|
|
} { |
|
|
|
|
/* Should get "C" when converting compressed */ |
|
|
|
|
ImageData2D image{CompressedPixelFormat::Bc1RGBUnorm, {}, nullptr}; |
|
|
|
|
CORRADE_COMPARE_AS(exporter.exportToData(image), |
|
|
|
|
CORRADE_COMPARE_AS(converter.exportToData(image), |
|
|
|
|
(Containers::Array<char>{Containers::InPlaceInit, {'C'}}), |
|
|
|
|
TestSuite::Compare::Container); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToFile() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; } |
|
|
|
|
bool doExportToFile(const ImageView2D& image, const std::string& filename) override { |
|
|
|
|
return Utility::Directory::write(filename, Containers::Array<char>{Containers::InPlaceInit, |
|
|
|
|
{char(image.size().x()), char(image.size().y())}}); |
|
|
|
|
return Utility::Directory::write(filename, Containers::arrayView( |
|
|
|
|
{char(image.size().x()), char(image.size().y())})); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
/* Remove previous file */ |
|
|
|
|
Utility::Directory::rm(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")); |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
CORRADE_VERIFY(converter.exportToFile(ImageView2D{PixelFormat::RGBA8Unorm, {0xf0, 0x0d}, {nullptr, 0xf0*0x0d*4}}, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"))); |
|
|
|
|
CORRADE_COMPARE_AS(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"), |
|
|
|
|
"\xf0\x0d", TestSuite::Compare::FileToString); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToFileThroughData() { |
|
|
|
|
class DataExporter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; } |
|
|
|
|
|
|
|
|
|
Containers::Array<char> doExportToData(const ImageView2D& image) override { |
|
|
|
|
return Containers::Array<char>{Containers::InPlaceInit, |
|
|
|
|
{char(image.size().x()), char(image.size().y())}}; |
|
|
|
|
return Containers::array({char(image.size().x()), char(image.size().y())}); |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
/* Remove previous file */ |
|
|
|
|
Utility::Directory::rm(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")); |
|
|
|
|
|
|
|
|
|
/* doExportToFile() should call doExportToData() */ |
|
|
|
|
DataExporter exporter; |
|
|
|
|
ImageView2D image(PixelFormat::RGBA8Unorm, {0xfe, 0xed}, {nullptr, 0xfe*0xed*4}); |
|
|
|
|
CORRADE_VERIFY(exporter.exportToFile(image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"))); |
|
|
|
|
CORRADE_VERIFY(converter.exportToFile(image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"))); |
|
|
|
|
CORRADE_COMPARE_AS(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"), |
|
|
|
|
"\xfe\xed", TestSuite::Compare::FileToString); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToFileThroughDataNotWritable() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; } |
|
|
|
|
|
|
|
|
|
Containers::Array<char> doExportToData(const ImageView2D& image) override { |
|
|
|
|
return Containers::Array<char>{Containers::InPlaceInit, |
|
|
|
|
{char(image.size().x()), char(image.size().y())}}; |
|
|
|
|
return Containers::array({char(image.size().x()), char(image.size().y())}); |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToFile(ImageView2D{PixelFormat::RGBA8Unorm, {0xfe, 0xed}, {nullptr, 0xfe*0xed*4}}, "/some/path/that/does/not/exist"); |
|
|
|
|
CORRADE_VERIFY(!converter.exportToFile(ImageView2D{PixelFormat::RGBA8Unorm, {0xfe, 0xed}, {nullptr, 0xfe*0xed*4}}, "/some/path/that/does/not/exist")); |
|
|
|
|
CORRADE_COMPARE(out.str(), |
|
|
|
|
"Utility::Directory::write(): can't open /some/path/that/does/not/exist\n" |
|
|
|
|
"Trade::AbstractImageConverter::exportToFile(): cannot write to file /some/path/that/does/not/exist\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToFileNotSupported() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return {}; } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToFile(ImageView2D{PixelFormat::RGBA8Unorm, {4, 6}, {nullptr, 96}}, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToFile(): feature not supported\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportToFileNotImplemented() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertFile; } |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToFile(ImageView2D{PixelFormat::RGBA8Unorm, {4, 6}, {nullptr, 96}}, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToFile(): feature advertised but not implemented\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportCompressedToFile() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedFile; } |
|
|
|
|
bool doExportToFile(const CompressedImageView2D& image, const std::string& filename) override { |
|
|
|
|
return Utility::Directory::write(filename, Containers::Array<char>{Containers::InPlaceInit, |
|
|
|
|
{char(image.size().x()), char(image.size().y())}}); |
|
|
|
|
return Utility::Directory::write(filename, Containers::arrayView( |
|
|
|
|
{char(image.size().x()), char(image.size().y())})); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
CORRADE_VERIFY(converter.exportToFile(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {0xd0, 0x0d}, {nullptr, 64}}, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"))); |
|
|
|
|
CORRADE_COMPARE_AS(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"), |
|
|
|
|
"\xd0\x0d", TestSuite::Compare::FileToString); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportCompressedToFileThroughData() { |
|
|
|
|
class DataExporter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedData; } |
|
|
|
|
|
|
|
|
|
Containers::Array<char> doExportToData(const CompressedImageView2D& image) override { |
|
|
|
|
return Containers::Array<char>{Containers::InPlaceInit, |
|
|
|
|
{char(image.size().x()), char(image.size().y())}}; |
|
|
|
|
return Containers::array({char(image.size().x()), char(image.size().y())}); |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
/* Remove previous file */ |
|
|
|
|
Utility::Directory::rm(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")); |
|
|
|
|
|
|
|
|
|
/* doExportToFile() should call doExportToData() */ |
|
|
|
|
DataExporter exporter; |
|
|
|
|
CORRADE_VERIFY(exporter.exportToFile(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {0xb0, 0xd9}, {nullptr, 64}}, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"))); |
|
|
|
|
CORRADE_VERIFY(converter.exportToFile(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {0xb0, 0xd9}, {nullptr, 64}}, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"))); |
|
|
|
|
CORRADE_COMPARE_AS(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"), |
|
|
|
|
"\xb0\xd9", TestSuite::Compare::FileToString); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportCompressedToFileThroughDataNotWritable() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedData; } |
|
|
|
|
|
|
|
|
|
Containers::Array<char> doExportToData(const CompressedImageView2D& image) override { |
|
|
|
|
return Containers::Array<char>{Containers::InPlaceInit, |
|
|
|
|
{char(image.size().x()), char(image.size().y())}}; |
|
|
|
|
return Containers::array({char(image.size().x()), char(image.size().y())}); |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToFile(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {16, 8}, {nullptr, 64}}, "/some/path/that/does/not/exist"); |
|
|
|
|
CORRADE_COMPARE(out.str(), |
|
|
|
|
"Utility::Directory::write(): can't open /some/path/that/does/not/exist\n" |
|
|
|
|
"Trade::AbstractImageConverter::exportToFile(): cannot write to file /some/path/that/does/not/exist\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportCompressedToFileNotSupported() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return {}; } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToFile(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {16, 8}, {nullptr, 64}}, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToFile(): feature not supported\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportCompressedToFileNotImplemented() { |
|
|
|
|
class Converter: public AbstractImageConverter { |
|
|
|
|
struct: AbstractImageConverter { |
|
|
|
|
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedFile; } |
|
|
|
|
}; |
|
|
|
|
} converter; |
|
|
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
Converter converter; |
|
|
|
|
converter.exportToFile(CompressedImageView2D{CompressedPixelFormat::Bc1RGBAUnorm, {16, 8}, {nullptr, 64}}, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")); |
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::exportToFile(): feature advertised but not implemented\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AbstractImageConverterTest::exportImageDataToFile() { |
|
|
|
|
ImageDataExporter exporter; |
|
|
|
|
ImageDataConverter converter; |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
/* Should get "B" when converting uncompressed */ |
|
|
|
|
ImageData2D image{PixelFormat::RGBA16F, {}, nullptr}; |
|
|
|
|
CORRADE_VERIFY(exporter.exportToFile(image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"))); |
|
|
|
|
CORRADE_VERIFY(converter.exportToFile(image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"))); |
|
|
|
|
CORRADE_COMPARE_AS(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"), |
|
|
|
|
"B", TestSuite::Compare::FileToString); |
|
|
|
|
} { |
|
|
|
|
/* Should get "C" when converting compressed */ |
|
|
|
|
ImageData2D image{CompressedPixelFormat::Bc2RGBAUnorm, {}, nullptr}; |
|
|
|
|
CORRADE_VERIFY(exporter.exportToFile(image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"))); |
|
|
|
|
CORRADE_VERIFY(converter.exportToFile(image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"))); |
|
|
|
|
CORRADE_COMPARE_AS(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"), |
|
|
|
|
"C", TestSuite::Compare::FileToString); |
|
|
|
|
} |
|
|
|
|
|