X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/be8332eb97efb229427486433c7593a67b4b1a4c..5dec941a5ba3c08870ab4b415dd6e5be368fa0f0:/tests/sizers/boxsizer.cpp diff --git a/tests/sizers/boxsizer.cpp b/tests/sizers/boxsizer.cpp index 558f15883b..0266af8b3e 100644 --- a/tests/sizers/boxsizer.cpp +++ b/tests/sizers/boxsizer.cpp @@ -22,10 +22,7 @@ #include "wx/sizer.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 @@ -43,10 +40,12 @@ private: CPPUNIT_TEST_SUITE( BoxSizerTestCase ); CPPUNIT_TEST( Size1 ); CPPUNIT_TEST( Size3 ); + CPPUNIT_TEST( CalcMin ); CPPUNIT_TEST_SUITE_END(); void Size1(); void Size3(); + void CalcMin(); wxWindow *m_win; wxSizer *m_sizer; @@ -57,7 +56,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" ); // ---------------------------------------------------------------------------- @@ -231,7 +230,7 @@ void BoxSizerTestCase::Size3() WX_ASSERT_EQUAL_MESSAGE ( ( - "test %lu, permutation #%d: wrong size for child #%d " + "test %lu, permutation #%lu: wrong size for child #%d " "for total size %d", static_cast(i), static_cast(p), @@ -248,3 +247,54 @@ void BoxSizerTestCase::Size3() } } } + +void BoxSizerTestCase::CalcMin() +{ + static const unsigned NUM_TEST_ITEM = 3; + + static const struct CalcMinTestData + { + // proportions of the elements, if one of them is -1 it means to not + // use this window at all in this test + int prop[NUM_TEST_ITEM]; + + // minimal sizes of the elements in the sizer direction + int minsize[NUM_TEST_ITEM]; + + // the expected minimal sizer size + int total; + } calcMinTestData[] = + { + { { 1, 1, -1 }, { 30, 50, 0 }, 100 }, + { { 1, 1, 0 }, { 30, 50, 20 }, 120 }, + { { 10, 10, -1 }, { 30, 50, 0 }, 100 }, + { { 1, 2, 2 }, { 50, 50, 80 }, 250 }, + { { 1, 2, 2 }, { 100, 50, 80 }, 500 }, + }; + + unsigned n; + wxWindow *child[NUM_TEST_ITEM]; + for ( n = 0; n < NUM_TEST_ITEM; n++ ) + child[n] = new wxWindow(m_win, wxID_ANY); + + for ( unsigned i = 0; i < WXSIZEOF(calcMinTestData); i++ ) + { + m_sizer->Clear(); + + const CalcMinTestData& cmtd = calcMinTestData[i]; + for ( n = 0; n < NUM_TEST_ITEM; n++ ) + { + if ( cmtd.prop[n] != -1 ) + { + child[n]->SetInitialSize(wxSize(cmtd.minsize[n], -1)); + m_sizer->Add(child[n], wxSizerFlags(cmtd.prop[n])); + } + } + + WX_ASSERT_EQUAL_MESSAGE + ( + ("In test #%u", i), + cmtd.total, m_sizer->CalcMin().x + ); + } +}