fixed wxImagePixelData compilation (ticket #3003); added a unit test for it (to be extended to cover more wxImage methods...)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-05-30 19:30:23 +00:00
parent 8aa6162938
commit 3e50a139b4
12 changed files with 126 additions and 7 deletions

84
tests/image/rawbmp.cpp Normal file
View File

@@ -0,0 +1,84 @@
///////////////////////////////////////////////////////////////////////////////
// Name: tests/image/rawbmp.cpp
// Purpose: Test for using raw bitmap access classes with wxImage
// Author: Vadim Zeitlin
// Created: 2008-05-30
// RCS-ID: $Id$
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "testprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#endif // WX_PRECOMP
#include "wx/image.h"
#include "wx/rawbmp.h"
namespace
{
const int WIDTH = 10;
const int HEIGHT = 10;
}
#define ASSERT_COL_EQUAL(x, y) \
CPPUNIT_ASSERT_EQUAL( (unsigned char)(x), (y) )
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
class ImageRawTestCase : public CppUnit::TestCase
{
public:
ImageRawTestCase() { }
private:
CPPUNIT_TEST_SUITE( ImageRawTestCase );
CPPUNIT_TEST( RGBImage );
CPPUNIT_TEST_SUITE_END();
void RGBImage();
DECLARE_NO_COPY_CLASS(ImageRawTestCase)
};
CPPUNIT_TEST_SUITE_REGISTRATION( ImageRawTestCase );
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ImageRawTestCase, "ImageRawTestCase" );
void ImageRawTestCase::RGBImage()
{
// create a check board image
wxImage image(WIDTH, HEIGHT);
wxImagePixelData data(image);
wxImagePixelData::Iterator p(data);
for ( int y = 0; y < HEIGHT; y++ )
{
const wxImagePixelData::Iterator rowStart = p;
for ( int x = 0; x < WIDTH; x++ )
{
p.Data() = (x + y) % 2 ? 0 : -1;
++p;
}
p = rowStart;
p.OffsetY(data, 1);
}
// test a few pixels
ASSERT_COL_EQUAL( 0xff, image.GetRed(0, 0) );
ASSERT_COL_EQUAL( 0xff, image.GetBlue(1, 1) );
ASSERT_COL_EQUAL( 0, image.GetGreen(0, 1) );
ASSERT_COL_EQUAL( 0, image.GetGreen(1, 0) );
}