mirror of https://github.com/mosra/magnum.git
Browse Source
Just the --info for now. This seemingly adds quite a lot of uncovered lines, but those were uncovered before as well, it's just actually visible now.pull/595/head
7 changed files with 199 additions and 6 deletions
@ -0,0 +1,140 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||||
|
2020, 2021, 2022 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 <cstdlib> |
||||||
|
#include <Corrade/Containers/Array.h> |
||||||
|
#include <Corrade/Containers/Optional.h> |
||||||
|
#include <Corrade/Containers/Pair.h> |
||||||
|
#include <Corrade/Containers/String.h> |
||||||
|
#include <Corrade/TestSuite/Tester.h> |
||||||
|
#include <Corrade/TestSuite/Compare/StringToFile.h> |
||||||
|
#include <Corrade/Utility/Format.h> |
||||||
|
#include <Corrade/Utility/Path.h> |
||||||
|
|
||||||
|
#include "Magnum/Trade/AbstractImporter.h" |
||||||
|
|
||||||
|
#include "configure.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Trade { namespace Test { namespace { |
||||||
|
|
||||||
|
struct ImageConverterTest: TestSuite::Tester { |
||||||
|
explicit ImageConverterTest(); |
||||||
|
|
||||||
|
void info(); |
||||||
|
}; |
||||||
|
|
||||||
|
using namespace Containers::Literals; |
||||||
|
|
||||||
|
const struct { |
||||||
|
const char* name; |
||||||
|
Containers::Array<Containers::String> args; |
||||||
|
const char* requiresImporter; |
||||||
|
const char* expected; |
||||||
|
} InfoData[]{ |
||||||
|
{"data", Containers::array<Containers::String>({ |
||||||
|
"-I", "TgaImporter", "--info", Utility::Path::join(TRADE_TEST_DIR, "ImageConverterTestFiles/file.tga")}), |
||||||
|
"TgaImporter", |
||||||
|
"info-data.txt"}, |
||||||
|
{"data, map", Containers::array<Containers::String>({ |
||||||
|
"--map", "-I", "TgaImporter", "--info", Utility::Path::join(TRADE_TEST_DIR, "ImageConverterTestFiles/file.tga")}), |
||||||
|
"TgaImporter", |
||||||
|
/** @todo change to something else once we have a plugin that can
|
||||||
|
zero-copy pass the imported data */ |
||||||
|
"info-data.txt"}, |
||||||
|
{"data, ignored output file", Containers::array<Containers::String>({ |
||||||
|
"-I", "TgaImporter", "--info", Utility::Path::join(TRADE_TEST_DIR, "ImageConverterTestFiles/file.tga"), "whatever.png"}), |
||||||
|
"TgaImporter", |
||||||
|
"info-data-ignored-output.txt"} |
||||||
|
}; |
||||||
|
|
||||||
|
ImageConverterTest::ImageConverterTest() { |
||||||
|
#ifndef CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT |
||||||
|
addInstancedTests({&ImageConverterTest::info}, |
||||||
|
Containers::arraySize(InfoData)); |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Create output dir, if doesn't already exist */ |
||||||
|
Utility::Path::make(Utility::Path::join(TRADE_TEST_OUTPUT_DIR, "ImageConverterTestFiles")); |
||||||
|
} |
||||||
|
|
||||||
|
namespace { |
||||||
|
|
||||||
|
#ifdef IMAGECONVERTER_EXECUTABLE_FILENAME |
||||||
|
/** @todo take a StringIterable once it exists */ |
||||||
|
Containers::Pair<bool, Containers::String> call(Containers::ArrayView<const Containers::String> arguments) { |
||||||
|
/* Create a string view array for the arguments, implicitly pass the
|
||||||
|
application name and plugin directory override */ |
||||||
|
/** @todo drop once StringIterable exists */ |
||||||
|
Containers::Array<Containers::StringView> argumentViews{ValueInit, arguments.size() + 3}; |
||||||
|
argumentViews[0] = ""_s; |
||||||
|
argumentViews[1] = "--plugin-dir"_s; |
||||||
|
argumentViews[2] = MAGNUM_PLUGINS_INSTALL_DIR; |
||||||
|
for(std::size_t i = 0; i != arguments.size(); ++i) |
||||||
|
argumentViews[i + 3] = arguments[i]; |
||||||
|
|
||||||
|
const Containers::String outputFilename = Utility::Path::join(TRADE_TEST_OUTPUT_DIR, "ImageConverterTestFiles/output.txt"); |
||||||
|
/** @todo clean up once Utility::System::execute() with output redirection
|
||||||
|
exists */ |
||||||
|
const bool success = std::system(Utility::format("{} {} > {} 2>&1", |
||||||
|
IMAGECONVERTER_EXECUTABLE_FILENAME, |
||||||
|
" "_s.join(argumentViews), /** @todo handle space escaping here? */ |
||||||
|
outputFilename |
||||||
|
).data()) == 0; |
||||||
|
|
||||||
|
const Containers::Optional<Containers::String> output = Utility::Path::readString(outputFilename); |
||||||
|
CORRADE_VERIFY(output); |
||||||
|
|
||||||
|
return {success, std::move(*output)}; |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void ImageConverterTest::info() { |
||||||
|
auto&& data = InfoData[testCaseInstanceId()]; |
||||||
|
setTestCaseDescription(data.name); |
||||||
|
|
||||||
|
#ifndef IMAGECONVERTER_EXECUTABLE_FILENAME |
||||||
|
CORRADE_SKIP("magnum-imageconverter not built, can't test"); |
||||||
|
#else |
||||||
|
/* Check if required plugins can be loaded. Catches also ABI and interface
|
||||||
|
mismatch errors. */ |
||||||
|
PluginManager::Manager<Trade::AbstractImporter> importerManager{MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR}; |
||||||
|
if(data.requiresImporter && !(importerManager.load(data.requiresImporter) & PluginManager::LoadState::Loaded)) |
||||||
|
CORRADE_SKIP(data.requiresImporter << "plugin can't be loaded."); |
||||||
|
|
||||||
|
CORRADE_VERIFY(true); /* capture correct function name */ |
||||||
|
|
||||||
|
Containers::Pair<bool, Containers::String> output = call(data.args); |
||||||
|
CORRADE_COMPARE_AS(output.second(), |
||||||
|
Utility::Path::join({TRADE_TEST_DIR, "ImageConverterTestFiles", data.expected}), |
||||||
|
TestSuite::Compare::StringToFile); |
||||||
|
CORRADE_VERIFY(output.first()); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
}}}} |
||||||
|
|
||||||
|
CORRADE_TEST_MAIN(Magnum::Trade::Test::ImageConverterTest) |
||||||
Binary file not shown.
@ -0,0 +1,4 @@ |
|||||||
|
Ignoring output file for --info: whatever.png |
||||||
|
2D image 0: |
||||||
|
Level 0: {2, 3} @ R8Unorm (0.0 kB) |
||||||
|
Total image data size: 0.0 kB |
||||||
@ -0,0 +1,3 @@ |
|||||||
|
2D image 0: |
||||||
|
Level 0: {2, 3} @ R8Unorm (0.0 kB) |
||||||
|
Total image data size: 0.0 kB |
||||||
Loading…
Reference in new issue