]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/comboboxtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/comboboxtest.cpp
3 // Purpose: wxComboBox unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 #include "wx/combobox.h"
27 #include "textentrytest.h"
28 #include "itemcontainertest.h"
29 #include "testableframe.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 class ComboBoxTestCase
: public TextEntryTestCase
, public ItemContainerTestCase
,
36 public CppUnit::TestCase
39 ComboBoxTestCase() { }
42 virtual void tearDown();
45 virtual wxTextEntry
*GetTestEntry() const { return m_combo
; }
46 virtual wxWindow
*GetTestWindow() const { return m_combo
; }
48 virtual wxItemContainer
*GetContainer() const { return m_combo
; }
49 virtual wxWindow
*GetContainerWindow() const { return m_combo
; }
51 virtual void CheckStringSelection(const char * WXUNUSED(sel
))
53 // do nothing here, as explained in TextEntryTestCase comment, our
54 // GetStringSelection() is the wxChoice, not wxTextEntry, one and there
55 // is no way to return the selection contents directly
58 CPPUNIT_TEST_SUITE( ComboBoxTestCase
);
60 wxITEM_CONTAINER_TESTS();
62 CPPUNIT_TEST( PopDismiss
);
64 CPPUNIT_TEST( ReadOnly
);
65 CPPUNIT_TEST( IsEmpty
);
66 CPPUNIT_TEST_SUITE_END();
76 DECLARE_NO_COPY_CLASS(ComboBoxTestCase
)
79 // register in the unnamed registry so that these tests are run by default
80 CPPUNIT_TEST_SUITE_REGISTRATION( ComboBoxTestCase
);
82 // also include in its own registry so that these tests can be run alone
83 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComboBoxTestCase
, "ComboBoxTestCase" );
85 // ----------------------------------------------------------------------------
86 // test initialization
87 // ----------------------------------------------------------------------------
89 void ComboBoxTestCase::setUp()
91 m_combo
= new wxComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
);
94 void ComboBoxTestCase::tearDown()
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 void ComboBoxTestCase::Size()
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
110 const int heightOrig
= m_combo
->GetSize().y
;
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
);
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
);
121 m_combo
->SetSize(-1, 10);
122 CPPUNIT_ASSERT_EQUAL( 10, m_combo
->GetSize().y
);
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
);
129 void ComboBoxTestCase::PopDismiss()
131 #if defined(__WXMSW__) || defined(__WXGTK210__)
132 EventCounter
drop(m_combo
, wxEVT_COMBOBOX_DROPDOWN
);
133 EventCounter
close(m_combo
, wxEVT_COMBOBOX_CLOSEUP
);
138 CPPUNIT_ASSERT_EQUAL(1, drop
.GetCount());
139 CPPUNIT_ASSERT_EQUAL(1, close
.GetCount());
143 void ComboBoxTestCase::Sort()
145 #if !defined(__WXOSX__)
146 m_combo
= new wxComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
147 wxDefaultPosition
, wxDefaultSize
, 0, NULL
,
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");
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));
164 m_combo
->Append("a");
166 CPPUNIT_ASSERT_EQUAL("a", m_combo
->GetString(0));
170 void ComboBoxTestCase::ReadOnly()
173 wxArrayString testitems
;
174 testitems
.Add("item 1");
175 testitems
.Add("item 2");
177 m_combo
= new wxComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
178 wxDefaultPosition
, wxDefaultSize
, testitems
,
181 m_combo
->SetValue("item 1");
183 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
185 m_combo
->SetValue("not an item");
187 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
189 // Since this uses FindString it is case insensitive
190 m_combo
->SetValue("ITEM 2");
192 CPPUNIT_ASSERT_EQUAL("item 2", m_combo
->GetValue());
196 void ComboBoxTestCase::IsEmpty()
198 CPPUNIT_ASSERT( m_combo
->IsListEmpty() );
199 CPPUNIT_ASSERT( m_combo
->IsTextEmpty() );
201 m_combo
->Append("foo");
202 CPPUNIT_ASSERT( !m_combo
->IsListEmpty() );
203 CPPUNIT_ASSERT( m_combo
->IsTextEmpty() );
205 m_combo
->SetValue("bar");
206 CPPUNIT_ASSERT( !m_combo
->IsListEmpty() );
207 CPPUNIT_ASSERT( !m_combo
->IsTextEmpty() );
210 CPPUNIT_ASSERT( m_combo
->IsListEmpty() );
211 CPPUNIT_ASSERT( m_combo
->IsTextEmpty() );
213 #ifdef TEST_INVALID_COMBOBOX_ISEMPTY
214 // Compiling this should fail, see failtest target definition in test.bkl.
219 #endif //wxUSE_COMBOBOX