Browse Source

DebugTools: now it can happen that the pixel list is empty.

findsdl-include-root
Vladimír Vondruš 7 years ago
parent
commit
d89b74d40a
  1. 10
      src/Magnum/DebugTools/CompareImage.cpp
  2. 48
      src/Magnum/DebugTools/Test/CompareImageTest.cpp

10
src/Magnum/DebugTools/CompareImage.cpp

@ -328,7 +328,14 @@ void printPixelDeltas(Debug& out, Containers::ArrayView<const Float> delta, Pixe
for(std::size_t i = 0; i != delta.size(); ++i) for(std::size_t i = 0; i != delta.size(); ++i)
if(!(delta[i] <= meanThreshold)) large.emplace(delta[i], i); if(!(delta[i] <= meanThreshold)) large.emplace(delta[i], i);
CORRADE_INTERNAL_ASSERT(!large.empty()); /* If there's no outliers, don't print anything. This can happen only when
--verbose is used. */
if(large.empty()) return;
/* If there are outliers, adding a newline to separate itself from the
delta image -- calling code wouldn't know if we produce output or not,
so it can't do that on its own. */
out << Debug::newline;
if(large.size() > maxCount) if(large.size() > maxCount)
out << " Top" << maxCount << "out of" << large.size() << "pixels above max/mean threshold:"; out << " Top" << maxCount << "out of" << large.size() << "pixels above max/mean threshold:";
@ -668,7 +675,6 @@ void ImageComparatorBase::printMessage(const TestSuite::ComparisonStatusFlags fl
out << "Delta image:" << Debug::newline; out << "Delta image:" << Debug::newline;
DebugTools::Implementation::printDeltaImage(out, _state->delta, _state->expectedImage->size(), _state->max, _state->maxThreshold, _state->meanThreshold); DebugTools::Implementation::printDeltaImage(out, _state->delta, _state->expectedImage->size(), _state->max, _state->maxThreshold, _state->meanThreshold);
out << Debug::newline;
CORRADE_INTERNAL_ASSERT(_state->actualFormat == _state->expectedImage->format()); CORRADE_INTERNAL_ASSERT(_state->actualFormat == _state->expectedImage->format());
DebugTools::Implementation::printPixelDeltas(out, _state->delta, _state->actualFormat, _state->actualPixels, _state->expectedImage->pixels(), _state->maxThreshold, _state->meanThreshold, 10); DebugTools::Implementation::printPixelDeltas(out, _state->delta, _state->actualFormat, _state->actualPixels, _state->expectedImage->pixels(), _state->maxThreshold, _state->meanThreshold, 10);
} }

48
src/Magnum/DebugTools/Test/CompareImageTest.cpp

@ -67,6 +67,7 @@ struct CompareImageTest: TestSuite::Tester {
void deltaImageSpecials(); void deltaImageSpecials();
void pixelDelta(); void pixelDelta();
void pixelDeltaEmpty();
void pixelDeltaOverflow(); void pixelDeltaOverflow();
void pixelDeltaSpecials(); void pixelDeltaSpecials();
@ -86,6 +87,7 @@ struct CompareImageTest: TestSuite::Tester {
void imageZeroDelta(); void imageZeroDelta();
void imageNonZeroDelta(); void imageNonZeroDelta();
void imageNonZeroDeltaNoPixels();
void imageError(); void imageError();
void imageFile(); void imageFile();
void imageFileZeroDelta(); void imageFileZeroDelta();
@ -137,6 +139,7 @@ CompareImageTest::CompareImageTest() {
&CompareImageTest::deltaImageSpecials, &CompareImageTest::deltaImageSpecials,
&CompareImageTest::pixelDelta, &CompareImageTest::pixelDelta,
&CompareImageTest::pixelDeltaEmpty,
&CompareImageTest::pixelDeltaOverflow, &CompareImageTest::pixelDeltaOverflow,
&CompareImageTest::pixelDeltaSpecials, &CompareImageTest::pixelDeltaSpecials,
@ -153,6 +156,7 @@ CompareImageTest::CompareImageTest() {
&CompareImageTest::imageZeroDelta, &CompareImageTest::imageZeroDelta,
&CompareImageTest::imageNonZeroDelta, &CompareImageTest::imageNonZeroDelta,
&CompareImageTest::imageNonZeroDeltaNoPixels,
&CompareImageTest::imageError}); &CompareImageTest::imageError});
addTests({&CompareImageTest::imageFileZeroDelta, addTests({&CompareImageTest::imageFileZeroDelta,
@ -464,16 +468,16 @@ void CompareImageTest::deltaImageSpecials() {
void CompareImageTest::pixelDelta() { void CompareImageTest::pixelDelta() {
{ {
Debug() << "Visual verification -- some lines should be yellow, some red:"; Debug out;
Debug d; out << "Visual verification -- some lines should be yellow, some red:";
Implementation::printPixelDeltas(d, DeltaRed, ActualRed.format(), ActualRed.pixels(), ExpectedRed.pixels(), 0.5f, 0.1f, 10); Implementation::printPixelDeltas(out, DeltaRed, ActualRed.format(), ActualRed.pixels(), ExpectedRed.pixels(), 0.5f, 0.1f, 10);
} }
std::ostringstream out; std::ostringstream out;
Debug d{&out, Debug::Flag::DisableColors}; Debug d{&out, Debug::Flag::DisableColors};
Implementation::printPixelDeltas(d, DeltaRed, ActualRed.format(), ActualRed.pixels(), ExpectedRed.pixels(), 0.5f, 0.1f, 10); Implementation::printPixelDeltas(d, DeltaRed, ActualRed.format(), ActualRed.pixels(), ExpectedRed.pixels(), 0.5f, 0.1f, 10);
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(), "\n"
" Pixels above max/mean threshold:\n" " Pixels above max/mean threshold:\n"
" [1,2] Vector(1), expected Vector(0) (Δ = 1)\n" " [1,2] Vector(1), expected Vector(0) (Δ = 1)\n"
" [0,0] Vector(0.3), expected Vector(0.65) (Δ = 0.35)\n" " [0,0] Vector(0.3), expected Vector(0.65) (Δ = 0.35)\n"
@ -481,12 +485,20 @@ void CompareImageTest::pixelDelta() {
" [0,2] Vector(-0.1), expected Vector(0.02) (Δ = 0.12)"); " [0,2] Vector(-0.1), expected Vector(0.02) (Δ = 0.12)");
} }
void CompareImageTest::pixelDeltaEmpty() {
std::ostringstream out;
Debug d{&out, Debug::Flag::DisableColors};
Implementation::printPixelDeltas(d, DeltaRed, ActualRed.format(), ActualRed.pixels(), ExpectedRed.pixels(), 1.0f, 1.0f, 10);
CORRADE_COMPARE(out.str(), "");
}
void CompareImageTest::pixelDeltaOverflow() { void CompareImageTest::pixelDeltaOverflow() {
std::ostringstream out; std::ostringstream out;
Debug d{&out, Debug::Flag::DisableColors}; Debug d{&out, Debug::Flag::DisableColors};
Implementation::printPixelDeltas(d, DeltaRed, ActualRed.format(), ActualRed.pixels(), ExpectedRed.pixels(), 0.5f, 0.1f, 3); Implementation::printPixelDeltas(d, DeltaRed, ActualRed.format(), ActualRed.pixels(), ExpectedRed.pixels(), 0.5f, 0.1f, 3);
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(), "\n"
" Top 3 out of 4 pixels above max/mean threshold:\n" " Top 3 out of 4 pixels above max/mean threshold:\n"
" [1,2] Vector(1), expected Vector(0) (Δ = 1)\n" " [1,2] Vector(1), expected Vector(0) (Δ = 1)\n"
" [0,0] Vector(0.3), expected Vector(0.65) (Δ = 0.35)\n" " [0,0] Vector(0.3), expected Vector(0.65) (Δ = 0.35)\n"
@ -500,7 +512,7 @@ void CompareImageTest::pixelDeltaSpecials() {
/* MSVC prints -nan(ind) instead of ±nan. But only sometimes. */ /* MSVC prints -nan(ind) instead of ±nan. But only sometimes. */
#ifdef _MSC_VER #ifdef _MSC_VER
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(), "\n"
" Pixels above max/mean threshold:\n" " Pixels above max/mean threshold:\n"
" [5,0] Vector(-inf), expected Vector(inf) (Δ = inf)\n" " [5,0] Vector(-inf), expected Vector(inf) (Δ = inf)\n"
" [3,0] Vector(0.3), expected Vector(-nan(ind)) (Δ = -nan(ind))\n" " [3,0] Vector(0.3), expected Vector(-nan(ind)) (Δ = -nan(ind))\n"
@ -509,7 +521,7 @@ void CompareImageTest::pixelDeltaSpecials() {
" [0,0] Vector(inf), expected Vector(1) (Δ = inf)\n" " [0,0] Vector(inf), expected Vector(1) (Δ = inf)\n"
" [8,0] Vector(3), expected Vector(-0.1) (Δ = 3.1)"); " [8,0] Vector(3), expected Vector(-0.1) (Δ = 3.1)");
#else #else
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(), "\n"
" Pixels above max/mean threshold:\n" " Pixels above max/mean threshold:\n"
" [5,0] Vector(-inf), expected Vector(inf) (Δ = inf)\n" " [5,0] Vector(-inf), expected Vector(inf) (Δ = inf)\n"
" [3,0] Vector(0.3), expected Vector(nan) (Δ = nan)\n" " [3,0] Vector(0.3), expected Vector(nan) (Δ = nan)\n"
@ -835,6 +847,28 @@ void CompareImageTest::imageNonZeroDelta() {
CORRADE_COMPARE(out.str(), ImageCompareVerbose); CORRADE_COMPARE(out.str(), ImageCompareVerbose);
} }
void CompareImageTest::imageNonZeroDeltaNoPixels() {
/* This will produce output if --verbose is specified */
CORRADE_COMPARE_WITH(ActualRgb, ExpectedRgb, (CompareImage{40.0f, 40.0f}));
std::ostringstream out;
{
TestSuite::Comparator<CompareImage> compare{40.0f, 40.0f};
TestSuite::ComparisonStatusFlags flags = compare(ActualRgb, ExpectedRgb);
/* No diagnostic as there's no error */
CORRADE_COMPARE(flags, TestSuite::ComparisonStatusFlag::Verbose);
Debug d{&out, Debug::Flag::DisableColors};
compare.printMessage(flags, d, "a", "b");
}
/* No pixel list written as there are no outliers. Testing this just once
since all other combinations (image/file/pixels) use the same codepath. */
CORRADE_COMPARE(out.str(),
"Images a and b have deltas 39/18.5 below threshold 40/40. Delta image:\n"
" |?M|\n");
}
void CompareImageTest::imageError() { void CompareImageTest::imageError() {
std::stringstream out; std::stringstream out;

Loading…
Cancel
Save