Use CATCH in WrapSizer unit tests
Use CATCH instead of CppUnit for unit tests of wxWrapSizer.
This commit is contained in:
@@ -24,104 +24,53 @@
|
|||||||
|
|
||||||
#include "asserthelper.h"
|
#include "asserthelper.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
TEST_CASE("wxWrapSizer::CalcMin", "[wxWrapSizer]")
|
||||||
// test class
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
class WrapSizerTestCase : public CppUnit::TestCase
|
|
||||||
{
|
{
|
||||||
public:
|
wxScopedPtr<wxWindow> win(new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY));
|
||||||
WrapSizerTestCase() { }
|
win->SetClientSize(180, 240);
|
||||||
|
|
||||||
virtual void setUp() wxOVERRIDE;
|
wxSizer *sizer = new wxWrapSizer(wxHORIZONTAL);
|
||||||
virtual void tearDown() wxOVERRIDE;
|
win->SetSizer(sizer);
|
||||||
|
|
||||||
private:
|
|
||||||
CPPUNIT_TEST_SUITE( WrapSizerTestCase );
|
|
||||||
CPPUNIT_TEST( CalcMin );
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
|
||||||
|
|
||||||
void CalcMin();
|
|
||||||
|
|
||||||
wxWindow *m_win;
|
|
||||||
wxSizer *m_sizer;
|
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(WrapSizerTestCase);
|
|
||||||
};
|
|
||||||
|
|
||||||
// register in the unnamed registry so that these tests are run by default
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( WrapSizerTestCase );
|
|
||||||
|
|
||||||
// also include in its own registry so that these tests can be run alone
|
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WrapSizerTestCase, "WrapSizerTestCase" );
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// test initialization
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void WrapSizerTestCase::setUp()
|
|
||||||
{
|
|
||||||
m_win = new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY);
|
|
||||||
m_win->SetClientSize(180, 240);
|
|
||||||
|
|
||||||
m_sizer = new wxWrapSizer(wxHORIZONTAL);
|
|
||||||
m_win->SetSizer(m_sizer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WrapSizerTestCase::tearDown()
|
|
||||||
{
|
|
||||||
delete m_win;
|
|
||||||
m_win = NULL;
|
|
||||||
|
|
||||||
m_sizer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// tests themselves
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void WrapSizerTestCase::CalcMin()
|
|
||||||
{
|
|
||||||
const wxSize sizeTotal = m_win->GetClientSize();
|
|
||||||
wxSize sizeMinExpected;
|
wxSize sizeMinExpected;
|
||||||
|
|
||||||
// With a single child the min size must be the same as child size.
|
// With a single child the min size must be the same as child size.
|
||||||
const wxSize sizeChild1 = wxSize(sizeTotal.x/2 - 10, sizeTotal.y/4);
|
const wxSize sizeChild1 = wxSize(80, 60);
|
||||||
sizeMinExpected = sizeChild1;
|
sizeMinExpected = sizeChild1;
|
||||||
|
|
||||||
wxWindow * const
|
wxWindow * const
|
||||||
child1 = new wxWindow(m_win, wxID_ANY, wxDefaultPosition, sizeChild1);
|
child1 = new wxWindow(win.get(), wxID_ANY, wxDefaultPosition, sizeChild1);
|
||||||
child1->SetBackgroundColour(*wxRED);
|
child1->SetBackgroundColour(*wxRED);
|
||||||
m_sizer->Add(child1);
|
sizer->Add(child1);
|
||||||
m_win->Layout();
|
win->Layout();
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( sizeMinExpected, m_sizer->CalcMin() );
|
CHECK( sizeMinExpected == sizer->CalcMin() );
|
||||||
|
|
||||||
// If both children can fit in the same row, the minimal size of the sizer
|
// If both children can fit in the same row, the minimal size of the sizer
|
||||||
// is determined by the sum of their minimal horizontal dimensions and
|
// is determined by the sum of their minimal horizontal dimensions and
|
||||||
// the maximum of their minimal vertical dimensions.
|
// the maximum of their minimal vertical dimensions.
|
||||||
const wxSize sizeChild2 = wxSize(sizeTotal.x/2 + 10, sizeTotal.y/3);
|
const wxSize sizeChild2 = wxSize(100, 80);
|
||||||
sizeMinExpected.x += sizeChild2.x;
|
sizeMinExpected.x += sizeChild2.x;
|
||||||
sizeMinExpected.y = wxMax(sizeChild1.y, sizeChild2.y);
|
sizeMinExpected.y = wxMax(sizeChild1.y, sizeChild2.y);
|
||||||
|
|
||||||
wxWindow * const
|
wxWindow * const
|
||||||
child2 = new wxWindow(m_win, wxID_ANY, wxDefaultPosition, sizeChild2);
|
child2 = new wxWindow(win.get(), wxID_ANY, wxDefaultPosition, sizeChild2);
|
||||||
child2->SetBackgroundColour(*wxYELLOW);
|
child2->SetBackgroundColour(*wxYELLOW);
|
||||||
m_sizer->Add(child2);
|
sizer->Add(child2);
|
||||||
m_win->Layout();
|
win->Layout();
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( sizeMinExpected, m_sizer->CalcMin() );
|
CHECK( sizeMinExpected == sizer->CalcMin() );
|
||||||
|
|
||||||
// Three children will take at least two rows so the minimal size in
|
// Three children will take at least two rows so the minimal size in
|
||||||
// vertical direction must increase.
|
// vertical direction must increase.
|
||||||
const wxSize sizeChild3 = wxSize(sizeTotal.x/2, sizeTotal.y/5);
|
const wxSize sizeChild3 = wxSize(90, 40);
|
||||||
sizeMinExpected.y += sizeChild3.y;
|
sizeMinExpected.y += sizeChild3.y;
|
||||||
|
|
||||||
wxWindow * const
|
wxWindow * const
|
||||||
child3 = new wxWindow(m_win, wxID_ANY, wxDefaultPosition, sizeChild3);
|
child3 = new wxWindow(win.get(), wxID_ANY, wxDefaultPosition, sizeChild3);
|
||||||
child3->SetBackgroundColour(*wxGREEN);
|
child3->SetBackgroundColour(*wxGREEN);
|
||||||
m_sizer->Add(child3);
|
sizer->Add(child3);
|
||||||
m_win->Layout();
|
win->Layout();
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( sizeMinExpected, m_sizer->CalcMin() );
|
CHECK( sizeMinExpected == sizer->CalcMin() );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user