]> git.saurik.com Git - wxWidgets.git/blob - tests/image/rawbmp.cpp
fixed wxImagePixelData compilation (ticket #3003); added a unit test for it (to be...
[wxWidgets.git] / tests / image / rawbmp.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/image/rawbmp.cpp
3 // Purpose: Test for using raw bitmap access classes with wxImage
4 // Author: Vadim Zeitlin
5 // Created: 2008-05-30
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ----------------------------------------------------------------------------
12 // headers
13 // ----------------------------------------------------------------------------
14
15 #include "testprec.h"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #ifndef WX_PRECOMP
22 #endif // WX_PRECOMP
23
24 #include "wx/image.h"
25 #include "wx/rawbmp.h"
26
27 namespace
28 {
29 const int WIDTH = 10;
30 const int HEIGHT = 10;
31 }
32
33 #define ASSERT_COL_EQUAL(x, y) \
34 CPPUNIT_ASSERT_EQUAL( (unsigned char)(x), (y) )
35
36 // ----------------------------------------------------------------------------
37 // test class
38 // ----------------------------------------------------------------------------
39
40 class ImageRawTestCase : public CppUnit::TestCase
41 {
42 public:
43 ImageRawTestCase() { }
44
45 private:
46 CPPUNIT_TEST_SUITE( ImageRawTestCase );
47 CPPUNIT_TEST( RGBImage );
48 CPPUNIT_TEST_SUITE_END();
49
50 void RGBImage();
51
52 DECLARE_NO_COPY_CLASS(ImageRawTestCase)
53 };
54
55 CPPUNIT_TEST_SUITE_REGISTRATION( ImageRawTestCase );
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ImageRawTestCase, "ImageRawTestCase" );
57
58 void ImageRawTestCase::RGBImage()
59 {
60 // create a check board image
61 wxImage image(WIDTH, HEIGHT);
62
63 wxImagePixelData data(image);
64 wxImagePixelData::Iterator p(data);
65 for ( int y = 0; y < HEIGHT; y++ )
66 {
67 const wxImagePixelData::Iterator rowStart = p;
68
69 for ( int x = 0; x < WIDTH; x++ )
70 {
71 p.Data() = (x + y) % 2 ? 0 : -1;
72 ++p;
73 }
74
75 p = rowStart;
76 p.OffsetY(data, 1);
77 }
78
79 // test a few pixels
80 ASSERT_COL_EQUAL( 0xff, image.GetRed(0, 0) );
81 ASSERT_COL_EQUAL( 0xff, image.GetBlue(1, 1) );
82 ASSERT_COL_EQUAL( 0, image.GetGreen(0, 1) );
83 ASSERT_COL_EQUAL( 0, image.GetGreen(1, 0) );
84 }