]> git.saurik.com Git - wxWidgets.git/blame - tests/window/setsize.cpp
Allow retrieving the descent and external leading of empty strings.
[wxWidgets.git] / tests / window / setsize.cpp
CommitLineData
5af86f4d
VZ
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
232fdc63 25#include "asserthelper.h"
5af86f4d
VZ
26
27// ----------------------------------------------------------------------------
28// test class
29// ----------------------------------------------------------------------------
30
31class SetSizeTestCase : public CppUnit::TestCase
32{
33public:
34 SetSizeTestCase() { }
35
36 virtual void setUp();
37 virtual void tearDown();
38
39private:
40 CPPUNIT_TEST_SUITE( SetSizeTestCase );
41 CPPUNIT_TEST( SetSize );
42 CPPUNIT_TEST( SetSizeLessThanMinSize );
054fdb68 43 CPPUNIT_TEST( BestSize );
5af86f4d
VZ
44 CPPUNIT_TEST_SUITE_END();
45
46 void SetSize();
47 void SetSizeLessThanMinSize();
054fdb68
VZ
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 };
5af86f4d
VZ
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
69CPPUNIT_TEST_SUITE_REGISTRATION( SetSizeTestCase );
70
e3778b4d 71// also include in its own registry so that these tests can be run alone
5af86f4d
VZ
72CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SetSizeTestCase, "SetSizeTestCase" );
73
74// ----------------------------------------------------------------------------
75// test initialization
76// ----------------------------------------------------------------------------
77
78void SetSizeTestCase::setUp()
79{
054fdb68 80 m_win = new MyWindow(wxTheApp->GetTopWindow());
5af86f4d
VZ
81}
82
83void SetSizeTestCase::tearDown()
84{
85 delete m_win;
86 m_win = NULL;
87}
88
89// ----------------------------------------------------------------------------
90// tests themselves
91// ----------------------------------------------------------------------------
92
93void SetSizeTestCase::SetSize()
94{
95 const wxSize size(127, 35);
96 m_win->SetSize(size);
97 CPPUNIT_ASSERT_EQUAL( size, m_win->GetSize() );
98}
99
100void 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
054fdb68
VZ
109void 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}