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 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
135 EventCounter
count(m_combo
, wxEVT_COMMAND_COMBOBOX_DROPDOWN
);
136 EventCounter
count1(m_combo
, wxEVT_COMMAND_COMBOBOX_CLOSEUP
);
141 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_COMMAND_COMBOBOX_DROPDOWN
));
142 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_COMMAND_COMBOBOX_CLOSEUP
));
145 void OwnerDrawnComboBoxTestCase::Sort()
147 m_combo
= new wxOwnerDrawnComboBox(wxTheApp
->GetTopWindow(),
149 wxDefaultPosition
, wxDefaultSize
,
153 m_combo
->Append("aaa");
154 m_combo
->Append("Aaa");
155 m_combo
->Append("aba");
156 m_combo
->Append("aaab");
157 m_combo
->Append("aab");
158 m_combo
->Append("AAA");
160 CPPUNIT_ASSERT_EQUAL("AAA", m_combo
->GetString(0));
161 CPPUNIT_ASSERT_EQUAL("Aaa", m_combo
->GetString(1));
162 CPPUNIT_ASSERT_EQUAL("aaa", m_combo
->GetString(2));
163 CPPUNIT_ASSERT_EQUAL("aaab", m_combo
->GetString(3));
164 CPPUNIT_ASSERT_EQUAL("aab", m_combo
->GetString(4));
165 CPPUNIT_ASSERT_EQUAL("aba", m_combo
->GetString(5));
167 m_combo
->Append("a");
169 CPPUNIT_ASSERT_EQUAL("a", m_combo
->GetString(0));
172 void OwnerDrawnComboBoxTestCase::ReadOnly()
174 wxArrayString testitems
;
175 testitems
.Add("item 1");
176 testitems
.Add("item 2");
178 m_combo
= new wxOwnerDrawnComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
179 wxDefaultPosition
, wxDefaultSize
,
183 m_combo
->SetValue("item 1");
185 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
187 m_combo
->SetValue("not an item");
189 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
191 // Since this uses FindString it is case insensitive
192 m_combo
->SetValue("ITEM 2");
194 CPPUNIT_ASSERT_EQUAL("item 2", m_combo
->GetValue());
197 #endif // wxUSE_ODCOMBOBOX