]> git.saurik.com Git - wxWidgets.git/blob - tests/window/setsize.cpp
Brazilian Portuguese translations update from Felipe.
[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 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // ----------------------------------------------------------------------------
10 // headers
11 // ----------------------------------------------------------------------------
12
13 #include "testprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/app.h"
21 #include "wx/window.h"
22 #endif // WX_PRECOMP
23
24 #include "asserthelper.h"
25
26 // ----------------------------------------------------------------------------
27 // test class
28 // ----------------------------------------------------------------------------
29
30 class SetSizeTestCase : public CppUnit::TestCase
31 {
32 public:
33 SetSizeTestCase() { }
34
35 virtual void setUp();
36 virtual void tearDown();
37
38 private:
39 CPPUNIT_TEST_SUITE( SetSizeTestCase );
40 CPPUNIT_TEST( SetSize );
41 CPPUNIT_TEST( SetSizeLessThanMinSize );
42 CPPUNIT_TEST( BestSize );
43 CPPUNIT_TEST_SUITE_END();
44
45 void SetSize();
46 void SetSizeLessThanMinSize();
47 void BestSize();
48
49 // Helper class overriding DoGetBestSize() for testing purposes.
50 class MyWindow : public wxWindow
51 {
52 public:
53 MyWindow(wxWindow* parent)
54 : wxWindow(parent, wxID_ANY)
55 {
56 }
57
58 protected:
59 virtual wxSize DoGetBestSize() const { return wxSize(50, 250); }
60 };
61
62 wxWindow *m_win;
63
64 DECLARE_NO_COPY_CLASS(SetSizeTestCase)
65 };
66
67 // register in the unnamed registry so that these tests are run by default
68 CPPUNIT_TEST_SUITE_REGISTRATION( SetSizeTestCase );
69
70 // also include in its own registry so that these tests can be run alone
71 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SetSizeTestCase, "SetSizeTestCase" );
72
73 // ----------------------------------------------------------------------------
74 // test initialization
75 // ----------------------------------------------------------------------------
76
77 void SetSizeTestCase::setUp()
78 {
79 m_win = new MyWindow(wxTheApp->GetTopWindow());
80 }
81
82 void SetSizeTestCase::tearDown()
83 {
84 delete m_win;
85 m_win = NULL;
86 }
87
88 // ----------------------------------------------------------------------------
89 // tests themselves
90 // ----------------------------------------------------------------------------
91
92 void SetSizeTestCase::SetSize()
93 {
94 const wxSize size(127, 35);
95 m_win->SetSize(size);
96 CPPUNIT_ASSERT_EQUAL( size, m_win->GetSize() );
97 }
98
99 void SetSizeTestCase::SetSizeLessThanMinSize()
100 {
101 m_win->SetMinSize(wxSize(100, 100));
102
103 const wxSize size(200, 50);
104 m_win->SetSize(size);
105 CPPUNIT_ASSERT_EQUAL( size, m_win->GetSize() );
106 }
107
108 void SetSizeTestCase::BestSize()
109 {
110 CPPUNIT_ASSERT_EQUAL( wxSize(50, 250), m_win->GetBestSize() );
111
112 m_win->SetMinSize(wxSize(100, 100));
113 CPPUNIT_ASSERT_EQUAL( wxSize(100, 250), m_win->GetBestSize() );
114
115 m_win->SetMaxSize(wxSize(200, 200));
116 CPPUNIT_ASSERT_EQUAL( wxSize(100, 200), m_win->GetBestSize() );
117 }