Add test really checking wxGridSizer::Layout()
The existing test with this name only checked wxFlexGridSizer::Layout() and the base class uses a different implementation, which merits its own unit test.
This commit is contained in:
parent
46bfb43d21
commit
7ae9e9b974
1 changed files with 58 additions and 19 deletions
|
|
@ -22,59 +22,79 @@
|
|||
#include "asserthelper.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// test fixtures
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class GridSizerTestCase
|
||||
// Base class for the two fixtures below.
|
||||
class GridSizerTestCaseBase
|
||||
{
|
||||
protected:
|
||||
GridSizerTestCase();
|
||||
~GridSizerTestCase();
|
||||
explicit GridSizerTestCaseBase(wxGridSizer* sizer);
|
||||
~GridSizerTestCaseBase();
|
||||
// Clear the current sizer contents and add the specified windows to it,
|
||||
// using the same flags for all of them.
|
||||
void SetChildren(const wxVector<wxWindow*>& children,
|
||||
const wxSizerFlags& flags);
|
||||
|
||||
wxWindow *m_win;
|
||||
wxFlexGridSizer *m_sizer;
|
||||
wxGridSizer* const m_sizerBase;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(GridSizerTestCase);
|
||||
wxDECLARE_NO_COPY_CLASS(GridSizerTestCaseBase);
|
||||
};
|
||||
|
||||
class GridSizerTestCase : public GridSizerTestCaseBase
|
||||
{
|
||||
protected:
|
||||
GridSizerTestCase()
|
||||
: GridSizerTestCaseBase(m_sizer = new wxGridSizer(2))
|
||||
{
|
||||
}
|
||||
|
||||
wxGridSizer *m_sizer;
|
||||
};
|
||||
|
||||
class FlexGridSizerTestCase : public GridSizerTestCaseBase
|
||||
{
|
||||
protected:
|
||||
FlexGridSizerTestCase()
|
||||
: GridSizerTestCaseBase(m_sizer = new wxFlexGridSizer(2))
|
||||
{
|
||||
}
|
||||
|
||||
wxFlexGridSizer *m_sizer;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test initialization
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
GridSizerTestCase::GridSizerTestCase()
|
||||
GridSizerTestCaseBase::GridSizerTestCaseBase(wxGridSizer* sizer)
|
||||
: m_sizerBase(sizer)
|
||||
{
|
||||
m_win = new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY);
|
||||
m_win->SetClientSize(127, 35);
|
||||
|
||||
m_sizer = new wxFlexGridSizer(2);
|
||||
m_win->SetSizer(m_sizer);
|
||||
m_win->SetSizer(m_sizerBase);
|
||||
}
|
||||
|
||||
GridSizerTestCase::~GridSizerTestCase()
|
||||
GridSizerTestCaseBase::~GridSizerTestCaseBase()
|
||||
{
|
||||
delete m_win;
|
||||
m_win = nullptr;
|
||||
|
||||
m_sizer = nullptr;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helpers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void GridSizerTestCase::SetChildren(const wxVector<wxWindow*>& children,
|
||||
void GridSizerTestCaseBase::SetChildren(const wxVector<wxWindow*>& children,
|
||||
const wxSizerFlags& flags)
|
||||
{
|
||||
m_sizer->Clear();
|
||||
m_sizerBase->Clear();
|
||||
for ( wxVector<wxWindow*>::const_iterator i = children.begin();
|
||||
i != children.end();
|
||||
++i )
|
||||
{
|
||||
m_sizer->Add(*i, flags);
|
||||
m_sizerBase->Add(*i, flags);
|
||||
}
|
||||
|
||||
m_win->Layout();
|
||||
|
|
@ -87,6 +107,25 @@ void GridSizerTestCase::SetChildren(const wxVector<wxWindow*>& children,
|
|||
TEST_CASE_METHOD(GridSizerTestCase,
|
||||
"wxGridSizer::Layout",
|
||||
"[grid-sizer][sizer]")
|
||||
{
|
||||
const wxSize sizeTotal = m_win->GetClientSize();
|
||||
const wxSize sizeChild(sizeTotal.x / 2, sizeTotal.y / 2);
|
||||
|
||||
wxVector<wxWindow*> children;
|
||||
for ( int n = 0; n < 3; n++ )
|
||||
{
|
||||
children.push_back(new wxWindow(m_win, wxID_ANY));
|
||||
}
|
||||
|
||||
SetChildren(children, wxSizerFlags().Expand());
|
||||
CHECK( children[0]->GetRect() == wxRect(wxPoint(0, 0), sizeChild) );
|
||||
CHECK( children[1]->GetRect() == wxRect(wxPoint(sizeChild.x, 0), sizeChild) );
|
||||
CHECK( children[2]->GetRect() == wxRect(wxPoint(0, sizeChild.y), sizeChild) );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(FlexGridSizerTestCase,
|
||||
"wxFlexGridSizer::Layout",
|
||||
"[grid-sizer][sizer]")
|
||||
{
|
||||
const wxSize sizeTotal = m_win->GetClientSize();
|
||||
const wxSize sizeChild(sizeTotal.x / 4, sizeTotal.y / 4);
|
||||
|
|
@ -180,8 +219,8 @@ TEST_CASE_METHOD(GridSizerTestCase,
|
|||
);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(GridSizerTestCase,
|
||||
"wxGridSizer::GrowMode",
|
||||
TEST_CASE_METHOD(FlexGridSizerTestCase,
|
||||
"wxFlexGridSizer::GrowMode",
|
||||
"[grid-sizer][sizer]")
|
||||
{
|
||||
wxVector<wxWindow*> children;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue