From 34e19a74490a15c906acbad61425665928998a34 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Thu, 13 Apr 2017 23:39:23 +0200 Subject: [PATCH] Prevent unit test from crashing under wxGTK3 Under wxGTK3 default color depth for wxBitmap is 24 bpp and therefore wxAlphaPixelData cannot be used to get access to wxBitmap's internal data in this case. See #17666. --- tests/graphics/bitmap.cpp | 41 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/tests/graphics/bitmap.cpp b/tests/graphics/bitmap.cpp index d1b7ba734f..47722e7edb 100644 --- a/tests/graphics/bitmap.cpp +++ b/tests/graphics/bitmap.cpp @@ -107,17 +107,38 @@ void BitmapTestCase::OverlappingBlit() dc.Blit( 0, 1, 10, 9, &dc, 0, 0 ); } // Select the bitmap out of the memory DC before using it directly. - // Now, lines 0 and 1 should be red, lines 2++ should still be white. - wxAlphaPixelData npd( m_bmp ); - wxAlphaPixelData::Iterator it( npd ); + if ( m_bmp.GetDepth() == 32 ) + { + wxAlphaPixelData npd( m_bmp ); + wxAlphaPixelData::Iterator it( npd ); - ASSERT_EQUAL_RGB( it, 255, 0, 0 ); - it.OffsetY( npd, 1 ); - ASSERT_EQUAL_RGB( it, 255, 0, 0 ); - it.OffsetY( npd, 1 ); - ASSERT_EQUAL_RGB( it, 255, 255, 255 ); - it.OffsetY( npd, 1 ); - ASSERT_EQUAL_RGB( it, 255, 255, 255 ); + ASSERT_EQUAL_RGB( it, 255, 0, 0 ); + it.OffsetY( npd, 1 ); + ASSERT_EQUAL_RGB( it, 255, 0, 0 ); + it.OffsetY( npd, 1 ); + ASSERT_EQUAL_RGB( it, 255, 255, 255 ); + it.OffsetY( npd, 1 ); + ASSERT_EQUAL_RGB( it, 255, 255, 255 ); + } + else + { + wxNativePixelData npd( m_bmp ); + wxNativePixelData::Iterator it( npd ); + if ( !npd ) + { + CPPUNIT_FAIL( "Raw access to bitmap data unavailable" ); + } + else + { + ASSERT_EQUAL_RGB( it, 255, 0, 0 ); + it.OffsetY( npd, 1 ); + ASSERT_EQUAL_RGB( it, 255, 0, 0 ); + it.OffsetY( npd, 1 ); + ASSERT_EQUAL_RGB( it, 255, 255, 255 ); + it.OffsetY( npd, 1 ); + ASSERT_EQUAL_RGB( it, 255, 255, 255 ); + } + } }