]> git.saurik.com Git - wxWidgets.git/blob - tests/window/setsize.cpp
Initialize wxXmlResourceHandler members in its ctor.
[wxWidgets.git] / tests / window / setsize.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/window/setsize.cpp
3 // Purpose: Tests for SetSize() and related wxWindow methods
4 // Author: Vadim Zeitlin
5 // Created: 2008-05-25
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 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/window.h"
23 #endif // WX_PRECOMP
24
25 #include "asserthelper.h"
26
27 // ----------------------------------------------------------------------------
28 // test class
29 // ----------------------------------------------------------------------------
30
31 class SetSizeTestCase : public CppUnit::TestCase
32 {
33 public:
34 SetSizeTestCase() { }
35
36 virtual void setUp();
37 virtual void tearDown();
38
39 private:
40 CPPUNIT_TEST_SUITE( SetSizeTestCase );
41 CPPUNIT_TEST( SetSize );
42 CPPUNIT_TEST( SetSizeLessThanMinSize );
43 CPPUNIT_TEST( BestSize );
44 CPPUNIT_TEST_SUITE_END();
45
46 void SetSize();
47 void SetSizeLessThanMinSize();
48 void BestSize();
49
50 // Helper class overriding DoGetBestSize() for testing purposes.
51 class MyWindow : public wxWindow
52 {
53 public:
54 MyWindow(wxWindow* parent)
55 : wxWindow(parent, wxID_ANY)
56 {
57 }
58
59 protected:
60 virtual wxSize DoGetBestSize() const { return wxSize(50, 250); }
61 };
62
63 wxWindow *m_win;
64
65 DECLARE_NO_COPY_CLASS(SetSizeTestCase)
66 };
67
68 // register in the unnamed registry so that these tests are run by default
69 CPPUNIT_TEST_SUITE_REGISTRATION( SetSizeTestCase );
70
71 // also include in its own registry so that these tests can be run alone
72 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SetSizeTestCase, "SetSizeTestCase" );
73
74 // ----------------------------------------------------------------------------
75 // test initialization
76 // ----------------------------------------------------------------------------
77
78 void SetSizeTestCase::setUp()
79 {
80 m_win = new MyWindow(wxTheApp->GetTopWindow());
81 }
82
83 void SetSizeTestCase::tearDown()
84 {
85 delete m_win;
86 m_win = NULL;
87 }
88
89 // ----------------------------------------------------------------------------
90 // tests themselves
91 // ----------------------------------------------------------------------------
92
93 void SetSizeTestCase::SetSize()
94 {
95 const wxSize size(127, 35);
96 m_win->SetSize(size);
97 CPPUNIT_ASSERT_EQUAL( size, m_win->GetSize() );
98 }
99
100 void SetSizeTestCase::SetSizeLessThanMinSize()
101 {
102 m_win->SetMinSize(wxSize(100, 100));
103
104 const wxSize size(200, 50);
105 m_win->SetSize(size);
106 CPPUNIT_ASSERT_EQUAL( size, m_win->GetSize() );
107 }
108
109 void SetSizeTestCase::BestSize()
110 {
111 CPPUNIT_ASSERT_EQUAL( wxSize(50, 250), m_win->GetBestSize() );
112
113 m_win->SetMinSize(wxSize(100, 100));
114 CPPUNIT_ASSERT_EQUAL( wxSize(100, 250), m_win->GetBestSize() );
115
116 m_win->SetMaxSize(wxSize(200, 200));
117 CPPUNIT_ASSERT_EQUAL( wxSize(100, 200), m_win->GetBestSize() );
118 }