|
|
|
|
/*
|
|
|
|
|
This file is part of Magnum.
|
|
|
|
|
|
|
|
|
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
|
|
|
|
|
2020, 2021, 2022, 2023 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/Containers/ArrayView.h>
|
|
|
|
|
#include <Corrade/Containers/Optional.h>
|
|
|
|
|
#include <Corrade/Containers/String.h>
|
|
|
|
|
#include <Corrade/TestSuite/Tester.h>
|
|
|
|
|
#include <Corrade/TestSuite/Compare/Container.h>
|
|
|
|
|
#include <Corrade/Utility/Algorithms.h>
|
|
|
|
|
#include <Corrade/Utility/DebugStl.h>
|
|
|
|
|
#include <Corrade/Utility/FormatStl.h>
|
|
|
|
|
#include <Corrade/Utility/Path.h>
|
|
|
|
|
|
Pixel storage support, part 2: renamed ColorFormat to PixelFormat etc.
Yeah, sorry, I know, the enums are renamed for second or third time in a
row, first they were Image::Format, then ImageFormat, then ColorFormat
and now PixelFormat. But this time it's final and last time they are
renamed and now everything is finally consistent:
* ColorFormat::DepthComponent -- depth is not a color, thus
PixelFormat::DepthComponent makes a lot more sense.
* There will be PixelStorage classes, which will be stored in images
alonside PixelFormat/PixelType enums, making everything nicely
aligned.
* The GL documentation about glTexImage2D() etc. denotes the <format>
and <type> parameters as format and type of *pixel* data, so now we
are _finally_ consistent with the official naming.
I wonder why did I not choose PixelFormat originally. Anyway, the old
<Magnum/ColorFormat.h> header, ColorFormat, ColorType and
CompressedColorFormat types are now aliases to the new ones, are marked
as deprecated and will be removed in some future release (as always, I'm
waiting at least six months before removing the deprecated
functionality).
11 years ago
|
|
|
#include "Magnum/PixelFormat.h"
|
plugins: new testing workflow.
The current testing workflow had quite a few major flaws and it was no
longer possible after the move of Any* plugins to core. Among the flaws
is:
* Every plugin was basically built twice, once as the real plugin and
once as a static testing library. Most of the build shared common
object files, but nevertheless it inflated build times and made the
buildsystem extremely complex.
* Because the actual plugin binary was never actually loaded during the
test, it couldn't spot problems like:
- undefined references
- errors in metadata files
- mismatched plugin interface/version, missing entry points
- broken static plugin import files
* Tests that made use of independent plugins (such as TgaImageConverter
test using TgaImporter to verify the output) had a hardcoded
dependency on such plugins, making a minimal setup very hard.
* Dynamic loading of plugins from the Any* proxies was always directed
to the install location on the filesystem with no possibility to
load these directly from the build tree. That caused random ABI
mismatch crashes, or, on the other hand, if no plugins were
installed, particular portions of the codebase weren't tested at all.
Now the workflow is the following:
* Every plugin is built exactly once, either as dynamic or as static.
* The test always loads it via the plugin manager. If it's dynamic,
it's loaded straight from the build directory; if it's static, it
gets linked to the test executable directly.
* Plugins used indirectly are always served from the build directory
(if enabled) to ensure reproducibility and independence on what's
installed on the filesystem. Missing presence of these plugins causes
particular tests to be simply skipped.
* Plugins that have extensive tests for internal functionality that's
not exposed through the plugin interface are still built in two
parts, but the internal tests are simply consuming the OBJECT files
directly instead of linking to a static library.
8 years ago
|
|
|
#include "Magnum/Trade/AbstractImporter.h"
|
|
|
|
|
#include "Magnum/Trade/ImageData.h"
|
|
|
|
|
|
|
|
|
|
#include "configure.h"
|
|
|
|
|
|
|
|
|
|
namespace Magnum { namespace Trade { namespace Test { namespace {
|
|
|
|
|
|
|
|
|
|
struct TgaImporterTest: TestSuite::Tester {
|
|
|
|
|
explicit TgaImporterTest();
|
|
|
|
|
|
|
|
|
|
void invalidEmpty();
|
|
|
|
|
void invalidShort();
|
|
|
|
|
void invalid();
|
|
|
|
|
void invalidBits();
|
|
|
|
|
|
|
|
|
|
void color24();
|
|
|
|
|
void color24Rle();
|
|
|
|
|
void color32();
|
|
|
|
|
void color32Rle();
|
|
|
|
|
void grayscale8();
|
|
|
|
|
void grayscale8Rle();
|
|
|
|
|
|
|
|
|
|
void tga2();
|
|
|
|
|
void fileTooLong();
|
|
|
|
|
|
|
|
|
|
void openMemory();
|
|
|
|
|
void openTwice();
|
|
|
|
|
void importTwice();
|
plugins: new testing workflow.
The current testing workflow had quite a few major flaws and it was no
longer possible after the move of Any* plugins to core. Among the flaws
is:
* Every plugin was basically built twice, once as the real plugin and
once as a static testing library. Most of the build shared common
object files, but nevertheless it inflated build times and made the
buildsystem extremely complex.
* Because the actual plugin binary was never actually loaded during the
test, it couldn't spot problems like:
- undefined references
- errors in metadata files
- mismatched plugin interface/version, missing entry points
- broken static plugin import files
* Tests that made use of independent plugins (such as TgaImageConverter
test using TgaImporter to verify the output) had a hardcoded
dependency on such plugins, making a minimal setup very hard.
* Dynamic loading of plugins from the Any* proxies was always directed
to the install location on the filesystem with no possibility to
load these directly from the build tree. That caused random ABI
mismatch crashes, or, on the other hand, if no plugins were
installed, particular portions of the codebase weren't tested at all.
Now the workflow is the following:
* Every plugin is built exactly once, either as dynamic or as static.
* The test always loads it via the plugin manager. If it's dynamic,
it's loaded straight from the build directory; if it's static, it
gets linked to the test executable directly.
* Plugins used indirectly are always served from the build directory
(if enabled) to ensure reproducibility and independence on what's
installed on the filesystem. Missing presence of these plugins causes
particular tests to be simply skipped.
* Plugins that have extensive tests for internal functionality that's
not exposed through the plugin interface are still built in two
parts, but the internal tests are simply consuming the OBJECT files
directly instead of linking to a static library.
8 years ago
|
|
|
|
|
|
|
|
/* Explicitly forbid system-wide plugin dependencies */
|
|
|
|
|
PluginManager::Manager<AbstractImporter> _manager{"nonexistent"};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr const char Grayscale8[]{
|
|
|
|
|
0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 8, 0,
|
|
|
|
|
1, 2,
|
|
|
|
|
3, 4,
|
|
|
|
|
5, 6,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr const char Grayscale8Rle[]{
|
|
|
|
|
0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 8, 0,
|
|
|
|
|
/* 2 pixels as-is */
|
|
|
|
|
'\x01', 1, 2,
|
|
|
|
|
/* 1 pixel 2x repeated */
|
|
|
|
|
'\x81', 3,
|
|
|
|
|
/* 1 pixel as-is */
|
|
|
|
|
'\x00', 5,
|
|
|
|
|
/* 1 pixel 1x repeated */
|
|
|
|
|
'\x00', 6
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr const char Color24[] = {
|
|
|
|
|
0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0,
|
|
|
|
|
1, 2, 3, 2, 3, 4,
|
|
|
|
|
3, 4, 5, 4, 5, 6,
|
|
|
|
|
5, 6, 7, 6, 7, 8
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr const char Color24Rle[] = {
|
|
|
|
|
0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0,
|
|
|
|
|
/* 3 pixels as-is */
|
|
|
|
|
'\x02', 1, 2, 3,
|
|
|
|
|
2, 3, 4,
|
|
|
|
|
3, 4, 5,
|
|
|
|
|
/* 1 pixel 3x repeated */
|
|
|
|
|
'\x82', 4, 5, 6
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Separate from ErrorData so we can just slice existing arrays instead of
|
|
|
|
|
creating new ones from scratch */
|
|
|
|
|
const struct {
|
|
|
|
|
const char* name;
|
|
|
|
|
Containers::ArrayView<const char> data;
|
|
|
|
|
const char* message;
|
|
|
|
|
} InvalidShortData[] {
|
|
|
|
|
{"short header", Containers::arrayView(Color24).prefix(17),
|
|
|
|
|
"file too short, expected at least 18 bytes but got 17"},
|
|
|
|
|
{"short data", Containers::arrayView(Color24).exceptSuffix(1),
|
|
|
|
|
"file too short, expected 36 bytes but got 35"},
|
|
|
|
|
{"short RLE data", Containers::arrayView(Color24Rle).exceptSuffix(1),
|
|
|
|
|
"RLE file too short at pixel 3"},
|
|
|
|
|
{"short RLE raw data", Containers::arrayView(Color24Rle).exceptSuffix(5),
|
|
|
|
|
"RLE file too short at pixel 0"}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const struct {
|
|
|
|
|
const char* name;
|
|
|
|
|
char imageType;
|
|
|
|
|
char bpp;
|
|
|
|
|
const char* message;
|
|
|
|
|
} InvalidBitsData[] {
|
|
|
|
|
{"color 16", 2, 16, "unsupported color bits-per-pixel: 16"},
|
|
|
|
|
{"grayscale 16", 3, 16, "unsupported grayscale bits-per-pixel: 16"},
|
|
|
|
|
{"RLE color 16", 10, 16, "unsupported color bits-per-pixel: 16"},
|
|
|
|
|
{"RLE grayscale 16", 11, 16, "unsupported grayscale bits-per-pixel: 16"}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const struct {
|
|
|
|
|
const char* name;
|
|
|
|
|
Containers::Array<char> data;
|
|
|
|
|
const char* message;
|
|
|
|
|
} InvalidData[]{
|
|
|
|
|
{"paletted", {InPlaceInit, {
|
|
|
|
|
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
|
|
}}, "paletted files are not supported"},
|
|
|
|
|
{"invalid image type", {InPlaceInit, {
|
|
|
|
|
0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
|
|
}}, "unsupported image type: 9"},
|
|
|
|
|
{"TGA 2 file too short", {InPlaceInit, {
|
|
|
|
|
0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0,
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, /* One byte for the sizes missing here */
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}, "TGA 2 file too short, expected at least 44 bytes but got 43"},
|
|
|
|
|
{"TGA 2 extension offset overlaps with file header", {InPlaceInit, {
|
|
|
|
|
0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0,
|
|
|
|
|
17, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}, "TGA 2 extension offset 17 overlaps with file header"},
|
|
|
|
|
{"TGA 2 extension offset overlaps with file footer", {InPlaceInit, {
|
|
|
|
|
0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0,
|
|
|
|
|
19, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}, "TGA 2 extension offset 19 out of range for 44 bytes and a 26-byte file footer"},
|
|
|
|
|
{"TGA 2 developer area offset overlaps with file header", {InPlaceInit, {
|
|
|
|
|
0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0,
|
|
|
|
|
0, 0, 0, 0, 17, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}, "TGA 2 developer area offset 17 overlaps with file header"},
|
|
|
|
|
{"TGA 2 developer area offset overlaps with file footer", {InPlaceInit, {
|
|
|
|
|
0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0,
|
|
|
|
|
0, 0, 0, 0, 19, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}, "TGA 2 developer area offset 19 out of range for 44 bytes and a 26-byte file footer"},
|
|
|
|
|
{"TGA 2 developer area offset overlaps with extension area", {InPlaceInit, {
|
|
|
|
|
0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0,
|
|
|
|
|
'\xdd', '\xee', '\xee',
|
|
|
|
|
19, 0, 0, 0, 18, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}, "TGA 2 developer area offset 18 overlaps with extensions at 19 bytes"},
|
|
|
|
|
{"RLE too large", {InPlaceInit, {
|
|
|
|
|
0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0,
|
|
|
|
|
/* 3 pixels as-is */
|
|
|
|
|
'\x02', 1, 2, 3,
|
|
|
|
|
2, 3, 4,
|
|
|
|
|
3, 4, 5,
|
|
|
|
|
/* 1 pixel 4x repeated (one more than it should be) */
|
|
|
|
|
'\x83', 4, 5, 6
|
|
|
|
|
}}, "RLE data at byte 28 contains 4 pixels but only 3 left to decode"},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const struct {
|
|
|
|
|
const char* name;
|
|
|
|
|
ImporterFlags flags;
|
|
|
|
|
const char* message24;
|
|
|
|
|
const char* message32;
|
|
|
|
|
} VerboseData[] {
|
|
|
|
|
{"", {}, "", ""},
|
|
|
|
|
{"verbose", ImporterFlag::Verbose,
|
|
|
|
|
"Trade::TgaImporter::image2D(): converting from BGR to RGB\n",
|
|
|
|
|
"Trade::TgaImporter::image2D(): converting from BGRA to RGBA\n"}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Tga2Data footer offsets rely on this */
|
|
|
|
|
static_assert(sizeof(Grayscale8Rle) == 27, "size of grayscale data not 27 bytes");
|
|
|
|
|
const struct {
|
|
|
|
|
const char* name;
|
|
|
|
|
Containers::Array<char> footer;
|
|
|
|
|
} Tga2Data[]{
|
|
|
|
|
{"just the footer", {InPlaceInit, {
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}},
|
|
|
|
|
{"extension", {InPlaceInit, {
|
|
|
|
|
'\xee', '\xee',
|
|
|
|
|
27, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}},
|
|
|
|
|
{"developer area", {InPlaceInit, {
|
|
|
|
|
'\xdd', '\xdd',
|
|
|
|
|
0, 0, 0, 0, 27, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}},
|
|
|
|
|
{"both extension and developer area", {InPlaceInit, {
|
|
|
|
|
'\xee', '\xee', '\xee', '\xdd', '\xdd', '\xdd', '\xdd', '\xdd',
|
|
|
|
|
27, 0, 0, 0, 30, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}},
|
|
|
|
|
{"empty extension area", {InPlaceInit, {
|
|
|
|
|
27, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}},
|
|
|
|
|
{"empty developer area", {InPlaceInit, {
|
|
|
|
|
0, 0, 0, 0, 27, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}},
|
|
|
|
|
{"empty extension and developer area", {InPlaceInit, {
|
|
|
|
|
27, 0, 0, 0, 27, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const struct {
|
|
|
|
|
const char* name;
|
|
|
|
|
Containers::Array<char> extra;
|
|
|
|
|
ImporterFlags flags;
|
|
|
|
|
bool quiet;
|
|
|
|
|
} FileTooLongData[]{
|
|
|
|
|
{"", {InPlaceInit, {
|
|
|
|
|
'e', 'x', 't', 'r', 'a'
|
|
|
|
|
}}, {}, false},
|
|
|
|
|
{"TGA 2", {InPlaceInit, {
|
|
|
|
|
'e', 'x', 't', 'r', 'a',
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', '\0'
|
|
|
|
|
}}, ImporterFlag::Quiet, true},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Shared among all plugins that implement data copying optimizations */
|
|
|
|
|
const struct {
|
|
|
|
|
const char* name;
|
|
|
|
|
bool(*open)(AbstractImporter&, Containers::ArrayView<const void>);
|
|
|
|
|
} OpenMemoryData[]{
|
|
|
|
|
{"data", [](AbstractImporter& importer, Containers::ArrayView<const void> data) {
|
|
|
|
|
/* Copy to ensure the original memory isn't referenced */
|
|
|
|
|
Containers::Array<char> copy{NoInit, data.size()};
|
|
|
|
|
Utility::copy(Containers::arrayCast<const char>(data), copy);
|
|
|
|
|
return importer.openData(copy);
|
|
|
|
|
}},
|
|
|
|
|
{"memory", [](AbstractImporter& importer, Containers::ArrayView<const void> data) {
|
|
|
|
|
return importer.openMemory(data);
|
|
|
|
|
}},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TgaImporterTest::TgaImporterTest() {
|
|
|
|
|
addTests({&TgaImporterTest::invalidEmpty});
|
|
|
|
|
|
|
|
|
|
addInstancedTests({&TgaImporterTest::invalidShort},
|
|
|
|
|
Containers::arraySize(InvalidShortData));
|
|
|
|
|
|
|
|
|
|
addInstancedTests({&TgaImporterTest::invalid},
|
|
|
|
|
Containers::arraySize(InvalidData));
|
|
|
|
|
|
|
|
|
|
addInstancedTests({&TgaImporterTest::invalidBits},
|
|
|
|
|
Containers::arraySize(InvalidBitsData));
|
|
|
|
|
|
|
|
|
|
addInstancedTests({
|
|
|
|
|
&TgaImporterTest::color24,
|
|
|
|
|
&TgaImporterTest::color24Rle,
|
|
|
|
|
&TgaImporterTest::color32,
|
|
|
|
|
&TgaImporterTest::color32Rle},
|
|
|
|
|
Containers::arraySize(VerboseData));
|
|
|
|
|
|
|
|
|
|
addTests({&TgaImporterTest::grayscale8,
|
|
|
|
|
&TgaImporterTest::grayscale8Rle});
|
|
|
|
|
|
|
|
|
|
addInstancedTests({&TgaImporterTest::tga2},
|
|
|
|
|
Containers::arraySize(Tga2Data));
|
|
|
|
|
|
|
|
|
|
addInstancedTests({&TgaImporterTest::fileTooLong},
|
|
|
|
|
Containers::arraySize(FileTooLongData));
|
|
|
|
|
|
|
|
|
|
addInstancedTests({&TgaImporterTest::openMemory},
|
|
|
|
|
Containers::arraySize(OpenMemoryData));
|
|
|
|
|
|
|
|
|
|
addTests({&TgaImporterTest::openTwice,
|
|
|
|
|
&TgaImporterTest::importTwice});
|
plugins: new testing workflow.
The current testing workflow had quite a few major flaws and it was no
longer possible after the move of Any* plugins to core. Among the flaws
is:
* Every plugin was basically built twice, once as the real plugin and
once as a static testing library. Most of the build shared common
object files, but nevertheless it inflated build times and made the
buildsystem extremely complex.
* Because the actual plugin binary was never actually loaded during the
test, it couldn't spot problems like:
- undefined references
- errors in metadata files
- mismatched plugin interface/version, missing entry points
- broken static plugin import files
* Tests that made use of independent plugins (such as TgaImageConverter
test using TgaImporter to verify the output) had a hardcoded
dependency on such plugins, making a minimal setup very hard.
* Dynamic loading of plugins from the Any* proxies was always directed
to the install location on the filesystem with no possibility to
load these directly from the build tree. That caused random ABI
mismatch crashes, or, on the other hand, if no plugins were
installed, particular portions of the codebase weren't tested at all.
Now the workflow is the following:
* Every plugin is built exactly once, either as dynamic or as static.
* The test always loads it via the plugin manager. If it's dynamic,
it's loaded straight from the build directory; if it's static, it
gets linked to the test executable directly.
* Plugins used indirectly are always served from the build directory
(if enabled) to ensure reproducibility and independence on what's
installed on the filesystem. Missing presence of these plugins causes
particular tests to be simply skipped.
* Plugins that have extensive tests for internal functionality that's
not exposed through the plugin interface are still built in two
parts, but the internal tests are simply consuming the OBJECT files
directly instead of linking to a static library.
8 years ago
|
|
|
|
|
|
|
|
/* Load the plugin directly from the build tree. Otherwise it's static and
|
|
|
|
|
already loaded. */
|
|
|
|
|
#ifdef TGAIMPORTER_PLUGIN_FILENAME
|
|
|
|
|
CORRADE_INTERNAL_ASSERT_OUTPUT(_manager.load(TGAIMPORTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded);
|
plugins: new testing workflow.
The current testing workflow had quite a few major flaws and it was no
longer possible after the move of Any* plugins to core. Among the flaws
is:
* Every plugin was basically built twice, once as the real plugin and
once as a static testing library. Most of the build shared common
object files, but nevertheless it inflated build times and made the
buildsystem extremely complex.
* Because the actual plugin binary was never actually loaded during the
test, it couldn't spot problems like:
- undefined references
- errors in metadata files
- mismatched plugin interface/version, missing entry points
- broken static plugin import files
* Tests that made use of independent plugins (such as TgaImageConverter
test using TgaImporter to verify the output) had a hardcoded
dependency on such plugins, making a minimal setup very hard.
* Dynamic loading of plugins from the Any* proxies was always directed
to the install location on the filesystem with no possibility to
load these directly from the build tree. That caused random ABI
mismatch crashes, or, on the other hand, if no plugins were
installed, particular portions of the codebase weren't tested at all.
Now the workflow is the following:
* Every plugin is built exactly once, either as dynamic or as static.
* The test always loads it via the plugin manager. If it's dynamic,
it's loaded straight from the build directory; if it's static, it
gets linked to the test executable directly.
* Plugins used indirectly are always served from the build directory
(if enabled) to ensure reproducibility and independence on what's
installed on the filesystem. Missing presence of these plugins causes
particular tests to be simply skipped.
* Plugins that have extensive tests for internal functionality that's
not exposed through the plugin interface are still built in two
parts, but the internal tests are simply consuming the OBJECT files
directly instead of linking to a static library.
8 years ago
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::invalidEmpty() {
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
Error redirectError{&out};
|
|
|
|
|
char a{};
|
|
|
|
|
/* Explicitly checking non-null but empty view */
|
|
|
|
|
CORRADE_VERIFY(!importer->openData({&a, 0}));
|
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::TgaImporter::openData(): the file is empty\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::invalidShort() {
|
|
|
|
|
auto&& data = InvalidShortData[testCaseInstanceId()];
|
|
|
|
|
setTestCaseDescription(data.name);
|
|
|
|
|
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
|
|
|
|
|
CORRADE_VERIFY(importer->openData(data.data));
|
|
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
Error redirectError{&out};
|
|
|
|
|
CORRADE_VERIFY(!importer->image2D(0));
|
|
|
|
|
CORRADE_COMPARE(out.str(), Utility::formatString("Trade::TgaImporter::image2D(): {}\n", data.message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::invalid() {
|
|
|
|
|
auto&& data = InvalidData[testCaseInstanceId()];
|
|
|
|
|
setTestCaseDescription(data.name);
|
|
|
|
|
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
|
|
|
|
|
CORRADE_VERIFY(importer->openData(data.data));
|
|
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
Error redirectError{&out};
|
plugins: new testing workflow.
The current testing workflow had quite a few major flaws and it was no
longer possible after the move of Any* plugins to core. Among the flaws
is:
* Every plugin was basically built twice, once as the real plugin and
once as a static testing library. Most of the build shared common
object files, but nevertheless it inflated build times and made the
buildsystem extremely complex.
* Because the actual plugin binary was never actually loaded during the
test, it couldn't spot problems like:
- undefined references
- errors in metadata files
- mismatched plugin interface/version, missing entry points
- broken static plugin import files
* Tests that made use of independent plugins (such as TgaImageConverter
test using TgaImporter to verify the output) had a hardcoded
dependency on such plugins, making a minimal setup very hard.
* Dynamic loading of plugins from the Any* proxies was always directed
to the install location on the filesystem with no possibility to
load these directly from the build tree. That caused random ABI
mismatch crashes, or, on the other hand, if no plugins were
installed, particular portions of the codebase weren't tested at all.
Now the workflow is the following:
* Every plugin is built exactly once, either as dynamic or as static.
* The test always loads it via the plugin manager. If it's dynamic,
it's loaded straight from the build directory; if it's static, it
gets linked to the test executable directly.
* Plugins used indirectly are always served from the build directory
(if enabled) to ensure reproducibility and independence on what's
installed on the filesystem. Missing presence of these plugins causes
particular tests to be simply skipped.
* Plugins that have extensive tests for internal functionality that's
not exposed through the plugin interface are still built in two
parts, but the internal tests are simply consuming the OBJECT files
directly instead of linking to a static library.
8 years ago
|
|
|
CORRADE_VERIFY(!importer->image2D(0));
|
|
|
|
|
CORRADE_COMPARE(out.str(), Utility::formatString("Trade::TgaImporter::image2D(): {}\n", data.message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::invalidBits() {
|
|
|
|
|
auto&& data = InvalidBitsData[testCaseInstanceId()];
|
|
|
|
|
setTestCaseDescription(data.name);
|
|
|
|
|
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
const char imageData[]{
|
|
|
|
|
0, 0, data.imageType, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, data.bpp, 0
|
|
|
|
|
};
|
|
|
|
|
CORRADE_VERIFY(importer->openData(imageData));
|
|
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
Error redirectError{&out};
|
plugins: new testing workflow.
The current testing workflow had quite a few major flaws and it was no
longer possible after the move of Any* plugins to core. Among the flaws
is:
* Every plugin was basically built twice, once as the real plugin and
once as a static testing library. Most of the build shared common
object files, but nevertheless it inflated build times and made the
buildsystem extremely complex.
* Because the actual plugin binary was never actually loaded during the
test, it couldn't spot problems like:
- undefined references
- errors in metadata files
- mismatched plugin interface/version, missing entry points
- broken static plugin import files
* Tests that made use of independent plugins (such as TgaImageConverter
test using TgaImporter to verify the output) had a hardcoded
dependency on such plugins, making a minimal setup very hard.
* Dynamic loading of plugins from the Any* proxies was always directed
to the install location on the filesystem with no possibility to
load these directly from the build tree. That caused random ABI
mismatch crashes, or, on the other hand, if no plugins were
installed, particular portions of the codebase weren't tested at all.
Now the workflow is the following:
* Every plugin is built exactly once, either as dynamic or as static.
* The test always loads it via the plugin manager. If it's dynamic,
it's loaded straight from the build directory; if it's static, it
gets linked to the test executable directly.
* Plugins used indirectly are always served from the build directory
(if enabled) to ensure reproducibility and independence on what's
installed on the filesystem. Missing presence of these plugins causes
particular tests to be simply skipped.
* Plugins that have extensive tests for internal functionality that's
not exposed through the plugin interface are still built in two
parts, but the internal tests are simply consuming the OBJECT files
directly instead of linking to a static library.
8 years ago
|
|
|
CORRADE_VERIFY(!importer->image2D(0));
|
|
|
|
|
CORRADE_COMPARE(out.str(), Utility::formatString("Trade::TgaImporter::image2D(): {}\n", data.message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::color24() {
|
|
|
|
|
auto&& data = VerboseData[testCaseInstanceId()];
|
|
|
|
|
setTestCaseDescription(data.name);
|
|
|
|
|
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
importer->setFlags(data.flags);
|
|
|
|
|
CORRADE_VERIFY(importer->openData(Color24));
|
|
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
Containers::Optional<Trade::ImageData2D> image;
|
|
|
|
|
{
|
|
|
|
|
Debug redirectOutput{&out};
|
|
|
|
|
image = importer->image2D(0);
|
|
|
|
|
}
|
|
|
|
|
CORRADE_VERIFY(image);
|
|
|
|
|
CORRADE_COMPARE(image->flags(), ImageFlags2D{});
|
|
|
|
|
CORRADE_COMPARE(image->storage().alignment(), 1);
|
|
|
|
|
CORRADE_COMPARE(image->format(), PixelFormat::RGB8Unorm);
|
|
|
|
|
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
|
|
|
|
|
CORRADE_COMPARE_AS(image->data(), Containers::arrayView<char>({
|
|
|
|
|
3, 2, 1, 4, 3, 2,
|
|
|
|
|
5, 4, 3, 6, 5, 4,
|
|
|
|
|
7, 6, 5, 8, 7, 6
|
|
|
|
|
}), TestSuite::Compare::Container);
|
|
|
|
|
CORRADE_COMPARE(out.str(), data.message24);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::color24Rle() {
|
|
|
|
|
auto&& data = VerboseData[testCaseInstanceId()];
|
|
|
|
|
setTestCaseDescription(data.name);
|
|
|
|
|
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
importer->setFlags(data.flags);
|
|
|
|
|
CORRADE_VERIFY(importer->openData(Color24Rle));
|
|
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
Containers::Optional<Trade::ImageData2D> image;
|
|
|
|
|
{
|
|
|
|
|
Debug redirectOutput{&out};
|
|
|
|
|
image = importer->image2D(0);
|
|
|
|
|
}
|
|
|
|
|
CORRADE_VERIFY(image);
|
|
|
|
|
CORRADE_COMPARE(image->flags(), ImageFlags2D{});
|
|
|
|
|
CORRADE_COMPARE(image->storage().alignment(), 1);
|
|
|
|
|
CORRADE_COMPARE(image->format(), PixelFormat::RGB8Unorm);
|
|
|
|
|
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
|
|
|
|
|
CORRADE_COMPARE_AS(image->data(), Containers::arrayView<char>({
|
|
|
|
|
3, 2, 1, 4, 3, 2,
|
|
|
|
|
5, 4, 3, 6, 5, 4,
|
|
|
|
|
6, 5, 4, 6, 5, 4
|
|
|
|
|
}), TestSuite::Compare::Container);
|
|
|
|
|
CORRADE_COMPARE(out.str(), data.message24);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::color32() {
|
|
|
|
|
auto&& data = VerboseData[testCaseInstanceId()];
|
|
|
|
|
setTestCaseDescription(data.name);
|
|
|
|
|
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
importer->setFlags(data.flags);
|
|
|
|
|
const char input[] = {
|
|
|
|
|
0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 32, 0,
|
|
|
|
|
1, 2, 3, 4, 2, 3, 4, 5,
|
|
|
|
|
3, 4, 5, 6, 4, 5, 6, 7,
|
|
|
|
|
5, 6, 7, 8, 6, 7, 8, 9
|
|
|
|
|
};
|
|
|
|
|
CORRADE_VERIFY(importer->openData(input));
|
|
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
Containers::Optional<Trade::ImageData2D> image;
|
|
|
|
|
{
|
|
|
|
|
Debug redirectOutput{&out};
|
|
|
|
|
image = importer->image2D(0);
|
|
|
|
|
}
|
|
|
|
|
CORRADE_VERIFY(image);
|
|
|
|
|
CORRADE_COMPARE(image->flags(), ImageFlags2D{});
|
|
|
|
|
CORRADE_COMPARE(image->storage().alignment(), 4);
|
|
|
|
|
CORRADE_COMPARE(image->format(), PixelFormat::RGBA8Unorm);
|
|
|
|
|
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
|
|
|
|
|
CORRADE_COMPARE_AS(image->data(), Containers::arrayView<char>({
|
|
|
|
|
3, 2, 1, 4, 4, 3, 2, 5,
|
|
|
|
|
5, 4, 3, 6, 6, 5, 4, 7,
|
|
|
|
|
7, 6, 5, 8, 8, 7, 6, 9
|
|
|
|
|
}), TestSuite::Compare::Container);
|
|
|
|
|
CORRADE_COMPARE(out.str(), data.message32);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::color32Rle() {
|
|
|
|
|
auto&& data = VerboseData[testCaseInstanceId()];
|
|
|
|
|
setTestCaseDescription(data.name);
|
|
|
|
|
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
importer->setFlags(data.flags);
|
|
|
|
|
const char input[] = {
|
|
|
|
|
0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 32, 0,
|
|
|
|
|
/* 2 pixels repeated */
|
|
|
|
|
'\x81', 1, 2, 3, 4,
|
|
|
|
|
/* 4 pixels as-is */
|
|
|
|
|
'\x03', 3, 4, 5, 6,
|
|
|
|
|
4, 5, 6, 7,
|
|
|
|
|
5, 6, 7, 8,
|
|
|
|
|
6, 7, 8, 9
|
|
|
|
|
};
|
|
|
|
|
CORRADE_VERIFY(importer->openData(input));
|
|
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
Containers::Optional<Trade::ImageData2D> image;
|
|
|
|
|
{
|
|
|
|
|
Debug redirectOutput{&out};
|
|
|
|
|
image = importer->image2D(0);
|
|
|
|
|
}
|
|
|
|
|
CORRADE_VERIFY(image);
|
|
|
|
|
CORRADE_COMPARE(image->flags(), ImageFlags2D{});
|
|
|
|
|
CORRADE_COMPARE(image->storage().alignment(), 4);
|
|
|
|
|
CORRADE_COMPARE(image->format(), PixelFormat::RGBA8Unorm);
|
|
|
|
|
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
|
|
|
|
|
CORRADE_COMPARE_AS(image->data(), Containers::arrayView<char>({
|
|
|
|
|
3, 2, 1, 4, 3, 2, 1, 4,
|
|
|
|
|
5, 4, 3, 6, 6, 5, 4, 7,
|
|
|
|
|
7, 6, 5, 8, 8, 7, 6, 9
|
|
|
|
|
}), TestSuite::Compare::Container);
|
|
|
|
|
CORRADE_COMPARE(out.str(), data.message32);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::grayscale8() {
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
CORRADE_VERIFY(importer->openData(Grayscale8));
|
|
|
|
|
|
plugins: new testing workflow.
The current testing workflow had quite a few major flaws and it was no
longer possible after the move of Any* plugins to core. Among the flaws
is:
* Every plugin was basically built twice, once as the real plugin and
once as a static testing library. Most of the build shared common
object files, but nevertheless it inflated build times and made the
buildsystem extremely complex.
* Because the actual plugin binary was never actually loaded during the
test, it couldn't spot problems like:
- undefined references
- errors in metadata files
- mismatched plugin interface/version, missing entry points
- broken static plugin import files
* Tests that made use of independent plugins (such as TgaImageConverter
test using TgaImporter to verify the output) had a hardcoded
dependency on such plugins, making a minimal setup very hard.
* Dynamic loading of plugins from the Any* proxies was always directed
to the install location on the filesystem with no possibility to
load these directly from the build tree. That caused random ABI
mismatch crashes, or, on the other hand, if no plugins were
installed, particular portions of the codebase weren't tested at all.
Now the workflow is the following:
* Every plugin is built exactly once, either as dynamic or as static.
* The test always loads it via the plugin manager. If it's dynamic,
it's loaded straight from the build directory; if it's static, it
gets linked to the test executable directly.
* Plugins used indirectly are always served from the build directory
(if enabled) to ensure reproducibility and independence on what's
installed on the filesystem. Missing presence of these plugins causes
particular tests to be simply skipped.
* Plugins that have extensive tests for internal functionality that's
not exposed through the plugin interface are still built in two
parts, but the internal tests are simply consuming the OBJECT files
directly instead of linking to a static library.
8 years ago
|
|
|
Containers::Optional<Trade::ImageData2D> image = importer->image2D(0);
|
|
|
|
|
CORRADE_VERIFY(image);
|
|
|
|
|
CORRADE_COMPARE(image->flags(), ImageFlags2D{});
|
|
|
|
|
CORRADE_COMPARE(image->storage().alignment(), 1);
|
|
|
|
|
CORRADE_COMPARE(image->format(), PixelFormat::R8Unorm);
|
|
|
|
|
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
|
|
|
|
|
CORRADE_COMPARE_AS(image->data(), Containers::arrayView<char>({
|
|
|
|
|
1, 2,
|
|
|
|
|
3, 4,
|
|
|
|
|
5, 6
|
|
|
|
|
}), TestSuite::Compare::Container);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::grayscale8Rle() {
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
CORRADE_VERIFY(importer->openData(Grayscale8Rle));
|
|
|
|
|
|
|
|
|
|
Containers::Optional<Trade::ImageData2D> image = importer->image2D(0);
|
|
|
|
|
CORRADE_VERIFY(image);
|
|
|
|
|
CORRADE_COMPARE(image->flags(), ImageFlags2D{});
|
|
|
|
|
CORRADE_COMPARE(image->storage().alignment(), 1);
|
|
|
|
|
CORRADE_COMPARE(image->format(), PixelFormat::R8Unorm);
|
|
|
|
|
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
|
|
|
|
|
CORRADE_COMPARE_AS(image->data(), Containers::arrayView<char>({
|
|
|
|
|
1, 2,
|
|
|
|
|
3, 3,
|
|
|
|
|
5, 6
|
|
|
|
|
}), TestSuite::Compare::Container);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::tga2() {
|
|
|
|
|
auto&& data = Tga2Data[testCaseInstanceId()];
|
|
|
|
|
setTestCaseDescription(data.name);
|
|
|
|
|
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
|
|
|
|
|
/* The actual image data is always the same, only the footer differs */
|
|
|
|
|
CORRADE_VERIFY(importer->openData(
|
|
|
|
|
Containers::StringView{Containers::arrayView(Grayscale8Rle)} +
|
|
|
|
|
Containers::StringView{data.footer}));
|
|
|
|
|
|
|
|
|
|
Containers::Optional<Trade::ImageData2D> image = importer->image2D(0);
|
|
|
|
|
CORRADE_VERIFY(image);
|
|
|
|
|
CORRADE_COMPARE(image->flags(), ImageFlags2D{});
|
|
|
|
|
CORRADE_COMPARE(image->storage().alignment(), 1);
|
|
|
|
|
CORRADE_COMPARE(image->format(), PixelFormat::R8Unorm);
|
|
|
|
|
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
|
|
|
|
|
CORRADE_COMPARE_AS(image->data(), Containers::arrayView<char>({
|
|
|
|
|
1, 2,
|
|
|
|
|
3, 3,
|
|
|
|
|
5, 6
|
|
|
|
|
}), TestSuite::Compare::Container);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::fileTooLong() {
|
|
|
|
|
auto&& data = FileTooLongData[testCaseInstanceId()];
|
|
|
|
|
setTestCaseDescription(data.name);
|
|
|
|
|
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
importer->setFlags(data.flags);
|
|
|
|
|
|
|
|
|
|
/* The actual image data is always the same, only the end differs */
|
|
|
|
|
CORRADE_VERIFY(importer->openData(
|
|
|
|
|
Containers::StringView{Containers::arrayView(Grayscale8)} +
|
|
|
|
|
Containers::StringView{data.extra}));
|
|
|
|
|
|
|
|
|
|
Containers::Optional<Trade::ImageData2D> image;
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
{
|
|
|
|
|
Warning redirectWarning{&out};
|
|
|
|
|
image = importer->image2D(0);
|
|
|
|
|
}
|
|
|
|
|
CORRADE_VERIFY(image);
|
|
|
|
|
CORRADE_COMPARE(image->flags(), ImageFlags2D{});
|
|
|
|
|
CORRADE_COMPARE(image->storage().alignment(), 1);
|
|
|
|
|
CORRADE_COMPARE(image->format(), PixelFormat::R8Unorm);
|
|
|
|
|
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
|
|
|
|
|
CORRADE_COMPARE_AS(image->data(), Containers::arrayView<char>({
|
|
|
|
|
1, 2,
|
|
|
|
|
3, 4,
|
|
|
|
|
5, 6
|
|
|
|
|
}), TestSuite::Compare::Container);
|
|
|
|
|
if(data.quiet)
|
|
|
|
|
CORRADE_COMPARE(out.str(), "");
|
|
|
|
|
else
|
|
|
|
|
CORRADE_COMPARE(out.str(), "Trade::TgaImporter::image2D(): ignoring 5 extra bytes at the end of image data\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::openMemory() {
|
|
|
|
|
/* same as color24() except that it uses openData() & openMemory() to test
|
|
|
|
|
data copying on import */
|
|
|
|
|
|
|
|
|
|
auto&& data = OpenMemoryData[testCaseInstanceId()];
|
|
|
|
|
setTestCaseDescription(data.name);
|
|
|
|
|
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
/* Eh fuck off, GCC, why can't you convert the array to an ArrayView on
|
|
|
|
|
your own if it's passed to a function pointer?! Clang can. */
|
|
|
|
|
CORRADE_VERIFY(data.open(*importer, Containers::arrayView(Color24)));
|
|
|
|
|
|
|
|
|
|
Containers::Optional<Trade::ImageData2D> image = importer->image2D(0);
|
|
|
|
|
CORRADE_VERIFY(image);
|
|
|
|
|
CORRADE_COMPARE(image->flags(), ImageFlags2D{});
|
|
|
|
|
CORRADE_COMPARE(image->storage().alignment(), 1);
|
|
|
|
|
CORRADE_COMPARE(image->format(), PixelFormat::RGB8Unorm);
|
|
|
|
|
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
|
|
|
|
|
CORRADE_COMPARE_AS(image->data(), Containers::arrayView<char>({
|
|
|
|
|
3, 2, 1, 4, 3, 2,
|
|
|
|
|
5, 4, 3, 6, 5, 4,
|
|
|
|
|
7, 6, 5, 8, 7, 6
|
|
|
|
|
}), TestSuite::Compare::Container);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::openTwice() {
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
|
|
|
|
|
CORRADE_VERIFY(importer->openFile(Utility::Path::join(TGAIMPORTER_TEST_DIR, "file.tga")));
|
|
|
|
|
CORRADE_VERIFY(importer->openFile(Utility::Path::join(TGAIMPORTER_TEST_DIR, "file.tga")));
|
|
|
|
|
|
|
|
|
|
/* Shouldn't crash, leak or anything */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TgaImporterTest::importTwice() {
|
|
|
|
|
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("TgaImporter");
|
|
|
|
|
CORRADE_VERIFY(importer->openFile(Utility::Path::join(TGAIMPORTER_TEST_DIR, "file.tga")));
|
|
|
|
|
|
|
|
|
|
/* Verify that everything is working the same way on second use */
|
|
|
|
|
{
|
plugins: new testing workflow.
The current testing workflow had quite a few major flaws and it was no
longer possible after the move of Any* plugins to core. Among the flaws
is:
* Every plugin was basically built twice, once as the real plugin and
once as a static testing library. Most of the build shared common
object files, but nevertheless it inflated build times and made the
buildsystem extremely complex.
* Because the actual plugin binary was never actually loaded during the
test, it couldn't spot problems like:
- undefined references
- errors in metadata files
- mismatched plugin interface/version, missing entry points
- broken static plugin import files
* Tests that made use of independent plugins (such as TgaImageConverter
test using TgaImporter to verify the output) had a hardcoded
dependency on such plugins, making a minimal setup very hard.
* Dynamic loading of plugins from the Any* proxies was always directed
to the install location on the filesystem with no possibility to
load these directly from the build tree. That caused random ABI
mismatch crashes, or, on the other hand, if no plugins were
installed, particular portions of the codebase weren't tested at all.
Now the workflow is the following:
* Every plugin is built exactly once, either as dynamic or as static.
* The test always loads it via the plugin manager. If it's dynamic,
it's loaded straight from the build directory; if it's static, it
gets linked to the test executable directly.
* Plugins used indirectly are always served from the build directory
(if enabled) to ensure reproducibility and independence on what's
installed on the filesystem. Missing presence of these plugins causes
particular tests to be simply skipped.
* Plugins that have extensive tests for internal functionality that's
not exposed through the plugin interface are still built in two
parts, but the internal tests are simply consuming the OBJECT files
directly instead of linking to a static library.
8 years ago
|
|
|
Containers::Optional<Trade::ImageData2D> image = importer->image2D(0);
|
|
|
|
|
CORRADE_VERIFY(image);
|
|
|
|
|
CORRADE_COMPARE(image->size(), (Vector2i{2, 3}));
|
|
|
|
|
} {
|
plugins: new testing workflow.
The current testing workflow had quite a few major flaws and it was no
longer possible after the move of Any* plugins to core. Among the flaws
is:
* Every plugin was basically built twice, once as the real plugin and
once as a static testing library. Most of the build shared common
object files, but nevertheless it inflated build times and made the
buildsystem extremely complex.
* Because the actual plugin binary was never actually loaded during the
test, it couldn't spot problems like:
- undefined references
- errors in metadata files
- mismatched plugin interface/version, missing entry points
- broken static plugin import files
* Tests that made use of independent plugins (such as TgaImageConverter
test using TgaImporter to verify the output) had a hardcoded
dependency on such plugins, making a minimal setup very hard.
* Dynamic loading of plugins from the Any* proxies was always directed
to the install location on the filesystem with no possibility to
load these directly from the build tree. That caused random ABI
mismatch crashes, or, on the other hand, if no plugins were
installed, particular portions of the codebase weren't tested at all.
Now the workflow is the following:
* Every plugin is built exactly once, either as dynamic or as static.
* The test always loads it via the plugin manager. If it's dynamic,
it's loaded straight from the build directory; if it's static, it
gets linked to the test executable directly.
* Plugins used indirectly are always served from the build directory
(if enabled) to ensure reproducibility and independence on what's
installed on the filesystem. Missing presence of these plugins causes
particular tests to be simply skipped.
* Plugins that have extensive tests for internal functionality that's
not exposed through the plugin interface are still built in two
parts, but the internal tests are simply consuming the OBJECT files
directly instead of linking to a static library.
8 years ago
|
|
|
Containers::Optional<Trade::ImageData2D> image = importer->image2D(0);
|
|
|
|
|
CORRADE_VERIFY(image);
|
|
|
|
|
CORRADE_COMPARE(image->size(), (Vector2i{2, 3}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}}}}
|
|
|
|
|
|
|
|
|
|
CORRADE_TEST_MAIN(Magnum::Trade::Test::TgaImporterTest)
|