]>
git.saurik.com Git - wxWidgets.git/blob - tests/sizers/wrapsizer.cpp
a5d857527d90cc59a63c7ee4f020da9d08d95a19
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/sizers/wrapsizer.cpp
3 // Purpose: Unit tests for wxWrapSizer
4 // Author: Catalin Raceanu
7 // Copyright: (c) 2010 wxWidgets development team
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 #include "wx/wrapsizer.h"
26 #include "asserthelper.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 class WrapSizerTestCase
: public CppUnit::TestCase
35 WrapSizerTestCase() { }
38 virtual void tearDown();
41 CPPUNIT_TEST_SUITE( WrapSizerTestCase
);
42 CPPUNIT_TEST( CalcMin
);
43 CPPUNIT_TEST_SUITE_END();
50 DECLARE_NO_COPY_CLASS(WrapSizerTestCase
)
53 // register in the unnamed registry so that these tests are run by default
54 CPPUNIT_TEST_SUITE_REGISTRATION( WrapSizerTestCase
);
56 // also include in it's own registry so that these tests can be run alone
57 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WrapSizerTestCase
, "WrapSizerTestCase" );
59 // ----------------------------------------------------------------------------
60 // test initialization
61 // ----------------------------------------------------------------------------
63 void WrapSizerTestCase::setUp()
65 m_win
= new wxWindow(wxTheApp
->GetTopWindow(), wxID_ANY
);
66 m_win
->SetClientSize(180, 240);
68 m_sizer
= new wxWrapSizer(wxHORIZONTAL
);
69 m_win
->SetSizer(m_sizer
);
72 void WrapSizerTestCase::tearDown()
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 void WrapSizerTestCase::CalcMin()
86 const wxSize sizeTotal
= m_win
->GetClientSize();
87 wxSize sizeMinExpected
;
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
;
94 child1
= new wxWindow(m_win
, wxID_ANY
, wxDefaultPosition
, sizeChild1
);
95 child1
->SetBackgroundColour(*wxRED
);
99 CPPUNIT_ASSERT_EQUAL( sizeMinExpected
, m_sizer
->CalcMin() );
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
);
109 child2
= new wxWindow(m_win
, wxID_ANY
, wxDefaultPosition
, sizeChild2
);
110 child2
->SetBackgroundColour(*wxYELLOW
);
111 m_sizer
->Add(child2
);
114 CPPUNIT_ASSERT_EQUAL( sizeMinExpected
, m_sizer
->CalcMin() );
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
;
122 child3
= new wxWindow(m_win
, wxID_ANY
, wxDefaultPosition
, sizeChild3
);
123 child3
->SetBackgroundColour(*wxGREEN
);
124 m_sizer
->Add(child3
);
127 CPPUNIT_ASSERT_EQUAL( sizeMinExpected
, m_sizer
->CalcMin() );