1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/ownerdrawncomboboxtest.cpp
3 // Purpose: OwnerDrawnComboBox unit test
4 // Author: Jaakko Salli
7 // Copyright: (c) 2010 Jaakko Salli
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
26 #include "wx/odcombo.h"
28 #include "textentrytest.h"
29 #include "itemcontainertest.h"
30 #include "testableframe.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 class OwnerDrawnComboBoxTestCase
: public TextEntryTestCase
,
37 public ItemContainerTestCase
,
38 public CppUnit::TestCase
41 OwnerDrawnComboBoxTestCase() { }
44 virtual void tearDown();
47 virtual wxTextEntry
*GetTestEntry() const { return m_combo
; }
48 virtual wxWindow
*GetTestWindow() const { return m_combo
; }
50 virtual wxItemContainer
*GetContainer() const { return m_combo
; }
51 virtual wxWindow
*GetContainerWindow() const { return m_combo
; }
53 virtual void CheckStringSelection(const char * WXUNUSED(sel
))
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
60 CPPUNIT_TEST_SUITE( OwnerDrawnComboBoxTestCase
);
62 wxITEM_CONTAINER_TESTS();
64 CPPUNIT_TEST( PopDismiss
);
66 CPPUNIT_TEST( ReadOnly
);
67 CPPUNIT_TEST_SUITE_END();
74 wxOwnerDrawnComboBox
*m_combo
;
76 DECLARE_NO_COPY_CLASS(OwnerDrawnComboBoxTestCase
)
79 // register in the unnamed registry so that these tests are run by default
80 CPPUNIT_TEST_SUITE_REGISTRATION( OwnerDrawnComboBoxTestCase
);
82 // also include in its own registry so that these tests can be run alone
83 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OwnerDrawnComboBoxTestCase
,
84 "OwnerDrawnComboBoxTestCase" );
86 // ----------------------------------------------------------------------------
87 // test initialization
88 // ----------------------------------------------------------------------------
90 void OwnerDrawnComboBoxTestCase::setUp()
92 m_combo
= new wxOwnerDrawnComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
);
95 void OwnerDrawnComboBoxTestCase::tearDown()
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 void OwnerDrawnComboBoxTestCase::Size()
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
111 const int heightOrig
= m_combo
->GetSize().y
;
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
);
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
);
122 m_combo
->SetSize(-1, 10);
123 CPPUNIT_ASSERT_EQUAL( 10, m_combo
->GetSize().y
);
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
);
130 void OwnerDrawnComboBoxTestCase::PopDismiss()
132 EventCounter
drop(m_combo
, wxEVT_COMMAND_COMBOBOX_DROPDOWN
);
133 EventCounter
close(m_combo
, wxEVT_COMMAND_COMBOBOX_CLOSEUP
);
138 CPPUNIT_ASSERT_EQUAL(1, drop
.GetCount());
139 CPPUNIT_ASSERT_EQUAL(1, close
.GetCount());
142 void OwnerDrawnComboBoxTestCase::Sort()
144 m_combo
= new wxOwnerDrawnComboBox(wxTheApp
->GetTopWindow(),
146 wxDefaultPosition
, wxDefaultSize
,
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));
169 void OwnerDrawnComboBoxTestCase::ReadOnly()
171 wxArrayString testitems
;
172 testitems
.Add("item 1");
173 testitems
.Add("item 2");
175 m_combo
= new wxOwnerDrawnComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
176 wxDefaultPosition
, wxDefaultSize
,
180 m_combo
->SetValue("item 1");
182 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
184 m_combo
->SetValue("not an item");
186 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
188 // Since this uses FindString it is case insensitive
189 m_combo
->SetValue("ITEM 2");
191 CPPUNIT_ASSERT_EQUAL("item 2", m_combo
->GetValue());
194 #endif // wxUSE_ODCOMBOBOX