Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UfbxImporter: Add support for searching images #142

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 126 additions & 1 deletion src/MagnumPlugins/UfbxImporter/Test/UfbxImporterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ struct UfbxImporterTest: TestSuite::Tester {
void imageDeduplication();
void imageNonExistentName();
void imageAbsolutePath();
void imageSearch();
void imageSearchSubdir();
void imageSearchSubdirTooDeep();
void imageSearchMissing();
void imageSearchMidRoot();
void imageSearchMultiSlash();
void imageSearchParentPath();
void imageNot2D();
void imageBrokenExternal();
void imageBrokenEmbedded();
Expand Down Expand Up @@ -315,6 +322,13 @@ UfbxImporterTest::UfbxImporterTest() {
&UfbxImporterTest::imageDeduplication,
&UfbxImporterTest::imageNonExistentName,
&UfbxImporterTest::imageAbsolutePath,
&UfbxImporterTest::imageSearch,
&UfbxImporterTest::imageSearchSubdir,
&UfbxImporterTest::imageSearchSubdirTooDeep,
&UfbxImporterTest::imageSearchMissing,
&UfbxImporterTest::imageSearchMidRoot,
&UfbxImporterTest::imageSearchMultiSlash,
&UfbxImporterTest::imageSearchParentPath,
&UfbxImporterTest::imageNot2D,
&UfbxImporterTest::imageBrokenExternal,
&UfbxImporterTest::imageBrokenEmbedded,
Expand Down Expand Up @@ -2330,11 +2344,122 @@ void UfbxImporterTest::imageAbsolutePath() {

std::ostringstream out;
Error redirectError{&out};

CORRADE_VERIFY(!importer->image2D(0));
CORRADE_COMPARE_AS(out.str(), "Trade::AbstractImporter::openFile(): cannot open file /absolute/path/to/tex-red.png", TestSuite::Compare::StringContains);
}

void UfbxImporterTest::imageSearch() {
if(_manager.loadState("PngImporter") == PluginManager::LoadState::NotFound)
CORRADE_SKIP("PngImporter plugin not found, cannot test");

Containers::Pointer<AbstractImporter> importer = _manager.instantiate("UfbxImporter");
importer->configuration().setValue("imageSearchDepth", -1);
CORRADE_VERIFY(importer->openFile(Utility::Path::join(UFBXIMPORTER_TEST_DIR, "image-absolute-path.fbx")));

CORRADE_COMPARE(importer->image2DCount(), 1);

Containers::Optional<ImageData2D> image = importer->image2D(0);
CORRADE_VERIFY(image);
CORRADE_COMPARE(image->size(), (Vector2i{1, 1}));
CORRADE_COMPARE(image->pixels<Color3ub>()[0][0], 0xff0000_rgb);
}

void UfbxImporterTest::imageSearchSubdir() {
if(_manager.loadState("PngImporter") == PluginManager::LoadState::NotFound)
CORRADE_SKIP("PngImporter plugin not found, cannot test");

Containers::Pointer<AbstractImporter> importer = _manager.instantiate("UfbxImporter");
importer->configuration().setValue("imageSearchDepth", -1);
CORRADE_VERIFY(importer->openFile(Utility::Path::join(UFBXIMPORTER_TEST_DIR, "external-absolute-texture.fbx")));

CORRADE_COMPARE(importer->image2DCount(), 1);

Containers::Optional<ImageData2D> image = importer->image2D(0);
CORRADE_VERIFY(image);
CORRADE_COMPARE(image->size(), (Vector2i{1, 1}));
CORRADE_COMPARE(image->pixels<Color3ub>()[0][0], 0xff0000_rgb);
}

void UfbxImporterTest::imageSearchSubdirTooDeep() {
if(_manager.loadState("PngImporter") == PluginManager::LoadState::NotFound)
CORRADE_SKIP("PngImporter plugin not found, cannot test");

Containers::Pointer<AbstractImporter> importer = _manager.instantiate("UfbxImporter");
importer->configuration().setValue("imageSearchDepth", 1);
CORRADE_VERIFY(importer->openFile(Utility::Path::join(UFBXIMPORTER_TEST_DIR, "external-absolute-texture.fbx")));

CORRADE_COMPARE(importer->image2DCount(), 1);

std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!importer->image2D(0));
CORRADE_COMPARE_AS(out.str(), "Trade::UfbxImporter::image2D(): could not resolve image: W:/ExternalTextures/tex-red-external.png", TestSuite::Compare::StringContains);
}

void UfbxImporterTest::imageSearchMissing() {
if(_manager.loadState("PngImporter") == PluginManager::LoadState::NotFound)
CORRADE_SKIP("PngImporter plugin not found, cannot test");

Containers::Pointer<AbstractImporter> importer = _manager.instantiate("UfbxImporter");
importer->configuration().setValue("imageSearchDepth", -1);
CORRADE_VERIFY(importer->openFile(Utility::Path::join(UFBXIMPORTER_TEST_DIR, "external-absolute-texture-missing.fbx")));

CORRADE_COMPARE(importer->image2DCount(), 1);

std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!importer->image2D(0));
CORRADE_COMPARE_AS(out.str(), "Trade::UfbxImporter::image2D(): could not resolve image: W:/ExternalTextures/tex-missing-file.png", TestSuite::Compare::StringContains);
}

void UfbxImporterTest::imageSearchMidRoot() {
if(_manager.loadState("PngImporter") == PluginManager::LoadState::NotFound)
CORRADE_SKIP("PngImporter plugin not found, cannot test");

Containers::Pointer<AbstractImporter> importer = _manager.instantiate("UfbxImporter");
importer->configuration().setValue("imageSearchDepth", -1);
CORRADE_VERIFY(importer->openFile(Utility::Path::join(UFBXIMPORTER_TEST_DIR, "image-absolute-path-mid-root.fbx")));

CORRADE_COMPARE(importer->image2DCount(), 1);

std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!importer->image2D(0));
CORRADE_COMPARE_AS(out.str(), "Trade::UfbxImporter::image2D(): could not resolve image: /absolute/C:/to/tex-missing.png", TestSuite::Compare::StringContains);
}

void UfbxImporterTest::imageSearchMultiSlash() {
if(_manager.loadState("PngImporter") == PluginManager::LoadState::NotFound)
CORRADE_SKIP("PngImporter plugin not found, cannot test");

Containers::Pointer<AbstractImporter> importer = _manager.instantiate("UfbxImporter");
importer->configuration().setValue("imageSearchDepth", -1);
CORRADE_VERIFY(importer->openFile(Utility::Path::join(UFBXIMPORTER_TEST_DIR, "image-absolute-path-multi-slash.fbx")));

CORRADE_COMPARE(importer->image2DCount(), 1);

Containers::Optional<ImageData2D> image = importer->image2D(0);
CORRADE_VERIFY(image);
CORRADE_COMPARE(image->size(), (Vector2i{1, 1}));
CORRADE_COMPARE(image->pixels<Color3ub>()[0][0], 0xff0000_rgb);
}

void UfbxImporterTest::imageSearchParentPath() {
if(_manager.loadState("PngImporter") == PluginManager::LoadState::NotFound)
CORRADE_SKIP("PngImporter plugin not found, cannot test");

Containers::Pointer<AbstractImporter> importer = _manager.instantiate("UfbxImporter");
importer->configuration().setValue("imageSearchDepth", -1);
CORRADE_VERIFY(importer->openFile(Utility::Path::join(UFBXIMPORTER_TEST_DIR, "image-parent-path.fbx")));

CORRADE_COMPARE(importer->image2DCount(), 1);

std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!importer->image2D(0));
CORRADE_COMPARE_AS(out.str(), "Trade::UfbxImporter::image2D(): could not resolve image: path/../UfbxImporter.cpp", TestSuite::Compare::StringContains);
}

void UfbxImporterTest::imageNot2D() {
if(_manager.loadState("DdsImporter") == PluginManager::LoadState::NotFound)
CORRADE_SKIP("DdsImporter plugin not found, cannot test");
Expand Down
Binary file not shown.
Binary file not shown.
Loading