]> git.saurik.com Git - wxWidgets.git/blob - tests/image/rawbmp.cpp
Fix DirTestCase to run on the systems without "C:" drive.
[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 #ifdef wxHAS_RAW_BITMAP
22
23 #ifndef WX_PRECOMP
24 #endif // WX_PRECOMP
25
26 #include "wx/image.h"
27 #include "wx/rawbmp.h"
28
29 namespace
30 {
31 const int WIDTH = 10;
32 const int HEIGHT = 10;
33 }
34
35 #define ASSERT_COL_EQUAL(x, y) \
36 CPPUNIT_ASSERT_EQUAL( (unsigned char)(x), (y) )
37
38 // ----------------------------------------------------------------------------
39 // test class
40 // ----------------------------------------------------------------------------
41
42 class ImageRawTestCase : public CppUnit::TestCase
43 {
44 public:
45 ImageRawTestCase() { }
46
47 private:
48 CPPUNIT_TEST_SUITE( ImageRawTestCase );
49 CPPUNIT_TEST( RGBImage );
50 CPPUNIT_TEST_SUITE_END();
51
52 void RGBImage();
53
54 DECLARE_NO_COPY_CLASS(ImageRawTestCase)
55 };
56
57 CPPUNIT_TEST_SUITE_REGISTRATION( ImageRawTestCase );
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ImageRawTestCase, "ImageRawTestCase" );
59
60 void ImageRawTestCase::RGBImage()
61 {
62 // create a check board image
63 wxImage image(WIDTH, HEIGHT);
64
65 wxImagePixelData data(image);
66 wxImagePixelData::Iterator p(data);
67 for ( int y = 0; y < HEIGHT; y++ )
68 {
69 const wxImagePixelData::Iterator rowStart = p;
70
71 for ( int x = 0; x < WIDTH; x++ )
72 {
73 p.Red() =
74 p.Green() =
75 p.Blue() = (x + y) % 2 ? 0 : -1;
76 ++p;
77 }
78
79 p = rowStart;
80 p.OffsetY(data, 1);
81 }
82
83 // test a few pixels
84 ASSERT_COL_EQUAL( 0xff, image.GetRed(0, 0) );
85 ASSERT_COL_EQUAL( 0xff, image.GetBlue(1, 1) );
86 ASSERT_COL_EQUAL( 0, image.GetGreen(0, 1) );
87 ASSERT_COL_EQUAL( 0, image.GetGreen(1, 0) );
88 }
89
90 #endif // wxHAS_RAW_BITMAP