1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/ownerdrawncomboboxtest.cpp
3 // Purpose: OwnerDrawnComboBox unit test
4 // Author: Jaakko Salli
6 // Copyright: (c) 2010 Jaakko Salli
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
25 #include "wx/odcombo.h"
27 #include "textentrytest.h"
28 #include "itemcontainertest.h"
29 #include "testableframe.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 class OwnerDrawnComboBoxTestCase
: public TextEntryTestCase
,
36 public ItemContainerTestCase
,
37 public CppUnit::TestCase
40 OwnerDrawnComboBoxTestCase() { }
43 virtual void tearDown();
46 virtual wxTextEntry
*GetTestEntry() const { return m_combo
; }
47 virtual wxWindow
*GetTestWindow() const { return m_combo
; }
49 virtual wxItemContainer
*GetContainer() const { return m_combo
; }
50 virtual wxWindow
*GetContainerWindow() const { return m_combo
; }
52 virtual void CheckStringSelection(const char * WXUNUSED(sel
))
54 // do nothing here, as explained in TextEntryTestCase comment, our
55 // GetStringSelection() is the wxChoice, not wxTextEntry, one and there
56 // is no way to return the selection contents directly
59 CPPUNIT_TEST_SUITE( OwnerDrawnComboBoxTestCase
);
61 wxITEM_CONTAINER_TESTS();
63 CPPUNIT_TEST( PopDismiss
);
65 CPPUNIT_TEST( ReadOnly
);
66 CPPUNIT_TEST_SUITE_END();
73 wxOwnerDrawnComboBox
*m_combo
;
75 DECLARE_NO_COPY_CLASS(OwnerDrawnComboBoxTestCase
)
78 // register in the unnamed registry so that these tests are run by default
79 CPPUNIT_TEST_SUITE_REGISTRATION( OwnerDrawnComboBoxTestCase
);
81 // also include in its own registry so that these tests can be run alone
82 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OwnerDrawnComboBoxTestCase
,
83 "OwnerDrawnComboBoxTestCase" );
85 // ----------------------------------------------------------------------------
86 // test initialization
87 // ----------------------------------------------------------------------------
89 void OwnerDrawnComboBoxTestCase::setUp()
91 m_combo
= new wxOwnerDrawnComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
);
94 void OwnerDrawnComboBoxTestCase::tearDown()
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 void OwnerDrawnComboBoxTestCase::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 OwnerDrawnComboBoxTestCase::PopDismiss()
131 EventCounter
drop(m_combo
, wxEVT_COMBOBOX_DROPDOWN
);
132 EventCounter
close(m_combo
, wxEVT_COMBOBOX_CLOSEUP
);
137 CPPUNIT_ASSERT_EQUAL(1, drop
.GetCount());
138 CPPUNIT_ASSERT_EQUAL(1, close
.GetCount());
141 void OwnerDrawnComboBoxTestCase::Sort()
143 m_combo
= new wxOwnerDrawnComboBox(wxTheApp
->GetTopWindow(),
145 wxDefaultPosition
, wxDefaultSize
,
149 m_combo
->Append("aaa");
150 m_combo
->Append("Aaa");
151 m_combo
->Append("aba");
152 m_combo
->Append("aaab");
153 m_combo
->Append("aab");
154 m_combo
->Append("AAA");
156 CPPUNIT_ASSERT_EQUAL("AAA", m_combo
->GetString(0));
157 CPPUNIT_ASSERT_EQUAL("Aaa", m_combo
->GetString(1));
158 CPPUNIT_ASSERT_EQUAL("aaa", m_combo
->GetString(2));
159 CPPUNIT_ASSERT_EQUAL("aaab", m_combo
->GetString(3));
160 CPPUNIT_ASSERT_EQUAL("aab", m_combo
->GetString(4));
161 CPPUNIT_ASSERT_EQUAL("aba", m_combo
->GetString(5));
163 m_combo
->Append("a");
165 CPPUNIT_ASSERT_EQUAL("a", m_combo
->GetString(0));
168 void OwnerDrawnComboBoxTestCase::ReadOnly()
170 wxArrayString testitems
;
171 testitems
.Add("item 1");
172 testitems
.Add("item 2");
174 m_combo
= new wxOwnerDrawnComboBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
175 wxDefaultPosition
, wxDefaultSize
,
179 m_combo
->SetValue("item 1");
181 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
183 m_combo
->SetValue("not an item");
185 CPPUNIT_ASSERT_EQUAL("item 1", m_combo
->GetValue());
187 // Since this uses FindString it is case insensitive
188 m_combo
->SetValue("ITEM 2");
190 CPPUNIT_ASSERT_EQUAL("item 2", m_combo
->GetValue());
193 #endif // wxUSE_ODCOMBOBOX