Browse Source

Trade: allow retrieving importer data directly by name.

pull/371/head
Vladimír Vondruš 6 years ago
parent
commit
a02e9465d6
  1. 2
      doc/changelog.dox
  2. 87
      src/Magnum/Trade/AbstractImporter.cpp
  3. 168
      src/Magnum/Trade/AbstractImporter.h
  4. 316
      src/Magnum/Trade/Test/AbstractImporterTest.cpp

2
doc/changelog.dox

@ -185,6 +185,8 @@ See also:
Equivalent APIs are exposed in both @ref Trade::ImageData and
@ref Trade::MeshData as well. See @ref Trade-AnimationData-usage-mutable
for more information.
- New convenience @ref Trade::AbstractImporter::material(const std::string&)
etc. APIs allowing to directly get a data using a string name
@subsubsection changelog-latest-new-vk Vk library

87
src/Magnum/Trade/AbstractImporter.cpp

@ -248,6 +248,13 @@ Containers::Optional<SceneData> AbstractImporter::doScene(UnsignedInt) {
CORRADE_ASSERT(false, "Trade::AbstractImporter::scene(): not implemented", {});
}
Containers::Optional<SceneData> AbstractImporter::scene(const std::string& name) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::scene(): no file opened", {});
const Int id = doSceneForName(name);
if(id == -1) return {};
return scene(id); /* not doScene(), so we get the range checks also */
}
UnsignedInt AbstractImporter::animationCount() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::animationCount(): no file opened", {});
return doAnimationCount();
@ -285,6 +292,13 @@ Containers::Optional<AnimationData> AbstractImporter::doAnimation(UnsignedInt) {
CORRADE_ASSERT(false, "Trade::AbstractImporter::animation(): not implemented", {});
}
Containers::Optional<AnimationData> AbstractImporter::animation(const std::string& name) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::animation(): no file opened", {});
const Int id = doAnimationForName(name);
if(id == -1) return {};
return animation(id); /* not doAnimation(), so we get the checks also */
}
UnsignedInt AbstractImporter::lightCount() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::lightCount(): no file opened", {});
return doLightCount();
@ -317,6 +331,13 @@ Containers::Optional<LightData> AbstractImporter::doLight(UnsignedInt) {
CORRADE_ASSERT(false, "Trade::AbstractImporter::light(): not implemented", {});
}
Containers::Optional<LightData> AbstractImporter::light(const std::string& name) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::light(): no file opened", {});
const Int id = doLightForName(name);
if(id == -1) return {};
return light(id); /* not doLight(), so we get the range checks also */
}
UnsignedInt AbstractImporter::cameraCount() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::cameraCount(): no file opened", {});
return doCameraCount();
@ -349,6 +370,13 @@ Containers::Optional<CameraData> AbstractImporter::doCamera(UnsignedInt) {
CORRADE_ASSERT(false, "Trade::AbstractImporter::camera(): not implemented", {});
}
Containers::Optional<CameraData> AbstractImporter::camera(const std::string& name) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::camera(): no file opened", {});
const Int id = doCameraForName(name);
if(id == -1) return {};
return camera(id); /* not doCamera(), so we get the range checks also */
}
UnsignedInt AbstractImporter::object2DCount() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::object2DCount(): no file opened", {});
return doObject2DCount();
@ -381,6 +409,13 @@ Containers::Pointer<ObjectData2D> AbstractImporter::doObject2D(UnsignedInt) {
CORRADE_ASSERT(false, "Trade::AbstractImporter::object2D(): not implemented", {});
}
Containers::Pointer<ObjectData2D> AbstractImporter::object2D(const std::string& name) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::object2D(): no file opened", {});
const Int id = doObject2DForName(name);
if(id == -1) return {};
return object2D(id); /* not doObject2D(), so we get the range checks also */
}
UnsignedInt AbstractImporter::object3DCount() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::object3DCount(): no file opened", {});
return doObject3DCount();
@ -413,6 +448,13 @@ Containers::Pointer<ObjectData3D> AbstractImporter::doObject3D(UnsignedInt) {
CORRADE_ASSERT(false, "Trade::AbstractImporter::object3D(): not implemented", {});
}
Containers::Pointer<ObjectData3D> AbstractImporter::object3D(const std::string& name) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::object3D(): no file opened", {});
const Int id = doObject3DForName(name);
if(id == -1) return {};
return object3D(id); /* not doObject3D(), so we get the range checks also */
}
UnsignedInt AbstractImporter::meshCount() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::meshCount(): no file opened", {});
return doMeshCount();
@ -451,6 +493,13 @@ Containers::Optional<MeshData> AbstractImporter::doMesh(UnsignedInt) {
CORRADE_ASSERT(false, "Trade::AbstractImporter::mesh(): not implemented", {});
}
Containers::Optional<MeshData> AbstractImporter::mesh(const std::string& name) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::mesh(): no file opened", {});
const Int id = doMeshForName(name);
if(id == -1) return {};
return mesh(id); /* not doMesh(), so we get the checks also */
}
MeshAttribute AbstractImporter::meshAttributeForName(const std::string& name) {
const MeshAttribute out = doMeshAttributeForName(name);
CORRADE_ASSERT(out == MeshAttribute{} || isMeshAttributeCustom(out),
@ -592,6 +641,13 @@ Containers::Pointer<AbstractMaterialData> AbstractImporter::doMaterial(UnsignedI
CORRADE_ASSERT(false, "Trade::AbstractImporter::material(): not implemented", {});
}
Containers::Pointer<AbstractMaterialData> AbstractImporter::material(const std::string& name) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::material(): no file opened", {});
const Int id = doMaterialForName(name);
if(id == -1) return {};
return material(id); /* not doMaterial(), so we get the range checks also */
}
UnsignedInt AbstractImporter::textureCount() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::textureCount(): no file opened", {});
return doTextureCount();
@ -624,6 +680,13 @@ Containers::Optional<TextureData> AbstractImporter::doTexture(UnsignedInt) {
CORRADE_ASSERT(false, "Trade::AbstractImporter::texture(): not implemented", {});
}
Containers::Optional<TextureData> AbstractImporter::texture(const std::string& name) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::texture(): no file opened", {});
const Int id = doTextureForName(name);
if(id == -1) return {};
return texture(id); /* not doTexture(), so we get the range checks also */
}
UnsignedInt AbstractImporter::image1DCount() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::image1DCount(): no file opened", {});
return doImage1DCount();
@ -680,6 +743,14 @@ Containers::Optional<ImageData1D> AbstractImporter::doImage1D(UnsignedInt, Unsig
CORRADE_ASSERT(false, "Trade::AbstractImporter::image1D(): not implemented", {});
}
Containers::Optional<ImageData1D> AbstractImporter::image1D(const std::string& name, const UnsignedInt level) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::image1D(): no file opened", {});
const Int id = doImage1DForName(name);
if(id == -1) return {};
/* not doImage1D(), so we get the range checks also */
return image1D(id, level);
}
UnsignedInt AbstractImporter::image2DCount() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::image2DCount(): no file opened", {});
return doImage2DCount();
@ -736,6 +807,14 @@ Containers::Optional<ImageData2D> AbstractImporter::doImage2D(UnsignedInt, Unsig
CORRADE_ASSERT(false, "Trade::AbstractImporter::image2D(): not implemented", {});
}
Containers::Optional<ImageData2D> AbstractImporter::image2D(const std::string& name, const UnsignedInt level) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::image2D(): no file opened", {});
const Int id = doImage2DForName(name);
if(id == -1) return {};
/* not doImage2D(), so we get the range checks also */
return image2D(id, level);
}
UnsignedInt AbstractImporter::image3DCount() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::image3DCount(): no file opened", {});
return doImage3DCount();
@ -792,6 +871,14 @@ Containers::Optional<ImageData3D> AbstractImporter::doImage3D(UnsignedInt, Unsig
CORRADE_ASSERT(false, "Trade::AbstractImporter::image3D(): not implemented", {});
}
Containers::Optional<ImageData3D> AbstractImporter::image3D(const std::string& name, const UnsignedInt level) {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::image3D(): no file opened", {});
const Int id = doImage3DForName(name);
if(id == -1) return {};
/* not doImage3D(), so we get the range checks also */
return image3D(id, level);
}
const void* AbstractImporter::importerState() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::importerState(): no file opened", {});
return doImporterState();

168
src/Magnum/Trade/AbstractImporter.h

@ -491,7 +491,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* If no scene for given name exists, returns @cpp -1 @ce. Expects that
* a file is opened.
* @see @ref sceneName()
* @see @ref sceneName(), @ref scene(const std::string&)
*/
Int sceneForName(const std::string& name);
@ -510,9 +510,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given scene or @ref Containers::NullOpt if import failed.
* Expects that a file is opened.
* @see @ref scene(const std::string&)
*/
Containers::Optional<SceneData> scene(UnsignedInt id);
/**
* @brief Scene for given name
* @m_since_latest
*
* A convenience API combining @ref sceneForName() and
* @ref scene(UnsignedInt). Returns @ref Containers::NullOpt either
* if @ref sceneForName() returns @cpp -1 @ce or if importing fails.
* Expects that a file is opened.
*/
Containers::Optional<SceneData> scene(const std::string& name);
/**
* @brief Animation count
*
@ -525,7 +537,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* If no animation for given name exists, returns @cpp -1 @ce. Expects
* that a file is opened.
* @see @ref animationName()
* @see @ref animationName(), @ref animation(const std::string&)
*/
Int animationForName(const std::string& name);
@ -544,9 +556,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given animation or @ref Containers::NullOpt if importing
* failed. Expects that a file is opened.
* @see @ref animation(const std::string&)
*/
Containers::Optional<AnimationData> animation(UnsignedInt id);
/**
* @brief Animation for given name
* @m_since_latest
*
* A convenience API combining @ref animationForName() and
* @ref animation(UnsignedInt). Returns @ref Containers::NullOpt either
* if @ref animationForName() returns @cpp -1 @ce or if importing
* fails. Expects that a file is opened.
*/
Containers::Optional<AnimationData> animation(const std::string& name);
/**
* @brief Light count
*
@ -559,7 +583,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* If no light for given name exists, returns @cpp -1 @ce. Expects that
* a file is opened.
* @see @ref lightName()
* @see @ref lightName(), @ref light(const std::string&)
*/
Int lightForName(const std::string& name);
@ -578,9 +602,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given light or @ref Containers::NullOpt if importing failed.
* Expects that a file is opened.
* @see @ref light(const std::string&)
*/
Containers::Optional<LightData> light(UnsignedInt id);
/**
* @brief Light for given name
* @m_since_latest
*
* A convenience API combining @ref lightForName() and
* @ref light(UnsignedInt). Returns @ref Containers::NullOpt either if
* @ref lightForName() returns @cpp -1 @ce or if importing fails.
* Expects that a file is opened.
*/
Containers::Optional<LightData> light(const std::string& name);
/**
* @brief Camera count
*
@ -593,7 +629,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* If no camera for given name exists, returns @cpp -1 @ce. Expects
* that a file is opened.
* @see @ref cameraName()
* @see @ref cameraName(), @ref camera(const std::string&)
*/
Int cameraForName(const std::string& name);
@ -612,9 +648,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given camera or @ref Containers::NullOpt if importing
* failed. Expects that a file is opened.
* @see @ref camera(const std::string&)
*/
Containers::Optional<CameraData> camera(UnsignedInt id);
/**
* @brief Camera for given name
* @m_since_latest
*
* A convenience API combining @ref cameraForName() and
* @ref camera(UnsignedInt). Returns @ref Containers::NullOpt either if
* @ref cameraForName() returns @cpp -1 @ce or if importing fails.
* Expects that a file is opened.
*/
Containers::Optional<CameraData> camera(const std::string& name);
/**
* @brief Two-dimensional object count
*
@ -627,7 +675,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* If no scene for given name exists, returns @cpp -1 @ce. Expects that
* a file is opened.
* @see @ref object2DName()
* @see @ref object2DName(), @ref object2D(const std::string&)
*/
Int object2DForName(const std::string& name);
@ -646,9 +694,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given object or @cpp nullptr @ce if importing failed.
* Expects that a file is opened.
* @see @ref object2D(const std::string&)
*/
Containers::Pointer<ObjectData2D> object2D(UnsignedInt id);
/**
* @brief Two-dimensional object for given name
* @m_since_latest
*
* A convenience API combining @ref object2DForName() and
* @ref object2D(UnsignedInt). Returns @cpp nullptr @ce either if
* @ref object2DForName() returns @cpp -1 @ce or if importing fails.
* Expects that a file is opened.
*/
Containers::Pointer<ObjectData2D> object2D(const std::string& name);
/**
* @brief Three-dimensional object count
*
@ -661,7 +721,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* If no scene for given name exists, returns @cpp -1 @ce. Expects that
* a file is opened.
* @see @ref object3DName()
* @see @ref object3DName(), @ref object3D(const std::string&)
*/
Int object3DForName(const std::string& name);
@ -680,9 +740,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given object or @cpp nullptr @ce if importing failed.
* Expects that a file is opened.
* @see @ref object3D(const std::string&)
*/
Containers::Pointer<ObjectData3D> object3D(UnsignedInt id);
/**
* @brief Three-dimensional object for given name
* @m_since_latest
*
* A convenience API combining @ref object3DForName() and
* @ref object3D(UnsignedInt). Returns @cpp nullptr @ce either if
* @ref object3DForName() returns @cpp -1 @ce or if importing fails.
* Expects that a file is opened.
*/
Containers::Pointer<ObjectData3D> object3D(const std::string& name);
/**
* @brief Mesh count
* @m_since_latest
@ -697,7 +769,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* If no mesh for given name exists, returns @cpp -1 @ce. Expects that
* a file is opened.
* @see @ref meshName()
* @see @ref meshName(), @ref mesh(const std::string&)
*/
Int meshForName(const std::string& name);
@ -718,9 +790,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given mesh or @ref Containers::NullOpt if importing failed.
* Expects that a file is opened.
* @see @ref mesh(const std::string&)
*/
Containers::Optional<MeshData> mesh(UnsignedInt id);
/**
* @brief Mesh for given name
* @m_since_latest
*
* A convenience API combining @ref meshForName() and
* @ref mesh(UnsignedInt). Returns @ref Containers::NullOpt either if
* @ref meshForName() returns @cpp -1 @ce or if importing fails.
* Expects that a file is opened.
*/
Containers::Optional<MeshData> mesh(const std::string& name);
/**
* @brief Mesh attribute for given name
* @m_since_latest
@ -852,7 +936,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
* @param id Material ID, from range [0, @ref materialCount()).
*
* Expects that a file is opened.
* @see @ref materialForName()
* @see @ref materialForName(), @ref material(const std::string&)
*/
std::string materialName(UnsignedInt id);
@ -862,9 +946,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given material or @cpp nullptr @ce if importing failed.
* Expects that a file is opened.
* @see @ref material(const std::string&)
*/
Containers::Pointer<AbstractMaterialData> material(UnsignedInt id);
/**
* @brief Material for given name
* @m_since_latest
*
* A convenience API combining @ref materialForName() and
* @ref material(UnsignedInt). Returns @ref Containers::NullOpt either
* if @ref materialForName() returns @cpp -1 @ce or if importing fails.
* Expects that a file is opened.
*/
Containers::Pointer<AbstractMaterialData> material(const std::string& name);
/**
* @brief Texture count
*
@ -877,7 +973,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* If no texture for given name exists, returns @cpp -1 @ce. Expects
* that a file is opened.
* @see @ref textureName()
* @see @ref textureName(), @ref texture(const std::string&)
*/
Int textureForName(const std::string& name);
@ -896,9 +992,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given texture or @ref Containers::NullOpt if importing
* failed. Expects that a file is opened.
* @see @ref texture(const std::string&)
*/
Containers::Optional<TextureData> texture(UnsignedInt id);
/**
* @brief Texture for given name
* @m_since_latest
*
* A convenience API combining @ref textureForName() and
* @ref texture(UnsignedInt). Returns @ref Containers::NullOpt either
* if @ref textureForName() returns @cpp -1 @ce or if importing fails.
* Expects that a file is opened.
*/
Containers::Optional<TextureData> texture(const std::string& name);
/**
* @brief One-dimensional image count
*
@ -922,7 +1030,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* If no image for given name exists, returns @cpp -1 @ce. Expects that
* a file is opened.
* @see @ref image1DName()
* @see @ref image1DName(), @ref image1D(const std::string&, UnsignedInt)
*/
Int image1DForName(const std::string& name);
@ -942,9 +1050,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given image or @ref Containers::NullOpt if importing failed.
* Expects that a file is opened.
* @see @ref image1D(const std::string&, UnsignedInt)
*/
Containers::Optional<ImageData1D> image1D(UnsignedInt id, UnsignedInt level = 0);
/**
* @brief One-dimensional image for given name
* @m_since_latest
*
* A convenience API combining @ref image1DForName() and
* @ref image1D(UnsignedInt, UnsignedInt). Returns
* @ref Containers::NullOpt either if @ref image1DForName() returns
* @cpp -1 @ce or if importing fails. Expects that a file is opened.
*/
Containers::Optional<ImageData1D> image1D(const std::string& name, UnsignedInt level = 0);
/**
* @brief Two-dimensional image count
*
@ -968,7 +1088,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* If no image for given name exists, returns @cpp -1 @ce. Expects that
* a file is opened.
* @see @ref image2DName()
* @see @ref image2DName(), @ref image2D(const std::string&, UnsignedInt)
*/
Int image2DForName(const std::string& name);
@ -988,9 +1108,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given image or @ref Containers::NullOpt if importing failed.
* Expects that a file is opened.
* @see @ref image2D(const std::string&, UnsignedInt)
*/
Containers::Optional<ImageData2D> image2D(UnsignedInt id, UnsignedInt level = 0);
/**
* @brief Two-dimensional image for given name
* @m_since_latest
*
* A convenience API combining @ref image2DForName() and
* @ref image2D(UnsignedInt, UnsignedInt). Returns
* @ref Containers::NullOpt either if @ref image2DForName() returns
* @cpp -1 @ce or if importing fails. Expects that a file is opened.
*/
Containers::Optional<ImageData2D> image2D(const std::string& name, UnsignedInt level = 0);
/**
* @brief Three-dimensional image count
*
@ -1014,7 +1146,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* If no image for given name exists, returns @cpp -1 @ce. Expects that
* a file is opened.
* @see @ref image3DName()
* @see @ref image3DName(), @ref image3D(const std::string&, UnsignedInt)
*/
Int image3DForName(const std::string& name);
@ -1034,9 +1166,21 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* Returns given image or @ref Containers::NullOpt if importing failed.
* Expects that a file is opened.
* @see @ref image3D(const std::string&, UnsignedInt)
*/
Containers::Optional<ImageData3D> image3D(UnsignedInt id, UnsignedInt level = 0);
/**
* @brief Three-dimensional image for given name
* @m_since_latest
*
* A convenience API combining @ref image3DForName() and
* @ref image3D(UnsignedInt, UnsignedInt). Returns
* @ref Containers::NullOpt either if @ref image3DForName() returns
* @cpp -1 @ce or if importing fails. Expects that a file is opened.
*/
Containers::Optional<ImageData3D> image3D(const std::string& name, UnsignedInt level = 0);
/*@}*/
/**

316
src/Magnum/Trade/Test/AbstractImporterTest.cpp

@ -1097,9 +1097,18 @@ void AbstractImporterTest::scene() {
CORRADE_COMPARE(importer.sceneForName("eighth"), 7);
CORRADE_COMPARE(importer.sceneName(7), "eighth");
auto data = importer.scene(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.scene(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.scene("eighth");
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.scene("foo"));
}
}
void AbstractImporterTest::sceneCountNotImplemented() {
@ -1219,7 +1228,10 @@ void AbstractImporterTest::sceneNoFile() {
Error redirectError{&out};
importer.scene(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::scene(): no file opened\n");
importer.scene("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::scene(): no file opened\n"
"Trade::AbstractImporter::scene(): no file opened\n");
}
void AbstractImporterTest::sceneOutOfRange() {
@ -1268,9 +1280,18 @@ void AbstractImporterTest::animation() {
CORRADE_COMPARE(importer.animationForName("eighth"), 7);
CORRADE_COMPARE(importer.animationName(7), "eighth");
auto data = importer.animation(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.animation(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.animation("eighth");
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.animation("foo"));
}
}
void AbstractImporterTest::animationCountNotImplemented() {
@ -1390,7 +1411,10 @@ void AbstractImporterTest::animationNoFile() {
Error redirectError{&out};
importer.animation(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::animation(): no file opened\n");
importer.animation("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::animation(): no file opened\n"
"Trade::AbstractImporter::animation(): no file opened\n");
}
void AbstractImporterTest::animationOutOfRange() {
@ -1457,6 +1481,7 @@ void AbstractImporterTest::animationCustomDataDeleter() {
void doClose() override {}
UnsignedInt doAnimationCount() const override { return 1; }
Int doAnimationForName(const std::string&) override { return 0; }
Containers::Optional<AnimationData> doAnimation(UnsignedInt) override {
return AnimationData{Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}}, nullptr};
}
@ -1466,7 +1491,10 @@ void AbstractImporterTest::animationCustomDataDeleter() {
Error redirectError{&out};
importer.animation(0);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::animation(): implementation is not allowed to use a custom Array deleter\n");
importer.animation("");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::animation(): implementation is not allowed to use a custom Array deleter\n"
"Trade::AbstractImporter::animation(): implementation is not allowed to use a custom Array deleter\n");
}
void AbstractImporterTest::animationCustomTrackDeleter() {
@ -1476,6 +1504,7 @@ void AbstractImporterTest::animationCustomTrackDeleter() {
void doClose() override {}
UnsignedInt doAnimationCount() const override { return 1; }
Int doAnimationForName(const std::string&) override { return 0; }
Containers::Optional<AnimationData> doAnimation(UnsignedInt) override {
return AnimationData{nullptr, Containers::Array<AnimationTrackData>{nullptr, 0, [](AnimationTrackData*, std::size_t) {}}};
}
@ -1485,7 +1514,10 @@ void AbstractImporterTest::animationCustomTrackDeleter() {
Error redirectError{&out};
importer.animation(0);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::animation(): implementation is not allowed to use a custom Array deleter\n");
importer.animation("");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::animation(): implementation is not allowed to use a custom Array deleter\n"
"Trade::AbstractImporter::animation(): implementation is not allowed to use a custom Array deleter\n");
}
void AbstractImporterTest::light() {
@ -1513,9 +1545,18 @@ void AbstractImporterTest::light() {
CORRADE_COMPARE(importer.lightForName("eighth"), 7);
CORRADE_COMPARE(importer.lightName(7), "eighth");
auto data = importer.light(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.light(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.light("eighth");
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.light("foo"));
}
}
void AbstractImporterTest::lightCountNotImplemented() {
@ -1635,7 +1676,10 @@ void AbstractImporterTest::lightNoFile() {
Error redirectError{&out};
importer.light(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::light(): no file opened\n");
importer.light("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::light(): no file opened\n"
"Trade::AbstractImporter::light(): no file opened\n");
}
void AbstractImporterTest::lightOutOfRange() {
@ -1679,9 +1723,18 @@ void AbstractImporterTest::camera() {
CORRADE_COMPARE(importer.cameraForName("eighth"), 7);
CORRADE_COMPARE(importer.cameraName(7), "eighth");
auto data = importer.camera(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.camera(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.camera("eighth");
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.camera("foo"));
}
}
void AbstractImporterTest::cameraCountNotImplemented() {
@ -1801,7 +1854,10 @@ void AbstractImporterTest::cameraNoFile() {
Error redirectError{&out};
importer.camera(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::camera(): no file opened\n");
importer.camera("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::camera(): no file opened\n"
"Trade::AbstractImporter::camera(): no file opened\n");
}
void AbstractImporterTest::cameraOutOfRange() {
@ -1845,9 +1901,18 @@ void AbstractImporterTest::object2D() {
CORRADE_COMPARE(importer.object2DForName("eighth"), 7);
CORRADE_COMPARE(importer.object2DName(7), "eighth");
auto data = importer.object2D(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.object2D(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.object2D("eighth");
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.object2D("foo"));
}
}
void AbstractImporterTest::object2DCountNotImplemented() {
@ -1967,7 +2032,10 @@ void AbstractImporterTest::object2DNoFile() {
Error redirectError{&out};
importer.object2D(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::object2D(): no file opened\n");
importer.object2D("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::object2D(): no file opened\n"
"Trade::AbstractImporter::object2D(): no file opened\n");
}
void AbstractImporterTest::object2DOutOfRange() {
@ -2011,9 +2079,18 @@ void AbstractImporterTest::object3D() {
CORRADE_COMPARE(importer.object3DForName("eighth"), 7);
CORRADE_COMPARE(importer.object3DName(7), "eighth");
auto data = importer.object3D(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.object3D(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.object3D("eighth");
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.object3D("foo"));
}
}
void AbstractImporterTest::object3DCountNotImplemented() {
@ -2133,7 +2210,10 @@ void AbstractImporterTest::object3DNoFile() {
Error redirectError{&out};
importer.object3D(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::object3D(): no file opened\n");
importer.object3D("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::object3D(): no file opened\n"
"Trade::AbstractImporter::object3D(): no file opened\n");
}
void AbstractImporterTest::object3DOutOfRange() {
@ -2179,9 +2259,18 @@ void AbstractImporterTest::mesh() {
CORRADE_COMPARE(importer.meshForName("eighth"), 7);
CORRADE_COMPARE(importer.meshName(7), "eighth");
auto data = importer.mesh(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.mesh(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.mesh("eighth");
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.mesh("foo"));
}
}
#ifdef MAGNUM_BUILD_DEPRECATED
@ -2340,7 +2429,10 @@ void AbstractImporterTest::meshNoFile() {
Error redirectError{&out};
importer.mesh(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::mesh(): no file opened\n");
importer.mesh("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::mesh(): no file opened\n"
"Trade::AbstractImporter::mesh(): no file opened\n");
}
void AbstractImporterTest::meshOutOfRange() {
@ -2418,6 +2510,7 @@ void AbstractImporterTest::meshCustomIndexDataDeleter() {
void doClose() override {}
UnsignedInt doMeshCount() const override { return 1; }
Int doMeshForName(const std::string&) override { return 0; }
Containers::Optional<MeshData> doMesh(UnsignedInt) override {
return MeshData{MeshPrimitive::Triangles, Containers::Array<char>{data, 1, [](char*, std::size_t) {}}, MeshIndexData{MeshIndexType::UnsignedByte, data}};
}
@ -2429,7 +2522,10 @@ void AbstractImporterTest::meshCustomIndexDataDeleter() {
Error redirectError{&out};
importer.mesh(0);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::mesh(): implementation is not allowed to use a custom Array deleter\n");
importer.mesh("");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::mesh(): implementation is not allowed to use a custom Array deleter\n"
"Trade::AbstractImporter::mesh(): implementation is not allowed to use a custom Array deleter\n");
}
void AbstractImporterTest::meshCustomVertexDataDeleter() {
@ -2439,6 +2535,7 @@ void AbstractImporterTest::meshCustomVertexDataDeleter() {
void doClose() override {}
UnsignedInt doMeshCount() const override { return 1; }
Int doMeshForName(const std::string&) override { return 0; }
Containers::Optional<MeshData> doMesh(UnsignedInt) override {
return MeshData{MeshPrimitive::Triangles, Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}}, {MeshAttributeData{MeshAttribute::Position, VertexFormat::Vector3, nullptr}}};
}
@ -2448,7 +2545,10 @@ void AbstractImporterTest::meshCustomVertexDataDeleter() {
Error redirectError{&out};
importer.mesh(0);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::mesh(): implementation is not allowed to use a custom Array deleter\n");
importer.mesh("");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::mesh(): implementation is not allowed to use a custom Array deleter\n"
"Trade::AbstractImporter::mesh(): implementation is not allowed to use a custom Array deleter\n");
}
void AbstractImporterTest::meshCustomAttributesDeleter() {
@ -2458,6 +2558,7 @@ void AbstractImporterTest::meshCustomAttributesDeleter() {
void doClose() override {}
UnsignedInt doMeshCount() const override { return 1; }
Int doMeshForName(const std::string&) override { return 0; }
Containers::Optional<MeshData> doMesh(UnsignedInt) override {
return MeshData{MeshPrimitive::Triangles, nullptr, Containers::Array<MeshAttributeData>{&positions, 1, [](MeshAttributeData*, std::size_t) {}}};
}
@ -2469,7 +2570,11 @@ void AbstractImporterTest::meshCustomAttributesDeleter() {
Error redirectError{&out};
importer.mesh(0);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::mesh(): implementation is not allowed to use a custom Array deleter\n");
importer.mesh("");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::mesh(): implementation is not allowed to use a custom Array deleter\n"
"Trade::AbstractImporter::mesh(): implementation is not allowed to use a custom Array deleter\n"
);
}
void AbstractImporterTest::meshAttributeName() {
@ -2933,9 +3038,18 @@ void AbstractImporterTest::material() {
CORRADE_COMPARE(importer.materialForName("eighth"), 7);
CORRADE_COMPARE(importer.materialName(7), "eighth");
auto data = importer.material(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.material(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.material("eighth");
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.material("foo"));
}
}
void AbstractImporterTest::materialCountNotImplemented() {
@ -3055,7 +3169,10 @@ void AbstractImporterTest::materialNoFile() {
Error redirectError{&out};
importer.material(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::material(): no file opened\n");
importer.material("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::material(): no file opened\n"
"Trade::AbstractImporter::material(): no file opened\n");
}
void AbstractImporterTest::materialOutOfRange() {
@ -3099,9 +3216,18 @@ void AbstractImporterTest::texture() {
CORRADE_COMPARE(importer.textureForName("eighth"), 7);
CORRADE_COMPARE(importer.textureName(7), "eighth");
auto data = importer.texture(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.texture(7);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.texture("eighth");
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.texture("foo"));
}
}
void AbstractImporterTest::textureCountNotImplemented() {
@ -3221,7 +3347,10 @@ void AbstractImporterTest::textureNoFile() {
Error redirectError{&out};
importer.texture(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::texture(): no file opened\n");
importer.texture("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::texture(): no file opened\n"
"Trade::AbstractImporter::texture(): no file opened\n");
}
void AbstractImporterTest::textureOutOfRange() {
@ -3270,9 +3399,18 @@ void AbstractImporterTest::image1D() {
CORRADE_COMPARE(importer.image1DForName("eighth"), 7);
CORRADE_COMPARE(importer.image1DName(7), "eighth");
auto data = importer.image1D(7, 2);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.image1D(7, 2);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.image1D("eighth", 2);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.image1D("foo"));
}
}
void AbstractImporterTest::image1DCountNotImplemented() {
@ -3346,6 +3484,7 @@ void AbstractImporterTest::image1DLevelCountZero() {
void doClose() override {}
UnsignedInt doImage1DCount() const override { return 8; }
Int doImage1DForName(const std::string&) override { return 0; }
UnsignedInt doImage1DLevelCount(UnsignedInt) override { return 0; }
} importer;
@ -3355,8 +3494,10 @@ void AbstractImporterTest::image1DLevelCountZero() {
/* This should print a similar message instead of a confusing
"level 1 out of range for 0 entries" */
importer.image1D(7, 1);
importer.image1D("", 1);
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image1DLevelCount(): implementation reported zero levels\n"
"Trade::AbstractImporter::image1D(): implementation reported zero levels\n"
"Trade::AbstractImporter::image1D(): implementation reported zero levels\n");
}
@ -3453,7 +3594,10 @@ void AbstractImporterTest::image1DNoFile() {
Error redirectError{&out};
importer.image1D(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::image1D(): no file opened\n");
importer.image1D("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image1D(): no file opened\n"
"Trade::AbstractImporter::image1D(): no file opened\n");
}
void AbstractImporterTest::image1DOutOfRange() {
@ -3479,13 +3623,17 @@ void AbstractImporterTest::image1DLevelOutOfRange() {
void doClose() override {}
UnsignedInt doImage1DCount() const override { return 8; }
Int doImage1DForName(const std::string&) override { return 0; }
UnsignedInt doImage1DLevelCount(UnsignedInt) override { return 3; }
} importer;
std::ostringstream out;
Error redirectError{&out};
importer.image1D(7, 3);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::image1D(): level 3 out of range for 3 entries\n");
importer.image1D("", 3);
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image1D(): level 3 out of range for 3 entries\n"
"Trade::AbstractImporter::image1D(): level 3 out of range for 3 entries\n");
}
void AbstractImporterTest::image1DNonOwningDeleter() {
@ -3533,6 +3681,7 @@ void AbstractImporterTest::image1DCustomDeleter() {
void doClose() override {}
UnsignedInt doImage1DCount() const override { return 1; }
Int doImage1DForName(const std::string&) override { return 0; }
Containers::Optional<ImageData1D> doImage1D(UnsignedInt, UnsignedInt) override {
return ImageData1D{PixelFormat::RGBA8Unorm, {}, Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}}};
}
@ -3542,7 +3691,10 @@ void AbstractImporterTest::image1DCustomDeleter() {
Error redirectError{&out};
importer.image1D(0);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::image1D(): implementation is not allowed to use a custom Array deleter\n");
importer.image1D("");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image1D(): implementation is not allowed to use a custom Array deleter\n"
"Trade::AbstractImporter::image1D(): implementation is not allowed to use a custom Array deleter\n");
}
void AbstractImporterTest::image2D() {
@ -3575,9 +3727,18 @@ void AbstractImporterTest::image2D() {
CORRADE_COMPARE(importer.image2DForName("eighth"), 7);
CORRADE_COMPARE(importer.image2DName(7), "eighth");
auto data = importer.image2D(7, 2);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.image2D(7, 2);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.image2D("eighth", 2);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.image2D("foo"));
}
}
void AbstractImporterTest::image2DCountNotImplemented() {
@ -3651,6 +3812,7 @@ void AbstractImporterTest::image2DLevelCountZero() {
void doClose() override {}
UnsignedInt doImage2DCount() const override { return 8; }
Int doImage2DForName(const std::string&) override { return 0; }
UnsignedInt doImage2DLevelCount(UnsignedInt) override { return 0; }
} importer;
@ -3660,8 +3822,10 @@ void AbstractImporterTest::image2DLevelCountZero() {
/* This should print a similar message instead of a confusing
"level 1 out of range for 0 entries" */
importer.image2D(7, 1);
importer.image2D(7, 1);
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image2DLevelCount(): implementation reported zero levels\n"
"Trade::AbstractImporter::image2D(): implementation reported zero levels\n"
"Trade::AbstractImporter::image2D(): implementation reported zero levels\n");
}
@ -3758,7 +3922,10 @@ void AbstractImporterTest::image2DNoFile() {
Error redirectError{&out};
importer.image2D(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::image2D(): no file opened\n");
importer.image2D("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image2D(): no file opened\n"
"Trade::AbstractImporter::image2D(): no file opened\n");
}
void AbstractImporterTest::image2DOutOfRange() {
@ -3784,13 +3951,17 @@ void AbstractImporterTest::image2DLevelOutOfRange() {
void doClose() override {}
UnsignedInt doImage2DCount() const override { return 8; }
Int doImage2DForName(const std::string&) override { return 0; }
UnsignedInt doImage2DLevelCount(UnsignedInt) override { return 3; }
} importer;
std::ostringstream out;
Error redirectError{&out};
importer.image2D(7, 3);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::image2D(): level 3 out of range for 3 entries\n");
importer.image2D("", 3);
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image2D(): level 3 out of range for 3 entries\n"
"Trade::AbstractImporter::image2D(): level 3 out of range for 3 entries\n");
}
void AbstractImporterTest::image2DNonOwningDeleter() {
@ -3838,6 +4009,7 @@ void AbstractImporterTest::image2DCustomDeleter() {
void doClose() override {}
UnsignedInt doImage2DCount() const override { return 1; }
Int doImage2DForName(const std::string&) override { return 0; }
Containers::Optional<ImageData2D> doImage2D(UnsignedInt, UnsignedInt) override {
return ImageData2D{PixelFormat::RGBA8Unorm, {}, Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}}};
}
@ -3847,7 +4019,10 @@ void AbstractImporterTest::image2DCustomDeleter() {
Error redirectError{&out};
importer.image2D(0);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::image2D(): implementation is not allowed to use a custom Array deleter\n");
importer.image2D("");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image2D(): implementation is not allowed to use a custom Array deleter\n"
"Trade::AbstractImporter::image2D(): implementation is not allowed to use a custom Array deleter\n");
}
void AbstractImporterTest::image3D() {
@ -3880,9 +4055,18 @@ void AbstractImporterTest::image3D() {
CORRADE_COMPARE(importer.image3DForName("eighth"), 7);
CORRADE_COMPARE(importer.image3DName(7), "eighth");
auto data = importer.image3D(7, 2);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
{
auto data = importer.image3D(7, 2);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
auto data = importer.image3D("eighth", 2);
CORRADE_VERIFY(data);
CORRADE_COMPARE(data->importerState(), &state);
} {
/* This should fail gracefully, not assert */
CORRADE_VERIFY(!importer.image3D("foo"));
}
}
void AbstractImporterTest::image3DCountNotImplemented() {
@ -3957,6 +4141,7 @@ void AbstractImporterTest::image3DLevelCountZero() {
void doClose() override {}
UnsignedInt doImage3DCount() const override { return 8; }
Int doImage3DForName(const std::string&) override { return 0; }
UnsignedInt doImage3DLevelCount(UnsignedInt) override { return 0; }
} importer;
@ -3966,8 +4151,10 @@ void AbstractImporterTest::image3DLevelCountZero() {
/* This should print a similar message instead of a confusing
"level 1 out of range for 0 entries" */
importer.image3D(7, 1);
importer.image3D("", 1);
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image3DLevelCount(): implementation reported zero levels\n"
"Trade::AbstractImporter::image3D(): implementation reported zero levels\n"
"Trade::AbstractImporter::image3D(): implementation reported zero levels\n");
}
@ -4064,7 +4251,10 @@ void AbstractImporterTest::image3DNoFile() {
Error redirectError{&out};
importer.image3D(42);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::image3D(): no file opened\n");
importer.image3D("foo");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image3D(): no file opened\n"
"Trade::AbstractImporter::image3D(): no file opened\n");
}
void AbstractImporterTest::image3DOutOfRange() {
@ -4090,13 +4280,17 @@ void AbstractImporterTest::image3DLevelOutOfRange() {
void doClose() override {}
UnsignedInt doImage3DCount() const override { return 8; }
Int doImage3DForName(const std::string&) override { return 0; }
UnsignedInt doImage3DLevelCount(UnsignedInt) override { return 3; }
} importer;
std::ostringstream out;
Error redirectError{&out};
importer.image3D(7, 3);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::image3D(): level 3 out of range for 3 entries\n");
importer.image3D("", 3);
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image3D(): level 3 out of range for 3 entries\n"
"Trade::AbstractImporter::image3D(): level 3 out of range for 3 entries\n");
}
void AbstractImporterTest::image3DNonOwningDeleter() {
@ -4144,6 +4338,7 @@ void AbstractImporterTest::image3DCustomDeleter() {
void doClose() override {}
UnsignedInt doImage3DCount() const override { return 1; }
Int doImage3DForName(const std::string&) override { return 0; }
Containers::Optional<ImageData3D> doImage3D(UnsignedInt, UnsignedInt) override {
return ImageData3D{PixelFormat::RGBA8Unorm, {}, Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}}};
}
@ -4153,7 +4348,10 @@ void AbstractImporterTest::image3DCustomDeleter() {
Error redirectError{&out};
importer.image3D(0);
CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::image3D(): implementation is not allowed to use a custom Array deleter\n");
importer.image3D("");
CORRADE_COMPARE(out.str(),
"Trade::AbstractImporter::image3D(): implementation is not allowed to use a custom Array deleter\n"
"Trade::AbstractImporter::image3D(): implementation is not allowed to use a custom Array deleter\n");
}
void AbstractImporterTest::importerState() {

Loading…
Cancel
Save