]>
git.saurik.com Git - wxWidgets.git/blob - tests/sizers/wrapsizer.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/sizers/wrapsizer.cpp
3 // Purpose: Unit tests for wxWrapSizer
4 // Author: Catalin Raceanu
6 // Copyright: (c) 2010 wxWidgets development team
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
23 #include "wx/wrapsizer.h"
25 #include "asserthelper.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class WrapSizerTestCase
: public CppUnit::TestCase
34 WrapSizerTestCase() { }
37 virtual void tearDown();
40 CPPUNIT_TEST_SUITE( WrapSizerTestCase
);
41 CPPUNIT_TEST( CalcMin
);
42 CPPUNIT_TEST_SUITE_END();
49 DECLARE_NO_COPY_CLASS(WrapSizerTestCase
)
52 // register in the unnamed registry so that these tests are run by default
53 CPPUNIT_TEST_SUITE_REGISTRATION( WrapSizerTestCase
);
55 // also include in its own registry so that these tests can be run alone
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WrapSizerTestCase
, "WrapSizerTestCase" );
58 // ----------------------------------------------------------------------------
59 // test initialization
60 // ----------------------------------------------------------------------------
62 void WrapSizerTestCase::setUp()
64 m_win
= new wxWindow(wxTheApp
->GetTopWindow(), wxID_ANY
);
65 m_win
->SetClientSize(180, 240);
67 m_sizer
= new wxWrapSizer(wxHORIZONTAL
);
68 m_win
->SetSizer(m_sizer
);
71 void WrapSizerTestCase::tearDown()
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 void WrapSizerTestCase::CalcMin()
85 const wxSize sizeTotal
= m_win
->GetClientSize();
86 wxSize sizeMinExpected
;
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
;
93 child1
= new wxWindow(m_win
, wxID_ANY
, wxDefaultPosition
, sizeChild1
);
94 child1
->SetBackgroundColour(*wxRED
);
98 CPPUNIT_ASSERT_EQUAL( sizeMinExpected
, m_sizer
->CalcMin() );
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
);
108 child2
= new wxWindow(m_win
, wxID_ANY
, wxDefaultPosition
, sizeChild2
);
109 child2
->SetBackgroundColour(*wxYELLOW
);
110 m_sizer
->Add(child2
);
113 CPPUNIT_ASSERT_EQUAL( sizeMinExpected
, m_sizer
->CalcMin() );
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
;
121 child3
= new wxWindow(m_win
, wxID_ANY
, wxDefaultPosition
, sizeChild3
);
122 child3
->SetBackgroundColour(*wxGREEN
);
123 m_sizer
->Add(child3
);
126 CPPUNIT_ASSERT_EQUAL( sizeMinExpected
, m_sizer
->CalcMin() );