bitmap.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. // headers
  10. // ----------------------------------------------------------------------------
  11. #include "testprec.h"
  12. #ifdef __BORLANDC__
  13. #pragma hdrstop
  14. #endif
  15. #include "wx/bitmap.h"
  16. #include "wx/dcmemory.h"
  17. // ----------------------------------------------------------------------------
  18. // test class
  19. // ----------------------------------------------------------------------------
  20. class BitmapTestCase : public CppUnit::TestCase
  21. {
  22. public:
  23. BitmapTestCase() { }
  24. virtual void setUp();
  25. virtual void tearDown();
  26. private:
  27. CPPUNIT_TEST_SUITE( BitmapTestCase );
  28. CPPUNIT_TEST( Mask );
  29. CPPUNIT_TEST_SUITE_END();
  30. void Mask();
  31. wxBitmap m_bmp;
  32. DECLARE_NO_COPY_CLASS(BitmapTestCase)
  33. };
  34. // register in the unnamed registry so that these tests are run by default
  35. CPPUNIT_TEST_SUITE_REGISTRATION( BitmapTestCase );
  36. // also include in its own registry so that these tests can be run alone
  37. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BitmapTestCase, "BitmapTestCase" );
  38. void BitmapTestCase::setUp()
  39. {
  40. m_bmp.Create(10, 10);
  41. wxMemoryDC dc(m_bmp);;
  42. dc.SetBackground(*wxWHITE);
  43. dc.Clear();
  44. dc.SetBrush(*wxBLACK_BRUSH);
  45. dc.DrawRectangle(4, 4, 2, 2);
  46. dc.SetPen(*wxRED_PEN);
  47. dc.DrawLine(0, 0, 10, 10);
  48. dc.DrawLine(10, 0, 0, 10);
  49. }
  50. void BitmapTestCase::tearDown()
  51. {
  52. m_bmp = wxNullBitmap;
  53. }
  54. void BitmapTestCase::Mask()
  55. {
  56. wxMask *mask = new wxMask(m_bmp, *wxBLACK);
  57. m_bmp.SetMask(mask);
  58. // copying masks should work
  59. wxMask *mask2 = new wxMask(*mask);
  60. m_bmp.SetMask(mask2);
  61. }