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