]>
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 CPPUNIT_TEST( SetValue
);
61 CPPUNIT_TEST( TextChangeEvents
);
62 CPPUNIT_TEST( Selection
);
63 CPPUNIT_TEST( InsertionPoint
);
64 CPPUNIT_TEST( Replace
);
65 // TODO on OS X only works interactively
66 // WXUISIM_TEST( Editable );
68 CPPUNIT_TEST( CopyPaste
);
69 CPPUNIT_TEST( UndoRedo
);
73 wxITEM_CONTAINER_TESTS();
75 CPPUNIT_TEST( PopDismiss
);
77 CPPUNIT_TEST( ReadOnly
);
78 CPPUNIT_TEST( IsEmpty
);
79 CPPUNIT_TEST_SUITE_END();
89 DECLARE_NO_COPY_CLASS(ComboBoxTestCase
)
92 // register in the unnamed registry so that these tests are run by default
93 CPPUNIT_TEST_SUITE_REGISTRATION( ComboBoxTestCase
);
95 // also include in its own registry so that these tests can be run alone
96 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComboBoxTestCase
, "ComboBoxTestCase" );
98 // ----------------------------------------------------------------------------
99 // test initialization
100 // ----------------------------------------------------------------------------
102 void ComboBoxTestCase::setUp()
104 m_combo
= new wxComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
);
107 void ComboBoxTestCase::tearDown()
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 void ComboBoxTestCase::Size()
119 // under MSW changing combobox size is a non-trivial operation because of
120 // confusion between the size of the control with and without dropdown, so
121 // check that it does work as expected
123 const int heightOrig
= m_combo
->GetSize().y
;
125 // check that the height doesn't change if we don't touch it
126 m_combo
->SetSize(100, -1);
127 CPPUNIT_ASSERT_EQUAL( heightOrig
, m_combo
->GetSize().y
);
129 // check that setting both big and small (but not too small, there is a
130 // limit on how small the control can become under MSW) heights works
131 m_combo
->SetSize(-1, 50);
132 CPPUNIT_ASSERT_EQUAL( 50, m_combo
->GetSize().y
);
134 m_combo
->SetSize(-1, 10);
135 CPPUNIT_ASSERT_EQUAL( 10, m_combo
->GetSize().y
);
137 // and also that restoring it works (this used to be broken before 2.9.1)
138 m_combo
->SetSize(-1, heightOrig
);
139 CPPUNIT_ASSERT_EQUAL( heightOrig
, m_combo
->GetSize().y
);
142 void ComboBoxTestCase::PopDismiss()
144 #if defined(__WXMSW__) || defined(__WXGTK210__)
145 EventCounter
drop(m_combo
, wxEVT_COMBOBOX_DROPDOWN
);
146 EventCounter
close(m_combo
, wxEVT_COMBOBOX_CLOSEUP
);
151 CPPUNIT_ASSERT_EQUAL(1, drop
.GetCount());
152 CPPUNIT_ASSERT_EQUAL(1, close
.GetCount());
156 void ComboBoxTestCase::Sort()
158 #if !defined(__WXOSX__)
159 m_combo
= new wxComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
160 wxDefaultPosition
, wxDefaultSize
, 0, NULL
,
163 m_combo
->Append("aaa");
164 m_combo
->Append("Aaa");
165 m_combo
->Append("aba");
166 m_combo
->Append("aaab");
167 m_combo
->Append("aab");
168 m_combo
->Append("AAA");
170 CPPUNIT_ASSERT_EQUAL("AAA", m_combo
->GetString(0));
171 CPPUNIT_ASSERT_EQUAL("Aaa", m_combo
->GetString(1));
172 CPPUNIT_ASSERT_EQUAL("aaa", m_combo
->GetString(2));
173 CPPUNIT_ASSERT_EQUAL("aaab", m_combo
->GetString(3));
174 CPPUNIT_ASSERT_EQUAL("aab", m_combo
->GetString(4));
175 CPPUNIT_ASSERT_EQUAL("aba", m_combo
->GetString(5));
177 m_combo
->Append("a");
179 CPPUNIT_ASSERT_EQUAL("a", m_combo
->GetString(0));
183 void ComboBoxTestCase::ReadOnly()
185 wxArrayString testitems
;
186 testitems
.Add("item 1");
187 testitems
.Add("item 2");
189 m_combo
= new wxComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
190 wxDefaultPosition
, wxDefaultSize
, testitems
,
193 m_combo
->SetValue("item 1");
195 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
197 m_combo
->SetValue("not an item");
199 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
201 // Since this uses FindString it is case insensitive
202 m_combo
->SetValue("ITEM 2");
204 CPPUNIT_ASSERT_EQUAL("item 2", m_combo
->GetValue());
207 void ComboBoxTestCase::IsEmpty()
209 CPPUNIT_ASSERT( m_combo
->IsListEmpty() );
210 CPPUNIT_ASSERT( m_combo
->IsTextEmpty() );
212 m_combo
->Append("foo");
213 CPPUNIT_ASSERT( !m_combo
->IsListEmpty() );
214 CPPUNIT_ASSERT( m_combo
->IsTextEmpty() );
216 m_combo
->SetValue("bar");
217 CPPUNIT_ASSERT( !m_combo
->IsListEmpty() );
218 CPPUNIT_ASSERT( !m_combo
->IsTextEmpty() );
221 CPPUNIT_ASSERT( m_combo
->IsListEmpty() );
222 CPPUNIT_ASSERT( m_combo
->IsTextEmpty() );
224 #ifdef TEST_INVALID_COMBOBOX_ISEMPTY
225 // Compiling this should fail, see failtest target definition in test.bkl.
230 #endif //wxUSE_COMBOBOX