From d5a6a5a627762f28bc456ed6657fa1ec9eda1f96 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Fri, 15 Mar 2019 00:09:35 +0700 Subject: [PATCH] Add unit test for wxWrapSizer::CalcMinFromMinor Add a unit test for a special case of a wrap sizer min size caclulation. Test wxWrapSizer::CalcMinFromMinor function for this case, when a wrap sizer used inside a sizer with the same alignment. --- tests/sizers/wrapsizer.cpp | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/sizers/wrapsizer.cpp b/tests/sizers/wrapsizer.cpp index e167c5db45..28278a19e4 100644 --- a/tests/sizers/wrapsizer.cpp +++ b/tests/sizers/wrapsizer.cpp @@ -74,3 +74,42 @@ TEST_CASE("wxWrapSizer::CalcMin", "[wxWrapSizer]") CHECK( sizeMinExpected == sizer->CalcMin() ); } + +TEST_CASE("wxWrapSizer::CalcMinFromMinor", "[wxWrapSizer]") +{ + wxScopedPtr win(new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY)); + win->SetClientSize(180, 240); + + wxSizer* boxSizer = new wxBoxSizer(wxHORIZONTAL); + win->SetSizer(boxSizer); + + // To test CalcMinFromMinor function the wrap sizer with the + // horizonral align added to the box sizer with horizontal align. + wxSizer* wrapSizer = new wxWrapSizer(wxHORIZONTAL); + boxSizer->Add(wrapSizer); + + // Add three child windows. Sum of the first and the second windows widths should + // be less than the width of the third window. + const wxSize sizeChild1 = wxSize(40, 60); + wxWindow * const + child1 = new wxWindow(win.get(), wxID_ANY, wxDefaultPosition, sizeChild1); + child1->SetBackgroundColour(*wxRED); + wrapSizer->Add(child1); + + const wxSize sizeChild2 = wxSize(50, 80); + wxWindow * const + child2 = new wxWindow(win.get(), wxID_ANY, wxDefaultPosition, sizeChild2); + child2->SetBackgroundColour(*wxGREEN); + wrapSizer->Add(child2); + + const wxSize sizeChild3 = wxSize(100, 120); + wxWindow * const + child3 = new wxWindow(win.get(), wxID_ANY, wxDefaultPosition, sizeChild3); + child3->SetBackgroundColour(*wxBLUE); + wrapSizer->Add(child3); + + // First two windows should be in a first row and the third in a second row. + const wxSize sizeMinExpected = wxSize(sizeChild3.x, sizeChild2.y + sizeChild3.y); + win->Layout(); + CHECK(sizeMinExpected == wrapSizer->CalcMin()); +}