Ensure that setting wxChoice height to its default value does set it.
[wxWidgets.git] / tests / controls / comboboxtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/comboboxtest.cpp
3 // Purpose: wxComboBox unit test
4 // Author: Vadim Zeitlin
5 // Created: 2007-09-25
6 // RCS-ID: $Id$
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/app.h"
22 #include "wx/combobox.h"
23 #endif // WX_PRECOMP
24
25 #include "textentrytest.h"
26
27 // ----------------------------------------------------------------------------
28 // test class
29 // ----------------------------------------------------------------------------
30
31 class ComboBoxTestCase : public TextEntryTestCase
32 {
33 public:
34 ComboBoxTestCase() { }
35
36 virtual void setUp();
37 virtual void tearDown();
38
39 private:
40 virtual wxTextEntry *GetTestEntry() const { return m_combo; }
41 virtual wxWindow *GetTestWindow() const { return m_combo; }
42
43 virtual void CheckStringSelection(const char * WXUNUSED(sel))
44 {
45 // do nothing here, as explained in TextEntryTestCase comment, our
46 // GetStringSelection() is the wxChoice, not wxTextEntry, one and there
47 // is no way to return the selection contents directly
48 }
49
50 CPPUNIT_TEST_SUITE( ComboBoxTestCase );
51 wxTEXT_ENTRY_TESTS();
52
53 CPPUNIT_TEST( Size );
54 CPPUNIT_TEST_SUITE_END();
55
56 void Size();
57
58 wxComboBox *m_combo;
59
60 DECLARE_NO_COPY_CLASS(ComboBoxTestCase)
61 };
62
63 // register in the unnamed registry so that these tests are run by default
64 CPPUNIT_TEST_SUITE_REGISTRATION( ComboBoxTestCase );
65
66 // also include in it's own registry so that these tests can be run alone
67 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComboBoxTestCase, "ComboBoxTestCase" );
68
69 // ----------------------------------------------------------------------------
70 // test initialization
71 // ----------------------------------------------------------------------------
72
73 void ComboBoxTestCase::setUp()
74 {
75 m_combo = new wxComboBox(wxTheApp->GetTopWindow(), wxID_ANY);
76 }
77
78 void ComboBoxTestCase::tearDown()
79 {
80 delete m_combo;
81 m_combo = NULL;
82 }
83
84 // ----------------------------------------------------------------------------
85 // tests themselves
86 // ----------------------------------------------------------------------------
87
88 void ComboBoxTestCase::Size()
89 {
90 // under MSW changing combobox size is a non-trivial operation because of
91 // confusion between the size of the control with and without dropdown, so
92 // check that it does work as expected
93
94 const int heightOrig = m_combo->GetSize().y;
95
96 // check that the height doesn't change if we don't touch it
97 m_combo->SetSize(100, -1);
98 CPPUNIT_ASSERT_EQUAL( heightOrig, m_combo->GetSize().y );
99
100 // check that setting both big and small (but not too small, there is a
101 // limit on how small the control can become under MSW) heights works
102 m_combo->SetSize(-1, 50);
103 CPPUNIT_ASSERT_EQUAL( 50, m_combo->GetSize().y );
104
105 m_combo->SetSize(-1, 10);
106 CPPUNIT_ASSERT_EQUAL( 10, m_combo->GetSize().y );
107
108 // and also that restoring it works (this used to be broken before 2.9.1)
109 m_combo->SetSize(-1, heightOrig);
110 CPPUNIT_ASSERT_EQUAL( heightOrig, m_combo->GetSize().y );
111 }
112