Add (a very simple for now) wxBoxSizer unit test.
[wxWidgets.git] / tests / sizers / boxsizer.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/sizers/boxsizer.cpp
3 // Purpose: Unit tests for wxBoxSizer
4 // Author: Vadim Zeitlin
5 // Created: 2010-03-06
6 // RCS-ID: $Id$
7 // Copyright: (c) 2010 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/sizer.h"
23 #endif // WX_PRECOMP
24
25 inline std::ostream& operator<<(std::ostream& o, const wxSize& s)
26 {
27 return o << s.x << 'x' << s.y;
28 }
29
30 // ----------------------------------------------------------------------------
31 // test class
32 // ----------------------------------------------------------------------------
33
34 class BoxSizerTestCase : public CppUnit::TestCase
35 {
36 public:
37 BoxSizerTestCase() { }
38
39 virtual void setUp();
40 virtual void tearDown();
41
42 private:
43 CPPUNIT_TEST_SUITE( BoxSizerTestCase );
44 CPPUNIT_TEST( Size1 );
45 CPPUNIT_TEST_SUITE_END();
46
47 void Size1();
48
49 wxWindow *m_win;
50 wxSizer *m_sizer;
51
52 DECLARE_NO_COPY_CLASS(BoxSizerTestCase)
53 };
54
55 // register in the unnamed registry so that these tests are run by default
56 CPPUNIT_TEST_SUITE_REGISTRATION( BoxSizerTestCase );
57
58 // also include in it's own registry so that these tests can be run alone
59 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BoxSizerTestCase, "BoxSizerTestCase" );
60
61 // ----------------------------------------------------------------------------
62 // test initialization
63 // ----------------------------------------------------------------------------
64
65 void BoxSizerTestCase::setUp()
66 {
67 m_win = new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY);
68 m_win->SetClientSize(127, 35);
69
70 m_sizer = new wxBoxSizer(wxHORIZONTAL);
71 m_win->SetSizer(m_sizer);
72 }
73
74 void BoxSizerTestCase::tearDown()
75 {
76 delete m_win;
77 m_win = NULL;
78
79 m_sizer = NULL;
80 }
81
82 // ----------------------------------------------------------------------------
83 // tests themselves
84 // ----------------------------------------------------------------------------
85
86 void BoxSizerTestCase::Size1()
87 {
88 const wxSize sizeTotal = m_win->GetClientSize();
89 const wxSize sizeChild = sizeTotal / 2;
90
91 wxWindow * const
92 child = new wxWindow(m_win, wxID_ANY, wxDefaultPosition, sizeChild);
93 m_sizer->Add(child);
94 m_win->Layout();
95 CPPUNIT_ASSERT_EQUAL( sizeChild, child->GetSize() );
96 ;
97 m_sizer->Clear();
98 m_sizer->Add(child, wxSizerFlags(1));
99 m_win->Layout();
100 CPPUNIT_ASSERT_EQUAL( wxSize(sizeTotal.x, sizeChild.y), child->GetSize() );
101
102 m_sizer->Clear();
103 m_sizer->Add(child, wxSizerFlags(1).Expand());
104 m_win->Layout();
105 CPPUNIT_ASSERT_EQUAL( sizeTotal, child->GetSize() );
106 }
107