bitmapcomboboxtest.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/controls/bitmapcomboboxtest.cpp
  3. // Purpose: wxBitmapComboBox unit test
  4. // Author: Steven Lamerton
  5. // Created: 2010-07-15
  6. // Copyright: (c) 2010 Steven Lamerton
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #include "testprec.h"
  9. #if wxUSE_BITMAPCOMBOBOX
  10. #ifdef __BORLANDC__
  11. #pragma hdrstop
  12. #endif
  13. #ifndef WX_PRECOMP
  14. #include "wx/app.h"
  15. #endif // WX_PRECOMP
  16. #include "wx/bmpcbox.h"
  17. #include "wx/artprov.h"
  18. #include "textentrytest.h"
  19. #include "itemcontainertest.h"
  20. #include "asserthelper.h"
  21. //Test only if we are based off of wxComboBox
  22. #ifndef wxGENERIC_BITMAPCOMBOBOX
  23. class BitmapComboBoxTestCase : public TextEntryTestCase,
  24. public ItemContainerTestCase,
  25. public CppUnit::TestCase
  26. {
  27. public:
  28. BitmapComboBoxTestCase() { }
  29. virtual void setUp();
  30. virtual void tearDown();
  31. private:
  32. virtual wxTextEntry *GetTestEntry() const { return m_combo; }
  33. virtual wxWindow *GetTestWindow() const { return m_combo; }
  34. virtual wxItemContainer *GetContainer() const { return m_combo; }
  35. virtual wxWindow *GetContainerWindow() const { return m_combo; }
  36. virtual void CheckStringSelection(const char * WXUNUSED(sel))
  37. {
  38. // do nothing here, as explained in TextEntryTestCase comment, our
  39. // GetStringSelection() is the wxChoice, not wxTextEntry, one and there
  40. // is no way to return the selection contents directly
  41. }
  42. CPPUNIT_TEST_SUITE( BitmapComboBoxTestCase );
  43. wxTEXT_ENTRY_TESTS();
  44. wxITEM_CONTAINER_TESTS();
  45. CPPUNIT_TEST( Bitmap );
  46. CPPUNIT_TEST_SUITE_END();
  47. void Bitmap();
  48. wxBitmapComboBox *m_combo;
  49. DECLARE_NO_COPY_CLASS(BitmapComboBoxTestCase)
  50. };
  51. // register in the unnamed registry so that these tests are run by default
  52. CPPUNIT_TEST_SUITE_REGISTRATION( BitmapComboBoxTestCase );
  53. // also include in its own registry so that these tests can be run alone
  54. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BitmapComboBoxTestCase,
  55. "BitmapComboBoxTestCase" );
  56. void BitmapComboBoxTestCase::setUp()
  57. {
  58. m_combo = new wxBitmapComboBox(wxTheApp->GetTopWindow(), wxID_ANY);
  59. }
  60. void BitmapComboBoxTestCase::tearDown()
  61. {
  62. wxDELETE(m_combo);
  63. }
  64. void BitmapComboBoxTestCase::Bitmap()
  65. {
  66. wxArrayString items;
  67. items.push_back("item 0");
  68. items.push_back("item 1");
  69. //We need this otherwise MSVC complains as it cannot find a suitable append
  70. static_cast<wxComboBox*>(m_combo)->Append(items);
  71. CPPUNIT_ASSERT(!m_combo->GetItemBitmap(0).IsOk());
  72. wxBitmap bitmap = wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER,
  73. wxSize(16, 16));
  74. m_combo->Append("item with bitmap", bitmap);
  75. CPPUNIT_ASSERT(m_combo->GetItemBitmap(2).IsOk());
  76. m_combo->Insert("item with bitmap", bitmap, 1);
  77. CPPUNIT_ASSERT(m_combo->GetItemBitmap(1).IsOk());
  78. m_combo->SetItemBitmap(0, bitmap);
  79. CPPUNIT_ASSERT(m_combo->GetItemBitmap(0).IsOk());
  80. CPPUNIT_ASSERT_EQUAL(wxSize(16, 16), m_combo->GetBitmapSize());
  81. }
  82. #endif //wxGENERIC_BITMAPCOMBOBOX
  83. #endif //wxUSE_BITMAPCOMBOBOX