]> git.saurik.com Git - wxWidgets.git/blob - tests/graphics/bitmap.cpp
XRC spec: relax requirements on some commonly omitted properties.
[wxWidgets.git] / tests / graphics / bitmap.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/graphics/bitmap.cpp
3 // Purpose: wxBitmap unit test
4 // Author: Vadim Zeitlin
5 // Created: 2010-03-29
6 // Copyright: (c) 2010 Vadim Zeitlin <vadim@wxwidgets.org>
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // ----------------------------------------------------------------------------
10 // headers
11 // ----------------------------------------------------------------------------
12
13 #include "testprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #include "wx/bitmap.h"
20 #include "wx/dcmemory.h"
21
22 // ----------------------------------------------------------------------------
23 // test class
24 // ----------------------------------------------------------------------------
25
26 class BitmapTestCase : public CppUnit::TestCase
27 {
28 public:
29 BitmapTestCase() { }
30
31 virtual void setUp();
32 virtual void tearDown();
33
34 private:
35 CPPUNIT_TEST_SUITE( BitmapTestCase );
36 CPPUNIT_TEST( Mask );
37 CPPUNIT_TEST_SUITE_END();
38
39 void Mask();
40
41 wxBitmap m_bmp;
42
43 DECLARE_NO_COPY_CLASS(BitmapTestCase)
44 };
45
46 // register in the unnamed registry so that these tests are run by default
47 CPPUNIT_TEST_SUITE_REGISTRATION( BitmapTestCase );
48
49 // also include in its own registry so that these tests can be run alone
50 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BitmapTestCase, "BitmapTestCase" );
51
52 void BitmapTestCase::setUp()
53 {
54 m_bmp.Create(10, 10);
55
56 wxMemoryDC dc(m_bmp);;
57 dc.SetBackground(*wxWHITE);
58 dc.Clear();
59
60 dc.SetBrush(*wxBLACK_BRUSH);
61 dc.DrawRectangle(4, 4, 2, 2);
62
63 dc.SetPen(*wxRED_PEN);
64 dc.DrawLine(0, 0, 10, 10);
65 dc.DrawLine(10, 0, 0, 10);
66 }
67
68 void BitmapTestCase::tearDown()
69 {
70 m_bmp = wxNullBitmap;
71 }
72
73 void BitmapTestCase::Mask()
74 {
75 wxMask *mask = new wxMask(m_bmp, *wxBLACK);
76 m_bmp.SetMask(mask);
77
78 // copying masks should work
79 wxMask *mask2 = new wxMask(*mask);
80 m_bmp.SetMask(mask2);
81 }
82