]>
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
6 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
23 #include "wx/combobox.h"
26 #include "textentrytest.h"
27 #include "itemcontainertest.h"
28 #include "testableframe.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 class ComboBoxTestCase
: public TextEntryTestCase
, public ItemContainerTestCase
,
35 public CppUnit::TestCase
38 ComboBoxTestCase() { }
41 virtual void tearDown();
44 virtual wxTextEntry
*GetTestEntry() const { return m_combo
; }
45 virtual wxWindow
*GetTestWindow() const { return m_combo
; }
47 virtual wxItemContainer
*GetContainer() const { return m_combo
; }
48 virtual wxWindow
*GetContainerWindow() const { return m_combo
; }
50 virtual void CheckStringSelection(const char * WXUNUSED(sel
))
52 // do nothing here, as explained in TextEntryTestCase comment, our
53 // GetStringSelection() is the wxChoice, not wxTextEntry, one and there
54 // is no way to return the selection contents directly
57 CPPUNIT_TEST_SUITE( ComboBoxTestCase
);
59 CPPUNIT_TEST( SetValue
);
60 CPPUNIT_TEST( TextChangeEvents
);
61 CPPUNIT_TEST( Selection
);
62 CPPUNIT_TEST( InsertionPoint
);
63 CPPUNIT_TEST( Replace
);
64 // TODO on OS X only works interactively
65 // WXUISIM_TEST( Editable );
67 CPPUNIT_TEST( CopyPaste
);
68 CPPUNIT_TEST( UndoRedo
);
72 wxITEM_CONTAINER_TESTS();
74 CPPUNIT_TEST( PopDismiss
);
76 CPPUNIT_TEST( ReadOnly
);
77 CPPUNIT_TEST( IsEmpty
);
78 CPPUNIT_TEST_SUITE_END();
88 DECLARE_NO_COPY_CLASS(ComboBoxTestCase
)
91 // register in the unnamed registry so that these tests are run by default
92 CPPUNIT_TEST_SUITE_REGISTRATION( ComboBoxTestCase
);
94 // also include in its own registry so that these tests can be run alone
95 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComboBoxTestCase
, "ComboBoxTestCase" );
97 // ----------------------------------------------------------------------------
98 // test initialization
99 // ----------------------------------------------------------------------------
101 void ComboBoxTestCase::setUp()
103 m_combo
= new wxComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
);
106 void ComboBoxTestCase::tearDown()
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 void ComboBoxTestCase::Size()
118 // under MSW changing combobox size is a non-trivial operation because of
119 // confusion between the size of the control with and without dropdown, so
120 // check that it does work as expected
122 const int heightOrig
= m_combo
->GetSize().y
;
124 // check that the height doesn't change if we don't touch it
125 m_combo
->SetSize(100, -1);
126 CPPUNIT_ASSERT_EQUAL( heightOrig
, m_combo
->GetSize().y
);
128 // check that setting both big and small (but not too small, there is a
129 // limit on how small the control can become under MSW) heights works
130 m_combo
->SetSize(-1, 50);
131 CPPUNIT_ASSERT_EQUAL( 50, m_combo
->GetSize().y
);
133 m_combo
->SetSize(-1, 10);
134 CPPUNIT_ASSERT_EQUAL( 10, m_combo
->GetSize().y
);
136 // and also that restoring it works (this used to be broken before 2.9.1)
137 m_combo
->SetSize(-1, heightOrig
);
138 CPPUNIT_ASSERT_EQUAL( heightOrig
, m_combo
->GetSize().y
);
141 void ComboBoxTestCase::PopDismiss()
143 #if defined(__WXMSW__) || defined(__WXGTK210__)
144 EventCounter
drop(m_combo
, wxEVT_COMBOBOX_DROPDOWN
);
145 EventCounter
close(m_combo
, wxEVT_COMBOBOX_CLOSEUP
);
150 CPPUNIT_ASSERT_EQUAL(1, drop
.GetCount());
151 CPPUNIT_ASSERT_EQUAL(1, close
.GetCount());
155 void ComboBoxTestCase::Sort()
157 #if !defined(__WXOSX__)
158 m_combo
= new wxComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
159 wxDefaultPosition
, wxDefaultSize
, 0, NULL
,
162 m_combo
->Append("aaa");
163 m_combo
->Append("Aaa");
164 m_combo
->Append("aba");
165 m_combo
->Append("aaab");
166 m_combo
->Append("aab");
167 m_combo
->Append("AAA");
169 CPPUNIT_ASSERT_EQUAL("AAA", m_combo
->GetString(0));
170 CPPUNIT_ASSERT_EQUAL("Aaa", m_combo
->GetString(1));
171 CPPUNIT_ASSERT_EQUAL("aaa", m_combo
->GetString(2));
172 CPPUNIT_ASSERT_EQUAL("aaab", m_combo
->GetString(3));
173 CPPUNIT_ASSERT_EQUAL("aab", m_combo
->GetString(4));
174 CPPUNIT_ASSERT_EQUAL("aba", m_combo
->GetString(5));
176 m_combo
->Append("a");
178 CPPUNIT_ASSERT_EQUAL("a", m_combo
->GetString(0));
182 void ComboBoxTestCase::ReadOnly()
184 wxArrayString testitems
;
185 testitems
.Add("item 1");
186 testitems
.Add("item 2");
188 m_combo
= new wxComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
189 wxDefaultPosition
, wxDefaultSize
, testitems
,
192 m_combo
->SetValue("item 1");
194 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
196 m_combo
->SetValue("not an item");
198 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
200 // Since this uses FindString it is case insensitive
201 m_combo
->SetValue("ITEM 2");
203 CPPUNIT_ASSERT_EQUAL("item 2", m_combo
->GetValue());
206 void ComboBoxTestCase::IsEmpty()
208 CPPUNIT_ASSERT( m_combo
->IsListEmpty() );
209 CPPUNIT_ASSERT( m_combo
->IsTextEmpty() );
211 m_combo
->Append("foo");
212 CPPUNIT_ASSERT( !m_combo
->IsListEmpty() );
213 CPPUNIT_ASSERT( m_combo
->IsTextEmpty() );
215 m_combo
->SetValue("bar");
216 CPPUNIT_ASSERT( !m_combo
->IsListEmpty() );
217 CPPUNIT_ASSERT( !m_combo
->IsTextEmpty() );
220 CPPUNIT_ASSERT( m_combo
->IsListEmpty() );
221 CPPUNIT_ASSERT( m_combo
->IsTextEmpty() );
223 #ifdef TEST_INVALID_COMBOBOX_ISEMPTY
224 // Compiling this should fail, see failtest target definition in test.bkl.
229 #endif //wxUSE_COMBOBOX