Show more information for wxImage::Scale() unit test failures
Output the maximal difference between the differing images pixels to show just how far are they from each other, exactly. And show the image file name as well, for convenience. Also run all checks instead of stopping after the first failing one.
This commit is contained in:
@@ -1320,8 +1320,8 @@ void ImageTestCase::BMPFlippingAndRLECompression()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool
|
static int
|
||||||
CompareApprox(const wxImage& i1, const wxImage& i2)
|
FindMaxChannelDiff(const wxImage& i1, const wxImage& i2)
|
||||||
{
|
{
|
||||||
if ( i1.GetWidth() != i2.GetWidth() )
|
if ( i1.GetWidth() != i2.GetWidth() )
|
||||||
return false;
|
return false;
|
||||||
@@ -1332,27 +1332,22 @@ CompareApprox(const wxImage& i1, const wxImage& i2)
|
|||||||
const unsigned char* p1 = i1.GetData();
|
const unsigned char* p1 = i1.GetData();
|
||||||
const unsigned char* p2 = i2.GetData();
|
const unsigned char* p2 = i2.GetData();
|
||||||
const int numBytes = i1.GetWidth()*i1.GetHeight()*3;
|
const int numBytes = i1.GetWidth()*i1.GetHeight()*3;
|
||||||
|
int maxDiff = 0;
|
||||||
for ( int n = 0; n < numBytes; n++, p1++, p2++ )
|
for ( int n = 0; n < numBytes; n++, p1++, p2++ )
|
||||||
{
|
{
|
||||||
switch ( *p1 - *p2 )
|
const int diff = std::abs(*p1 - *p2);
|
||||||
{
|
if ( diff > maxDiff )
|
||||||
case -1:
|
maxDiff = diff;
|
||||||
case 0:
|
|
||||||
case +1:
|
|
||||||
// Accept up to one pixel difference, this happens because of
|
|
||||||
// different rounding behaviours in different compiler versions
|
|
||||||
// even under the same architecture, see the example in
|
|
||||||
// http://thread.gmane.org/gmane.comp.lib.wxwidgets.devel/151149/focus=151154
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return maxDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note that we accept up to one pixel difference, this happens because of
|
||||||
|
// different rounding behaviours in different compiler versions
|
||||||
|
// even under the same architecture, see the example in
|
||||||
|
// http://thread.gmane.org/gmane.comp.lib.wxwidgets.devel/151149/focus=151154
|
||||||
|
|
||||||
// The 0 below can be replaced with 1 to generate, instead of comparing with,
|
// The 0 below can be replaced with 1 to generate, instead of comparing with,
|
||||||
// the test files.
|
// the test files.
|
||||||
#define ASSERT_IMAGE_EQUAL_TO_FILE(image, file) \
|
#define ASSERT_IMAGE_EQUAL_TO_FILE(image, file) \
|
||||||
@@ -1362,13 +1357,16 @@ CompareApprox(const wxImage& i1, const wxImage& i2)
|
|||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
wxImage imageFromFile(file); \
|
const wxImage imageFromFile(file); \
|
||||||
CPPUNIT_ASSERT_MESSAGE( "Failed to load " file, imageFromFile.IsOk() ); \
|
if ( imageFromFile.IsOk() ) \
|
||||||
CPPUNIT_ASSERT_MESSAGE \
|
{ \
|
||||||
( \
|
INFO("Wrong scaled \"" << file << "\" " << Catch::toString(image)); \
|
||||||
"Wrong scaled " + Catch::toString(image), \
|
CHECK(FindMaxChannelDiff(imageFromFile, image) <= 1); \
|
||||||
CompareApprox(imageFromFile, image) \
|
} \
|
||||||
); \
|
else \
|
||||||
|
{ \
|
||||||
|
FAIL("Failed to load \"" << file << "\""); \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageTestCase::ScaleCompare()
|
void ImageTestCase::ScaleCompare()
|
||||||
|
Reference in New Issue
Block a user