]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/bitmapcomboboxtest.cpp
More German translations updates from Sebastian Walderich.
[wxWidgets.git] / tests / controls / bitmapcomboboxtest.cpp
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
9 #include "testprec.h"
10
11 #if wxUSE_BITMAPCOMBOBOX
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #endif // WX_PRECOMP
20
21 #include "wx/bmpcbox.h"
22 #include "wx/artprov.h"
23 #include "textentrytest.h"
24 #include "itemcontainertest.h"
25 #include "asserthelper.h"
26
27 //Test only if we are based off of wxComboBox
28 #ifndef wxGENERIC_BITMAPCOMBOBOX
29
30 class BitmapComboBoxTestCase : public TextEntryTestCase,
31 public ItemContainerTestCase,
32 public CppUnit::TestCase
33 {
34 public:
35 BitmapComboBoxTestCase() { }
36
37 virtual void setUp();
38 virtual void tearDown();
39
40 private:
41 virtual wxTextEntry *GetTestEntry() const { return m_combo; }
42 virtual wxWindow *GetTestWindow() const { return m_combo; }
43
44 virtual wxItemContainer *GetContainer() const { return m_combo; }
45 virtual wxWindow *GetContainerWindow() const { return m_combo; }
46
47 virtual void CheckStringSelection(const char * WXUNUSED(sel))
48 {
49 // do nothing here, as explained in TextEntryTestCase comment, our
50 // GetStringSelection() is the wxChoice, not wxTextEntry, one and there
51 // is no way to return the selection contents directly
52 }
53
54 CPPUNIT_TEST_SUITE( BitmapComboBoxTestCase );
55 wxTEXT_ENTRY_TESTS();
56 wxITEM_CONTAINER_TESTS();
57 CPPUNIT_TEST( Bitmap );
58 CPPUNIT_TEST_SUITE_END();
59
60 void Bitmap();
61
62 wxBitmapComboBox *m_combo;
63
64 DECLARE_NO_COPY_CLASS(BitmapComboBoxTestCase)
65 };
66
67 // register in the unnamed registry so that these tests are run by default
68 CPPUNIT_TEST_SUITE_REGISTRATION( BitmapComboBoxTestCase );
69
70 // also include in its own registry so that these tests can be run alone
71 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BitmapComboBoxTestCase,
72 "BitmapComboBoxTestCase" );
73
74 void BitmapComboBoxTestCase::setUp()
75 {
76 m_combo = new wxBitmapComboBox(wxTheApp->GetTopWindow(), wxID_ANY);
77 }
78
79 void BitmapComboBoxTestCase::tearDown()
80 {
81 wxDELETE(m_combo);
82 }
83
84 void BitmapComboBoxTestCase::Bitmap()
85 {
86 wxArrayString items;
87 items.push_back("item 0");
88 items.push_back("item 1");
89
90 //We need this otherwise MSVC complains as it cannot find a suitable append
91 static_cast<wxComboBox*>(m_combo)->Append(items);
92
93 CPPUNIT_ASSERT(!m_combo->GetItemBitmap(0).IsOk());
94
95 wxBitmap bitmap = wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER,
96 wxSize(16, 16));
97
98 m_combo->Append("item with bitmap", bitmap);
99
100 CPPUNIT_ASSERT(m_combo->GetItemBitmap(2).IsOk());
101
102 m_combo->Insert("item with bitmap", bitmap, 1);
103
104 CPPUNIT_ASSERT(m_combo->GetItemBitmap(1).IsOk());
105
106 m_combo->SetItemBitmap(0, bitmap);
107
108 CPPUNIT_ASSERT(m_combo->GetItemBitmap(0).IsOk());
109
110 CPPUNIT_ASSERT_EQUAL(wxSize(16, 16), m_combo->GetBitmapSize());
111 }
112
113 #endif //wxGENERIC_BITMAPCOMBOBOX
114
115 #endif //wxUSE_BITMAPCOMBOBOX