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