mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.9 KiB
107 lines
3.9 KiB
|
11 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
8 years ago
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
|
||
|
11 years ago
|
Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include <sstream>
|
||
|
|
#include <Corrade/TestSuite/Tester.h>
|
||
|
|
#include <Corrade/Utility/Directory.h>
|
||
|
|
#include <Corrade/PluginManager/Manager.h>
|
||
|
8 years ago
|
|
||
|
|
#include "Magnum/PixelFormat.h"
|
||
|
8 years ago
|
#include "Magnum/Trade/AbstractImageConverter.h"
|
||
|
8 years ago
|
#include "Magnum/Trade/ImageData.h"
|
||
|
11 years ago
|
|
||
|
|
#include "configure.h"
|
||
|
|
|
||
|
|
namespace Magnum { namespace Trade { namespace Test {
|
||
|
|
|
||
|
|
struct AnyImageConverterTest: TestSuite::Tester {
|
||
|
|
explicit AnyImageConverterTest();
|
||
|
|
|
||
|
8 years ago
|
void tga();
|
||
|
11 years ago
|
|
||
|
|
void unknown();
|
||
|
|
|
||
|
8 years ago
|
/* Explicitly forbid system-wide plugin dependencies */
|
||
|
|
PluginManager::Manager<AbstractImageConverter> _manager{"nonexistent"};
|
||
|
11 years ago
|
};
|
||
|
|
|
||
|
8 years ago
|
AnyImageConverterTest::AnyImageConverterTest() {
|
||
|
8 years ago
|
addTests({&AnyImageConverterTest::tga,
|
||
|
11 years ago
|
|
||
|
|
&AnyImageConverterTest::unknown});
|
||
|
8 years ago
|
|
||
|
|
/* Load the plugin directly from the build tree. Otherwise it's static and
|
||
|
|
already loaded. */
|
||
|
|
#ifdef ANYIMAGECONVERTER_PLUGIN_FILENAME
|
||
|
|
CORRADE_INTERNAL_ASSERT(_manager.load(ANYIMAGECONVERTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded);
|
||
|
|
#endif
|
||
|
|
/* Optional plugins that don't have to be here */
|
||
|
|
#ifdef TGAIMAGECONVERTER_PLUGIN_FILENAME
|
||
|
|
CORRADE_INTERNAL_ASSERT(_manager.load(TGAIMAGECONVERTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
/* Create the output directory if it doesn't exist yet */
|
||
|
|
CORRADE_INTERNAL_ASSERT(Utility::Directory::mkpath(ANYIMAGECONVERTER_TEST_DIR));
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
constexpr const char Data[] = {
|
||
|
|
1, 2, 3, 2, 3, 4, 0, 0,
|
||
|
|
3, 4, 5, 4, 5, 6, 0, 0,
|
||
|
|
5, 6, 7, 6, 7, 8, 0, 0
|
||
|
|
};
|
||
|
|
|
||
|
8 years ago
|
const ImageView2D Image{PixelFormat::RGB8Unorm, {2, 3}, Data};
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
8 years ago
|
void AnyImageConverterTest::tga() {
|
||
|
8 years ago
|
if(!(_manager.loadState("TgaImageConverter") & PluginManager::LoadState::Loaded))
|
||
|
|
CORRADE_SKIP("TgaImageConverter plugin not enabled, cannot test");
|
||
|
11 years ago
|
|
||
|
8 years ago
|
const std::string filename = Utility::Directory::join(ANYIMAGECONVERTER_TEST_DIR, "output.tga");
|
||
|
10 years ago
|
|
||
|
|
if(Utility::Directory::fileExists(filename))
|
||
|
|
CORRADE_VERIFY(Utility::Directory::rm(filename));
|
||
|
11 years ago
|
|
||
|
|
/* Just test that the exported file exists */
|
||
|
8 years ago
|
std::unique_ptr<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
|
||
|
|
CORRADE_VERIFY(converter->exportToFile(Image, filename));
|
||
|
10 years ago
|
CORRADE_VERIFY(Utility::Directory::fileExists(filename));
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
|
void AnyImageConverterTest::unknown() {
|
||
|
|
std::ostringstream output;
|
||
|
10 years ago
|
Error redirectError{&output};
|
||
|
11 years ago
|
|
||
|
8 years ago
|
std::unique_ptr<AbstractImageConverter> converter = _manager.instantiate("AnyImageConverter");
|
||
|
|
CORRADE_VERIFY(!converter->exportToFile(Image, "image.xcf"));
|
||
|
11 years ago
|
|
||
|
|
CORRADE_COMPARE(output.str(), "Trade::AnyImageConverter::exportToFile(): cannot determine type of file image.xcf\n");
|
||
|
|
}
|
||
|
|
|
||
|
|
}}}
|
||
|
|
|
||
|
|
CORRADE_TEST_MAIN(Magnum::Trade::Test::AnyImageConverterTest)
|