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