]> git.saurik.com Git - wxWidgets.git/blame - tests/sizers/wrapsizer.cpp
Disable more tests in wxOSX/PPC build.
[wxWidgets.git] / tests / sizers / wrapsizer.cpp
CommitLineData
e4c903b2
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/sizers/wrapsizer.cpp
3// Purpose: Unit tests for wxWrapSizer
4// Author: Catalin Raceanu
5// Created: 2010-10-23
e3778b4d 6// RCS-ID: $Id$
e4c903b2
VZ
7// Copyright: (c) 2010 wxWidgets development team
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#endif // WX_PRECOMP
23
24#include "wx/wrapsizer.h"
25
26#include "asserthelper.h"
27
28// ----------------------------------------------------------------------------
29// test class
30// ----------------------------------------------------------------------------
31
32class WrapSizerTestCase : public CppUnit::TestCase
33{
34public:
35 WrapSizerTestCase() { }
36
37 virtual void setUp();
38 virtual void tearDown();
39
40private:
41 CPPUNIT_TEST_SUITE( WrapSizerTestCase );
42 CPPUNIT_TEST( CalcMin );
43 CPPUNIT_TEST_SUITE_END();
44
45 void CalcMin();
46
47 wxWindow *m_win;
48 wxSizer *m_sizer;
49
50 DECLARE_NO_COPY_CLASS(WrapSizerTestCase)
51};
52
53// register in the unnamed registry so that these tests are run by default
54CPPUNIT_TEST_SUITE_REGISTRATION( WrapSizerTestCase );
55
e3778b4d 56// also include in its own registry so that these tests can be run alone
e4c903b2
VZ
57CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WrapSizerTestCase, "WrapSizerTestCase" );
58
59// ----------------------------------------------------------------------------
60// test initialization
61// ----------------------------------------------------------------------------
62
63void WrapSizerTestCase::setUp()
64{
65 m_win = new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY);
66 m_win->SetClientSize(180, 240);
67
68 m_sizer = new wxWrapSizer(wxHORIZONTAL);
69 m_win->SetSizer(m_sizer);
70}
71
72void WrapSizerTestCase::tearDown()
73{
74 delete m_win;
75 m_win = NULL;
76
77 m_sizer = NULL;
78}
79
80// ----------------------------------------------------------------------------
81// tests themselves
82// ----------------------------------------------------------------------------
83
84void WrapSizerTestCase::CalcMin()
85{
86 const wxSize sizeTotal = m_win->GetClientSize();
87 wxSize sizeMinExpected;
88
89 // With a single child the min size must be the same as child size.
90 const wxSize sizeChild1 = wxSize(sizeTotal.x/2 - 10, sizeTotal.y/4);
91 sizeMinExpected = sizeChild1;
92
93 wxWindow * const
94 child1 = new wxWindow(m_win, wxID_ANY, wxDefaultPosition, sizeChild1);
95 child1->SetBackgroundColour(*wxRED);
96 m_sizer->Add(child1);
97 m_win->Layout();
98
99 CPPUNIT_ASSERT_EQUAL( sizeMinExpected, m_sizer->CalcMin() );
100
101 // If both children can fit in the same row, the minimal size of the sizer
102 // is determined by the sum of their minimal horizontal dimensions and
103 // the maximum of their minimal vertical dimensions.
104 const wxSize sizeChild2 = wxSize(sizeTotal.x/2 + 10, sizeTotal.y/3);
105 sizeMinExpected.x += sizeChild2.x;
106 sizeMinExpected.y = wxMax(sizeChild1.y, sizeChild2.y);
107
108 wxWindow * const
109 child2 = new wxWindow(m_win, wxID_ANY, wxDefaultPosition, sizeChild2);
110 child2->SetBackgroundColour(*wxYELLOW);
111 m_sizer->Add(child2);
112 m_win->Layout();
113
114 CPPUNIT_ASSERT_EQUAL( sizeMinExpected, m_sizer->CalcMin() );
115
116 // Three children will take at least two rows so the minimal size in
117 // vertical direction must increase.
118 const wxSize sizeChild3 = wxSize(sizeTotal.x/2, sizeTotal.y/5);
119 sizeMinExpected.y += sizeChild3.y;
120
121 wxWindow * const
122 child3 = new wxWindow(m_win, wxID_ANY, wxDefaultPosition, sizeChild3);
123 child3->SetBackgroundColour(*wxGREEN);
124 m_sizer->Add(child3);
125 m_win->Layout();
126
127 CPPUNIT_ASSERT_EQUAL( sizeMinExpected, m_sizer->CalcMin() );
128}