wxwidgets/tests/sizers/boxsizer.cpp
Vadim Zeitlin a71aeb2426 Ensure that size in the minor direction of box sizer doesn't exceed the total.
This is similar to the previous commit but for the transversal direction of a
box sizer: we could give an item size larger than the size of the sizer itself
making only part of its window visible (and thus potentially making the window
unusable e.g. because the scrollbar wasn't visible at all).

Fix this by always restricting the item size in the minor direction to the
total size available and add a unit test which failed previously and passes
now.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63705 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2010-03-18 15:07:19 +00:00

119 lines
3.3 KiB
C++

///////////////////////////////////////////////////////////////////////////////
// Name: tests/sizers/boxsizer.cpp
// Purpose: Unit tests for wxBoxSizer
// Author: Vadim Zeitlin
// Created: 2010-03-06
// RCS-ID: $Id$
// Copyright: (c) 2010 Vadim Zeitlin <vadim@wxwidgets.org>
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "testprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/sizer.h"
#endif // WX_PRECOMP
inline std::ostream& operator<<(std::ostream& o, const wxSize& s)
{
return o << s.x << 'x' << s.y;
}
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
class BoxSizerTestCase : public CppUnit::TestCase
{
public:
BoxSizerTestCase() { }
virtual void setUp();
virtual void tearDown();
private:
CPPUNIT_TEST_SUITE( BoxSizerTestCase );
CPPUNIT_TEST( Size1 );
CPPUNIT_TEST_SUITE_END();
void Size1();
wxWindow *m_win;
wxSizer *m_sizer;
DECLARE_NO_COPY_CLASS(BoxSizerTestCase)
};
// 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
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BoxSizerTestCase, "BoxSizerTestCase" );
// ----------------------------------------------------------------------------
// test initialization
// ----------------------------------------------------------------------------
void BoxSizerTestCase::setUp()
{
m_win = new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY);
m_win->SetClientSize(127, 35);
m_sizer = new wxBoxSizer(wxHORIZONTAL);
m_win->SetSizer(m_sizer);
}
void BoxSizerTestCase::tearDown()
{
delete m_win;
m_win = NULL;
m_sizer = NULL;
}
// ----------------------------------------------------------------------------
// tests themselves
// ----------------------------------------------------------------------------
void BoxSizerTestCase::Size1()
{
const wxSize sizeTotal = m_win->GetClientSize();
const wxSize sizeChild = sizeTotal / 2;
wxWindow * const
child = new wxWindow(m_win, wxID_ANY, wxDefaultPosition, sizeChild);
m_sizer->Add(child);
m_win->Layout();
CPPUNIT_ASSERT_EQUAL( sizeChild, child->GetSize() );
;
m_sizer->Clear();
m_sizer->Add(child, wxSizerFlags(1));
m_win->Layout();
CPPUNIT_ASSERT_EQUAL( wxSize(sizeTotal.x, sizeChild.y), child->GetSize() );
m_sizer->Clear();
m_sizer->Add(child, wxSizerFlags(1).Expand());
m_win->Layout();
CPPUNIT_ASSERT_EQUAL( sizeTotal, child->GetSize() );
m_sizer->Clear();
m_sizer->Add(child, wxSizerFlags());
m_sizer->SetItemMinSize(child, sizeTotal*2);
m_win->Layout();
CPPUNIT_ASSERT_EQUAL( sizeTotal, child->GetSize() );
m_sizer->Clear();
m_sizer->Add(child, wxSizerFlags().Expand());
m_sizer->SetItemMinSize(child, sizeTotal*2);
m_win->Layout();
CPPUNIT_ASSERT_EQUAL( sizeTotal, child->GetSize() );
}