diff --git a/tests/image/image.cpp b/tests/image/image.cpp index 4e8ab69d0d..6622358146 100644 --- a/tests/image/image.cpp +++ b/tests/image/image.cpp @@ -1346,11 +1346,48 @@ void ImageTestCase::BMPFlippingAndRLECompression() } +static bool +CompareApprox(const wxImage& i1, const wxImage& i2) +{ + if ( i1.GetWidth() != i2.GetWidth() ) + return false; + + if ( i1.GetHeight() != i2.GetHeight() ) + return false; + + const unsigned char* p1 = i1.GetData(); + const unsigned char* p2 = i2.GetData(); + const int numBytes = i1.GetWidth()*i1.GetHeight()*3; + for ( int n = 0; n < numBytes; n++, p1++, p2++ ) + { + switch ( *p1 - *p2 ) + { + case -1: + 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; +} + #define ASSERT_IMAGE_EQUAL_TO_FILE(image, file) \ { \ wxImage imageFromFile(file); \ CPPUNIT_ASSERT_MESSAGE( "Failed to load " file, imageFromFile.IsOk() ); \ - CPPUNIT_ASSERT_EQUAL( imageFromFile, image ); \ + CPPUNIT_ASSERT_MESSAGE \ + ( \ + "Wrong scaled " + CppUnit::assertion_traits::toString(image), \ + CompareApprox(imageFromFile, image) \ + ); \ } void ImageTestCase::ScaleCompare()