X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df67b58b5b265e1b8afa1ee1a4ba061806a37d8d..1ec4e9c2b72a01a7ba7da569e0f8d04a81aaba10:/tests/sizers/boxsizer.cpp diff --git a/tests/sizers/boxsizer.cpp b/tests/sizers/boxsizer.cpp index 9e7cc5191e..118cacf494 100644 --- a/tests/sizers/boxsizer.cpp +++ b/tests/sizers/boxsizer.cpp @@ -20,12 +20,10 @@ #ifndef WX_PRECOMP #include "wx/app.h" #include "wx/sizer.h" + #include "wx/listbox.h" #endif // WX_PRECOMP -inline std::ostream& operator<<(std::ostream& o, const wxSize& s) -{ - return o << s.x << 'x' << s.y; -} +#include "asserthelper.h" // ---------------------------------------------------------------------------- // test class @@ -44,11 +42,17 @@ private: CPPUNIT_TEST( Size1 ); CPPUNIT_TEST( Size3 ); CPPUNIT_TEST( CalcMin ); + CPPUNIT_TEST( BestSizeRespectsMaxSize ); + CPPUNIT_TEST( RecalcSizesRespectsMaxSize1 ); + CPPUNIT_TEST( RecalcSizesRespectsMaxSize2 ); CPPUNIT_TEST_SUITE_END(); void Size1(); void Size3(); void CalcMin(); + void BestSizeRespectsMaxSize(); + void RecalcSizesRespectsMaxSize1(); + void RecalcSizesRespectsMaxSize2(); wxWindow *m_win; wxSizer *m_sizer; @@ -59,7 +63,7 @@ private: // register in the unnamed registry so that these tests are run by default CPPUNIT_TEST_SUITE_REGISTRATION( BoxSizerTestCase ); -// also include in it's own registry so that these tests can be run alone +// also include in its own registry so that these tests can be run alone CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BoxSizerTestCase, "BoxSizerTestCase" ); // ---------------------------------------------------------------------------- @@ -301,3 +305,75 @@ void BoxSizerTestCase::CalcMin() ); } } + +void BoxSizerTestCase::BestSizeRespectsMaxSize() +{ + m_sizer->Clear(); + + const int maxWidth = 100; + + wxSizer* sizer = new wxBoxSizer(wxVERTICAL); + wxListBox* listbox = new wxListBox(m_win, wxID_ANY); + listbox->Append("some very very very very very very very very very very very long string"); + listbox->SetMaxSize(wxSize(maxWidth, -1)); + sizer->Add(listbox); + + m_sizer->Add(sizer); + m_win->Layout(); + + CPPUNIT_ASSERT_EQUAL(maxWidth, listbox->GetSize().GetWidth()); +} + +void BoxSizerTestCase::RecalcSizesRespectsMaxSize1() +{ + m_sizer->Clear(); + + const int maxWidth = 100; + + m_win->SetClientSize(300, 300); + + wxSizer* sizer1 = new wxBoxSizer(wxVERTICAL); + m_sizer->Add(sizer1); + + wxListBox* listbox1 = new wxListBox(m_win, wxID_ANY); + listbox1->Append("some very very very very very very very very very very very long string"); + sizer1->Add(listbox1); + + wxSizer* sizer2 = new wxBoxSizer(wxHORIZONTAL); + sizer1->Add(sizer2, wxSizerFlags().Expand()); + + wxListBox* listbox2 = new wxListBox(m_win, wxID_ANY); + listbox2->Append("some string"); + listbox2->SetMaxSize(wxSize(100, -1)); + sizer2->Add(listbox2, wxSizerFlags().Proportion(1)); + + m_win->Layout(); + + CPPUNIT_ASSERT_EQUAL(maxWidth, listbox2->GetSize().GetWidth()); +} + +void BoxSizerTestCase::RecalcSizesRespectsMaxSize2() +{ + m_sizer->Clear(); + + m_win->SetClientSize(300, 300); + + wxSizer* sizer1 = new wxBoxSizer(wxVERTICAL); + m_sizer->Add(sizer1, wxSizerFlags().Expand()); + + wxWindow* child1 = new wxWindow(m_win, wxID_ANY); + sizer1->Add(child1, wxSizerFlags().Proportion(1)); + + wxWindow* child2 = new wxWindow(m_win, wxID_ANY); + child2->SetMaxSize(wxSize(-1, 50)); + sizer1->Add(child2, wxSizerFlags().Proportion(1)); + + wxWindow* child3 = new wxWindow(m_win, wxID_ANY); + sizer1->Add(child3, wxSizerFlags().Proportion(1)); + + m_win->Layout(); + + CPPUNIT_ASSERT_EQUAL(125, child1->GetSize().GetHeight()); + CPPUNIT_ASSERT_EQUAL(50, child2->GetSize().GetHeight()); + CPPUNIT_ASSERT_EQUAL(125, child3->GetSize().GetHeight()); +}