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