]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/ownerdrawncomboboxtest.cpp
XRC spec: relax requirements on some commonly omitted properties.
[wxWidgets.git] / tests / controls / ownerdrawncomboboxtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/ownerdrawncomboboxtest.cpp
3 // Purpose: OwnerDrawnComboBox unit test
4 // Author: Jaakko Salli
5 // Created: 2010-12-17
6 // Copyright: (c) 2010 Jaakko Salli
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // ----------------------------------------------------------------------------
10 // headers
11 // ----------------------------------------------------------------------------
12
13 #include "testprec.h"
14
15 #if wxUSE_ODCOMBOBOX
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #ifndef WX_PRECOMP
22 #include "wx/app.h"
23 #endif // WX_PRECOMP
24
25 #include "wx/odcombo.h"
26
27 #include "textentrytest.h"
28 #include "itemcontainertest.h"
29 #include "testableframe.h"
30
31 // ----------------------------------------------------------------------------
32 // test class
33 // ----------------------------------------------------------------------------
34
35 class OwnerDrawnComboBoxTestCase : public TextEntryTestCase,
36 public ItemContainerTestCase,
37 public CppUnit::TestCase
38 {
39 public:
40 OwnerDrawnComboBoxTestCase() { }
41
42 virtual void setUp();
43 virtual void tearDown();
44
45 private:
46 virtual wxTextEntry *GetTestEntry() const { return m_combo; }
47 virtual wxWindow *GetTestWindow() const { return m_combo; }
48
49 virtual wxItemContainer *GetContainer() const { return m_combo; }
50 virtual wxWindow *GetContainerWindow() const { return m_combo; }
51
52 virtual void CheckStringSelection(const char * WXUNUSED(sel))
53 {
54 // do nothing here, as explained in TextEntryTestCase comment, our
55 // GetStringSelection() is the wxChoice, not wxTextEntry, one and there
56 // is no way to return the selection contents directly
57 }
58
59 CPPUNIT_TEST_SUITE( OwnerDrawnComboBoxTestCase );
60 wxTEXT_ENTRY_TESTS();
61 wxITEM_CONTAINER_TESTS();
62 CPPUNIT_TEST( Size );
63 CPPUNIT_TEST( PopDismiss );
64 CPPUNIT_TEST( Sort );
65 CPPUNIT_TEST( ReadOnly );
66 CPPUNIT_TEST_SUITE_END();
67
68 void Size();
69 void PopDismiss();
70 void Sort();
71 void ReadOnly();
72
73 wxOwnerDrawnComboBox *m_combo;
74
75 DECLARE_NO_COPY_CLASS(OwnerDrawnComboBoxTestCase)
76 };
77
78 // register in the unnamed registry so that these tests are run by default
79 CPPUNIT_TEST_SUITE_REGISTRATION( OwnerDrawnComboBoxTestCase );
80
81 // also include in its own registry so that these tests can be run alone
82 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OwnerDrawnComboBoxTestCase,
83 "OwnerDrawnComboBoxTestCase" );
84
85 // ----------------------------------------------------------------------------
86 // test initialization
87 // ----------------------------------------------------------------------------
88
89 void OwnerDrawnComboBoxTestCase::setUp()
90 {
91 m_combo = new wxOwnerDrawnComboBox(wxTheApp->GetTopWindow(), wxID_ANY);
92 }
93
94 void OwnerDrawnComboBoxTestCase::tearDown()
95 {
96 delete m_combo;
97 m_combo = NULL;
98 }
99
100 // ----------------------------------------------------------------------------
101 // tests themselves
102 // ----------------------------------------------------------------------------
103
104 void OwnerDrawnComboBoxTestCase::Size()
105 {
106 // under MSW changing combobox size is a non-trivial operation because of
107 // confusion between the size of the control with and without dropdown, so
108 // check that it does work as expected
109
110 const int heightOrig = m_combo->GetSize().y;
111
112 // check that the height doesn't change if we don't touch it
113 m_combo->SetSize(100, -1);
114 CPPUNIT_ASSERT_EQUAL( heightOrig, m_combo->GetSize().y );
115
116 // check that setting both big and small (but not too small, there is a
117 // limit on how small the control can become under MSW) heights works
118 m_combo->SetSize(-1, 50);
119 CPPUNIT_ASSERT_EQUAL( 50, m_combo->GetSize().y );
120
121 m_combo->SetSize(-1, 10);
122 CPPUNIT_ASSERT_EQUAL( 10, m_combo->GetSize().y );
123
124 // and also that restoring it works (this used to be broken before 2.9.1)
125 m_combo->SetSize(-1, heightOrig);
126 CPPUNIT_ASSERT_EQUAL( heightOrig, m_combo->GetSize().y );
127 }
128
129 void OwnerDrawnComboBoxTestCase::PopDismiss()
130 {
131 EventCounter drop(m_combo, wxEVT_COMBOBOX_DROPDOWN);
132 EventCounter close(m_combo, wxEVT_COMBOBOX_CLOSEUP);
133
134 m_combo->Popup();
135 m_combo->Dismiss();
136
137 CPPUNIT_ASSERT_EQUAL(1, drop.GetCount());
138 CPPUNIT_ASSERT_EQUAL(1, close.GetCount());
139 }
140
141 void OwnerDrawnComboBoxTestCase::Sort()
142 {
143 m_combo = new wxOwnerDrawnComboBox(wxTheApp->GetTopWindow(),
144 wxID_ANY, "",
145 wxDefaultPosition, wxDefaultSize,
146 0, NULL,
147 wxCB_SORT);
148
149 m_combo->Append("aaa");
150 m_combo->Append("Aaa");
151 m_combo->Append("aba");
152 m_combo->Append("aaab");
153 m_combo->Append("aab");
154 m_combo->Append("AAA");
155
156 CPPUNIT_ASSERT_EQUAL("AAA", m_combo->GetString(0));
157 CPPUNIT_ASSERT_EQUAL("Aaa", m_combo->GetString(1));
158 CPPUNIT_ASSERT_EQUAL("aaa", m_combo->GetString(2));
159 CPPUNIT_ASSERT_EQUAL("aaab", m_combo->GetString(3));
160 CPPUNIT_ASSERT_EQUAL("aab", m_combo->GetString(4));
161 CPPUNIT_ASSERT_EQUAL("aba", m_combo->GetString(5));
162
163 m_combo->Append("a");
164
165 CPPUNIT_ASSERT_EQUAL("a", m_combo->GetString(0));
166 }
167
168 void OwnerDrawnComboBoxTestCase::ReadOnly()
169 {
170 wxArrayString testitems;
171 testitems.Add("item 1");
172 testitems.Add("item 2");
173
174 m_combo = new wxOwnerDrawnComboBox(wxTheApp->GetTopWindow(), wxID_ANY, "",
175 wxDefaultPosition, wxDefaultSize,
176 testitems,
177 wxCB_READONLY);
178
179 m_combo->SetValue("item 1");
180
181 CPPUNIT_ASSERT_EQUAL("item 1", m_combo->GetValue());
182
183 m_combo->SetValue("not an item");
184
185 CPPUNIT_ASSERT_EQUAL("item 1", m_combo->GetValue());
186
187 // Since this uses FindString it is case insensitive
188 m_combo->SetValue("ITEM 2");
189
190 CPPUNIT_ASSERT_EQUAL("item 2", m_combo->GetValue());
191 }
192
193 #endif // wxUSE_ODCOMBOBOX