Browse Source

Text: check for presence of custom deleters.

To match existing requirements in all other plugins.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
5f59a1bbec
  1. 28
      src/Magnum/Text/AbstractFontConverter.cpp
  2. 90
      src/Magnum/Text/Test/AbstractFontConverterTest.cpp

28
src/Magnum/Text/AbstractFontConverter.cpp

@ -104,7 +104,14 @@ std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConvert
CORRADE_ASSERT(features() >= (FontConverterFeature::ExportFont|FontConverterFeature::ConvertData), CORRADE_ASSERT(features() >= (FontConverterFeature::ExportFont|FontConverterFeature::ConvertData),
"Text::AbstractFontConverter::exportFontToData(): feature not supported", {}); "Text::AbstractFontConverter::exportFontToData(): feature not supported", {});
return doExportFontToData(font, cache, filename, uniqueUnicode(characters)); std::vector<std::pair<std::string, Containers::Array<char>>> out = doExportFontToData(font, cache, filename, uniqueUnicode(characters));
#ifndef CORRADE_NO_ASSERT
for(const auto& i: out)
CORRADE_ASSERT(!i.second.deleter(),
"Text::AbstractFontConverter::exportFontToData(): implementation is not allowed to use a custom Array deleter", {});
#endif
return out;
} }
std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::doExportFontToData(AbstractFont& font, AbstractGlyphCache& cache, const std::string& filename, const std::u32string& characters) const { std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::doExportFontToData(AbstractFont& font, AbstractGlyphCache& cache, const std::string& filename, const std::u32string& characters) const {
@ -123,7 +130,10 @@ Containers::Array<char> AbstractFontConverter::exportFontToSingleData(AbstractFo
CORRADE_ASSERT(!(features() & FontConverterFeature::MultiFile), CORRADE_ASSERT(!(features() & FontConverterFeature::MultiFile),
"Text::AbstractFontConverter::exportFontToSingleData(): the format is not single-file", nullptr); "Text::AbstractFontConverter::exportFontToSingleData(): the format is not single-file", nullptr);
return doExportFontToSingleData(font, cache, uniqueUnicode(characters)); Containers::Array<char> out = doExportFontToSingleData(font, cache, uniqueUnicode(characters));
CORRADE_ASSERT(!out.deleter(),
"Text::AbstractFontConverter::exportFontToSingleData(): implementation is not allowed to use a custom Array deleter", {});
return out;
} }
Containers::Array<char> AbstractFontConverter::doExportFontToSingleData(AbstractFont&, AbstractGlyphCache&, const std::u32string&) const { Containers::Array<char> AbstractFontConverter::doExportFontToSingleData(AbstractFont&, AbstractGlyphCache&, const std::u32string&) const {
@ -157,7 +167,14 @@ std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConvert
CORRADE_ASSERT(features() >= (FontConverterFeature::ExportGlyphCache|FontConverterFeature::ConvertData), CORRADE_ASSERT(features() >= (FontConverterFeature::ExportGlyphCache|FontConverterFeature::ConvertData),
"Text::AbstractFontConverter::exportGlyphCacheToData(): feature not supported", {}); "Text::AbstractFontConverter::exportGlyphCacheToData(): feature not supported", {});
return doExportGlyphCacheToData(cache, filename); std::vector<std::pair<std::string, Containers::Array<char>>> out = doExportGlyphCacheToData(cache, filename);
#ifndef CORRADE_NO_ASSERT
for(const auto& i: out)
CORRADE_ASSERT(!i.second.deleter(),
"Text::AbstractFontConverter::exportGlyphCacheToData(): implementation is not allowed to use a custom Array deleter", {});
#endif
return out;
} }
std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::doExportGlyphCacheToData(AbstractGlyphCache& cache, const std::string& filename) const { std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::doExportGlyphCacheToData(AbstractGlyphCache& cache, const std::string& filename) const {
@ -176,7 +193,10 @@ Containers::Array<char> AbstractFontConverter::exportGlyphCacheToSingleData(Abst
CORRADE_ASSERT(!(features() & FontConverterFeature::MultiFile), CORRADE_ASSERT(!(features() & FontConverterFeature::MultiFile),
"Text::AbstractFontConverter::exportGlyphCacheToSingleData(): the format is not single-file", nullptr); "Text::AbstractFontConverter::exportGlyphCacheToSingleData(): the format is not single-file", nullptr);
return doExportGlyphCacheToSingleData(cache); Containers::Array<char> out = doExportGlyphCacheToSingleData(cache);
CORRADE_ASSERT(!out.deleter(),
"Text::AbstractFontConverter::exportGlyphCacheToSingleData(): implementation is not allowed to use a custom Array deleter", {});
return out;
} }
Containers::Array<char> AbstractFontConverter::doExportGlyphCacheToSingleData(AbstractGlyphCache&) const { Containers::Array<char> AbstractFontConverter::doExportGlyphCacheToSingleData(AbstractGlyphCache&) const {

90
src/Magnum/Text/Test/AbstractFontConverterTest.cpp

@ -51,9 +51,11 @@ struct AbstractFontConverterTest: TestSuite::Tester {
void exportFontToSingleData(); void exportFontToSingleData();
void exportFontToSingleDataNotImplemented(); void exportFontToSingleDataNotImplemented();
void exportFontToSingleDataCustomDeleter();
void exportFontToSingleDataNotSingleFile(); void exportFontToSingleDataNotSingleFile();
void exportFontToData(); void exportFontToData();
void exportFontToDataNotImplemented(); void exportFontToDataNotImplemented();
void exportFontToDataCustomDeleter();
void exportFontToDataThroughSingleData(); void exportFontToDataThroughSingleData();
void exportFontToDataThroughSingleDataFailed(); void exportFontToDataThroughSingleDataFailed();
void exportFontToFile(); void exportFontToFile();
@ -64,9 +66,11 @@ struct AbstractFontConverterTest: TestSuite::Tester {
void exportGlyphCacheToSingleData(); void exportGlyphCacheToSingleData();
void exportGlyphCacheToSingleDataNotImplemented(); void exportGlyphCacheToSingleDataNotImplemented();
void exportGlyphCacheToSingleDataCustomDeleter();
void exportGlyphCacheToSingleDataNotSingleFile(); void exportGlyphCacheToSingleDataNotSingleFile();
void exportGlyphCacheToData(); void exportGlyphCacheToData();
void exportGlyphCacheToDataNotImplemented(); void exportGlyphCacheToDataNotImplemented();
void exportGlyphCacheToDataCustomDeleter();
void exportGlyphCacheToDataThroughSingleData(); void exportGlyphCacheToDataThroughSingleData();
void exportGlyphCacheToDataThroughSingleDataFailed(); void exportGlyphCacheToDataThroughSingleDataFailed();
void exportGlyphCacheToFile(); void exportGlyphCacheToFile();
@ -100,9 +104,11 @@ AbstractFontConverterTest::AbstractFontConverterTest() {
&AbstractFontConverterTest::exportFontToSingleData, &AbstractFontConverterTest::exportFontToSingleData,
&AbstractFontConverterTest::exportFontToSingleDataNotImplemented, &AbstractFontConverterTest::exportFontToSingleDataNotImplemented,
&AbstractFontConverterTest::exportFontToSingleDataCustomDeleter,
&AbstractFontConverterTest::exportFontToSingleDataNotSingleFile, &AbstractFontConverterTest::exportFontToSingleDataNotSingleFile,
&AbstractFontConverterTest::exportFontToData, &AbstractFontConverterTest::exportFontToData,
&AbstractFontConverterTest::exportFontToDataNotImplemented, &AbstractFontConverterTest::exportFontToDataNotImplemented,
&AbstractFontConverterTest::exportFontToDataCustomDeleter,
&AbstractFontConverterTest::exportFontToDataThroughSingleData, &AbstractFontConverterTest::exportFontToDataThroughSingleData,
&AbstractFontConverterTest::exportFontToDataThroughSingleDataFailed, &AbstractFontConverterTest::exportFontToDataThroughSingleDataFailed,
&AbstractFontConverterTest::exportFontToFile, &AbstractFontConverterTest::exportFontToFile,
@ -113,9 +119,11 @@ AbstractFontConverterTest::AbstractFontConverterTest() {
&AbstractFontConverterTest::exportGlyphCacheToSingleData, &AbstractFontConverterTest::exportGlyphCacheToSingleData,
&AbstractFontConverterTest::exportGlyphCacheToSingleDataNotImplemented, &AbstractFontConverterTest::exportGlyphCacheToSingleDataNotImplemented,
&AbstractFontConverterTest::exportGlyphCacheToSingleDataCustomDeleter,
&AbstractFontConverterTest::exportGlyphCacheToSingleDataNotSingleFile, &AbstractFontConverterTest::exportGlyphCacheToSingleDataNotSingleFile,
&AbstractFontConverterTest::exportGlyphCacheToData, &AbstractFontConverterTest::exportGlyphCacheToData,
&AbstractFontConverterTest::exportGlyphCacheToDataNotImplemented, &AbstractFontConverterTest::exportGlyphCacheToDataNotImplemented,
&AbstractFontConverterTest::exportGlyphCacheToDataCustomDeleter,
&AbstractFontConverterTest::exportGlyphCacheToDataThroughSingleData, &AbstractFontConverterTest::exportGlyphCacheToDataThroughSingleData,
&AbstractFontConverterTest::exportGlyphCacheToDataThroughSingleDataFailed, &AbstractFontConverterTest::exportGlyphCacheToDataThroughSingleDataFailed,
&AbstractFontConverterTest::exportGlyphCacheToFile, &AbstractFontConverterTest::exportGlyphCacheToFile,
@ -248,6 +256,25 @@ void AbstractFontConverterTest::exportFontToSingleDataNotImplemented() {
CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportFontToSingleData(): feature advertised but not implemented\n"); CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportFontToSingleData(): feature advertised but not implemented\n");
} }
void AbstractFontConverterTest::exportFontToSingleDataCustomDeleter() {
CORRADE_SKIP_IF_NO_ASSERT();
struct: AbstractFontConverter {
FontConverterFeatures doFeatures() const override {
return FontConverterFeature::ConvertData|FontConverterFeature::ExportFont;
}
Containers::Array<char> doExportFontToSingleData(AbstractFont&, AbstractGlyphCache&, const std::u32string&) const override {
return Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}};
}
} converter;
std::ostringstream out;
Error redirectError{&out};
converter.exportFontToSingleData(dummyFont, dummyGlyphCache, {});
CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportFontToSingleData(): implementation is not allowed to use a custom Array deleter\n");
}
void AbstractFontConverterTest::exportFontToSingleDataNotSingleFile() { void AbstractFontConverterTest::exportFontToSingleDataNotSingleFile() {
CORRADE_SKIP_IF_NO_ASSERT(); CORRADE_SKIP_IF_NO_ASSERT();
@ -307,6 +334,28 @@ void AbstractFontConverterTest::exportFontToDataNotImplemented() {
CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportFontToData(): feature advertised but not implemented\n"); CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportFontToData(): feature advertised but not implemented\n");
} }
void AbstractFontConverterTest::exportFontToDataCustomDeleter() {
CORRADE_SKIP_IF_NO_ASSERT();
struct: AbstractFontConverter {
FontConverterFeatures doFeatures() const override {
return FontConverterFeature::ConvertData|FontConverterFeature::ExportFont;
}
std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont&, AbstractGlyphCache&, const std::string&, const std::u32string&) const override {
/* First is alright, second not */
std::vector<std::pair<std::string, Containers::Array<char>>> out;
out.emplace_back("", nullptr);
out.emplace_back("", Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}});
return out;
}
} converter;
std::ostringstream out;
Error redirectError{&out};
converter.exportFontToData(dummyFont, dummyGlyphCache, "font.out", {});
CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportFontToData(): implementation is not allowed to use a custom Array deleter\n");
}
void AbstractFontConverterTest::exportFontToDataThroughSingleData() { void AbstractFontConverterTest::exportFontToDataThroughSingleData() {
struct: AbstractFontConverter { struct: AbstractFontConverter {
FontConverterFeatures doFeatures() const override { FontConverterFeatures doFeatures() const override {
@ -493,6 +542,25 @@ void AbstractFontConverterTest::exportGlyphCacheToSingleDataNotImplemented() {
CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportGlyphCacheToSingleData(): feature advertised but not implemented\n"); CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportGlyphCacheToSingleData(): feature advertised but not implemented\n");
} }
void AbstractFontConverterTest::exportGlyphCacheToSingleDataCustomDeleter() {
CORRADE_SKIP_IF_NO_ASSERT();
struct: AbstractFontConverter {
FontConverterFeatures doFeatures() const override {
return FontConverterFeature::ConvertData|FontConverterFeature::ExportGlyphCache;
}
Containers::Array<char> doExportGlyphCacheToSingleData(AbstractGlyphCache&) const override {
return Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}};
}
} converter;
std::ostringstream out;
Error redirectError{&out};
converter.exportGlyphCacheToSingleData(dummyGlyphCache);
CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportGlyphCacheToSingleData(): implementation is not allowed to use a custom Array deleter\n");
}
void AbstractFontConverterTest::exportGlyphCacheToSingleDataNotSingleFile() { void AbstractFontConverterTest::exportGlyphCacheToSingleDataNotSingleFile() {
CORRADE_SKIP_IF_NO_ASSERT(); CORRADE_SKIP_IF_NO_ASSERT();
@ -551,6 +619,28 @@ void AbstractFontConverterTest::exportGlyphCacheToDataNotImplemented() {
CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportGlyphCacheToData(): feature advertised but not implemented\n"); CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportGlyphCacheToData(): feature advertised but not implemented\n");
} }
void AbstractFontConverterTest::exportGlyphCacheToDataCustomDeleter() {
CORRADE_SKIP_IF_NO_ASSERT();
struct: AbstractFontConverter {
FontConverterFeatures doFeatures() const override {
return FontConverterFeature::ConvertData|FontConverterFeature::ExportGlyphCache;
}
std::vector<std::pair<std::string, Containers::Array<char>>> doExportGlyphCacheToData(AbstractGlyphCache&, const std::string&) const override {
/* First is alright, second not */
std::vector<std::pair<std::string, Containers::Array<char>>> out;
out.emplace_back("", nullptr);
out.emplace_back("", Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}});
return out;
}
} converter;
std::ostringstream out;
Error redirectError{&out};
converter.exportGlyphCacheToData(dummyGlyphCache, "cache.out");
CORRADE_COMPARE(out.str(), "Text::AbstractFontConverter::exportGlyphCacheToData(): implementation is not allowed to use a custom Array deleter\n");
}
void AbstractFontConverterTest::exportGlyphCacheToDataThroughSingleData() { void AbstractFontConverterTest::exportGlyphCacheToDataThroughSingleData() {
struct: AbstractFontConverter { struct: AbstractFontConverter {
FontConverterFeatures doFeatures() const override { FontConverterFeatures doFeatures() const override {

Loading…
Cancel
Save