Migrate wxBitmap tests to Catch
This commit is contained in:
@@ -26,81 +26,57 @@
|
||||
#endif // wxUSE_GRAPHICS_CONTEXT
|
||||
|
||||
#define ASSERT_EQUAL_RGB(c, r, g, b) \
|
||||
CPPUNIT_ASSERT_EQUAL( r, (int)c.Red() ); \
|
||||
CPPUNIT_ASSERT_EQUAL( g, (int)c.Green() ); \
|
||||
CPPUNIT_ASSERT_EQUAL( b, (int)c.Blue() )
|
||||
REQUIRE( r == (int)c.Red() ); \
|
||||
REQUIRE( g == (int)c.Green() ); \
|
||||
REQUIRE( b == (int)c.Blue() )
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class BitmapTestCase : public CppUnit::TestCase
|
||||
TEST_CASE("BitmapTestCase::Mask", "[bitmap][mask]")
|
||||
{
|
||||
public:
|
||||
BitmapTestCase() { }
|
||||
|
||||
virtual void setUp() wxOVERRIDE;
|
||||
virtual void tearDown() wxOVERRIDE;
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( BitmapTestCase );
|
||||
CPPUNIT_TEST( Mask );
|
||||
CPPUNIT_TEST( OverlappingBlit );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Mask();
|
||||
void OverlappingBlit();
|
||||
|
||||
wxBitmap m_bmp;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(BitmapTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( BitmapTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BitmapTestCase, "BitmapTestCase" );
|
||||
|
||||
void BitmapTestCase::setUp()
|
||||
{
|
||||
m_bmp.Create(10, 10);
|
||||
|
||||
wxMemoryDC dc(m_bmp);;
|
||||
wxBitmap bmp(10, 10);
|
||||
{
|
||||
wxMemoryDC dc(bmp);
|
||||
dc.SetBackground(*wxWHITE);
|
||||
dc.Clear();
|
||||
|
||||
dc.SetBrush(*wxBLACK_BRUSH);
|
||||
dc.DrawRectangle(4, 4, 2, 2);
|
||||
|
||||
dc.SetPen(*wxRED_PEN);
|
||||
dc.DrawLine(0, 0, 10, 10);
|
||||
dc.DrawLine(10, 0, 0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
void BitmapTestCase::tearDown()
|
||||
{
|
||||
m_bmp = wxNullBitmap;
|
||||
}
|
||||
|
||||
void BitmapTestCase::Mask()
|
||||
{
|
||||
wxMask *mask = new wxMask(m_bmp, *wxBLACK);
|
||||
m_bmp.SetMask(mask);
|
||||
wxMask *mask = new wxMask(bmp, *wxBLACK);
|
||||
bmp.SetMask(mask);
|
||||
REQUIRE(bmp.GetMask() == mask);
|
||||
|
||||
// copying masks should work
|
||||
wxMask *mask2 = NULL;
|
||||
REQUIRE_NOTHROW(mask2 = new wxMask(*mask));
|
||||
m_bmp.SetMask(mask2);
|
||||
bmp.SetMask(mask2);
|
||||
REQUIRE(bmp.GetMask() == mask2);
|
||||
}
|
||||
|
||||
void BitmapTestCase::OverlappingBlit()
|
||||
TEST_CASE("BitmapTestCase::OverlappingBlit", "[bitmap][blit]")
|
||||
{
|
||||
m_bmp.SetMask( NULL );
|
||||
wxBitmap bmp(10, 10);
|
||||
{
|
||||
wxMemoryDC dc(bmp);
|
||||
dc.SetBackground(*wxWHITE);
|
||||
dc.Clear();
|
||||
dc.SetBrush(*wxBLACK_BRUSH);
|
||||
dc.DrawRectangle(4, 4, 2, 2);
|
||||
dc.SetPen(*wxRED_PEN);
|
||||
dc.DrawLine(0, 0, 10, 10);
|
||||
dc.DrawLine(10, 0, 0, 10);
|
||||
}
|
||||
REQUIRE(bmp.GetMask() == NULL);
|
||||
|
||||
// Clear to white.
|
||||
{
|
||||
wxMemoryDC dc(m_bmp);
|
||||
wxMemoryDC dc(bmp);
|
||||
#if wxUSE_GRAPHICS_CONTEXT
|
||||
wxGraphicsContext* gc = dc.GetGraphicsContext();
|
||||
if ( gc )
|
||||
@@ -123,10 +99,10 @@ void BitmapTestCase::OverlappingBlit()
|
||||
} // 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.
|
||||
|
||||
if ( m_bmp.GetDepth() == 32 )
|
||||
if ( bmp.GetDepth() == 32 )
|
||||
{
|
||||
wxAlphaPixelData npd( m_bmp );
|
||||
CPPUNIT_ASSERT_MESSAGE( "Expected raw pixels to not be NULL", npd );
|
||||
wxAlphaPixelData npd( bmp );
|
||||
REQUIRE( npd );
|
||||
wxAlphaPixelData::Iterator it( npd );
|
||||
|
||||
ASSERT_EQUAL_RGB( it, 255, 0, 0 );
|
||||
@@ -139,14 +115,10 @@ void BitmapTestCase::OverlappingBlit()
|
||||
}
|
||||
else
|
||||
{
|
||||
wxNativePixelData npd( m_bmp );
|
||||
wxNativePixelData npd( bmp );
|
||||
REQUIRE( npd );
|
||||
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 );
|
||||
@@ -155,7 +127,6 @@ void BitmapTestCase::OverlappingBlit()
|
||||
it.OffsetY( npd, 1 );
|
||||
ASSERT_EQUAL_RGB( it, 255, 255, 255 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //wxHAS_RAW_BITMAP
|
||||
|
Reference in New Issue
Block a user