Get rid of CppUnit boilerplate in wxGridSizer unit test

No real changes, just simplify and use CHECK() instead of
CPPUNIT_ASSERT_EQUAL() (which is the same as REQUIRE()).
This commit is contained in:
Vadim Zeitlin
2021-01-25 00:48:30 +01:00
parent b48c46285c
commit 08d8d12872

View File

@@ -25,23 +25,11 @@
// test class // test class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class GridSizerTestCase : public CppUnit::TestCase class GridSizerTestCase
{ {
public: protected:
GridSizerTestCase() { } GridSizerTestCase();
~GridSizerTestCase();
virtual void setUp() wxOVERRIDE;
virtual void tearDown() wxOVERRIDE;
private:
CPPUNIT_TEST_SUITE( GridSizerTestCase );
CPPUNIT_TEST( Expand );
CPPUNIT_TEST( IncompatibleFlags );
CPPUNIT_TEST_SUITE_END();
void Expand();
void IncompatibleFlags();
// Clear the current sizer contents and add the specified windows to it, // Clear the current sizer contents and add the specified windows to it,
// using the same flags for all of them. // using the same flags for all of them.
void SetChildren(const wxVector<wxWindow*>& children, void SetChildren(const wxVector<wxWindow*>& children,
@@ -53,17 +41,11 @@ private:
wxDECLARE_NO_COPY_CLASS(GridSizerTestCase); wxDECLARE_NO_COPY_CLASS(GridSizerTestCase);
}; };
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( GridSizerTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( GridSizerTestCase, "GridSizerTestCase" );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// test initialization // test initialization
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void GridSizerTestCase::setUp() GridSizerTestCase::GridSizerTestCase()
{ {
m_win = new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY); m_win = new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY);
m_win->SetClientSize(127, 35); m_win->SetClientSize(127, 35);
@@ -72,7 +54,7 @@ void GridSizerTestCase::setUp()
m_win->SetSizer(m_sizer); m_win->SetSizer(m_sizer);
} }
void GridSizerTestCase::tearDown() GridSizerTestCase::~GridSizerTestCase()
{ {
delete m_win; delete m_win;
m_win = NULL; m_win = NULL;
@@ -102,7 +84,9 @@ void GridSizerTestCase::SetChildren(const wxVector<wxWindow*>& children,
// tests themselves // tests themselves
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void GridSizerTestCase::Expand() TEST_CASE_METHOD(GridSizerTestCase,
"wxGridSizer::Expand",
"[grid-sizer][sizer]")
{ {
const wxSize sizeTotal = m_win->GetClientSize(); const wxSize sizeTotal = m_win->GetClientSize();
const wxSize sizeChild(sizeTotal.x / 4, sizeTotal.y / 4); const wxSize sizeChild(sizeTotal.x / 4, sizeTotal.y / 4);
@@ -121,42 +105,38 @@ void GridSizerTestCase::Expand()
// Without Expand() windows have their initial size. // Without Expand() windows have their initial size.
SetChildren(children, wxSizerFlags()); SetChildren(children, wxSizerFlags());
CPPUNIT_ASSERT_EQUAL( sizeChild, children[0]->GetSize() ); CHECK( children[0]->GetSize() == sizeChild );
CPPUNIT_ASSERT_EQUAL( sizeChild, children[1]->GetSize() ); CHECK( children[1]->GetSize() == sizeChild );
CPPUNIT_ASSERT_EQUAL( sizeChild, children[2]->GetSize() ); CHECK( children[2]->GetSize() == sizeChild );
CPPUNIT_ASSERT_EQUAL( sizeChild, children[3]->GetSize() ); CHECK( children[3]->GetSize() == sizeChild );
// With just expand, they expand to fill the entire column and the row // With just expand, they expand to fill the entire column and the row
// containing them (which may or not expand on its own). // containing them (which may or not expand on its own).
SetChildren(children, wxSizerFlags().Expand()); SetChildren(children, wxSizerFlags().Expand());
CPPUNIT_ASSERT_EQUAL( sizeChild, children[0]->GetSize() ); CHECK( children[0]->GetSize() == sizeChild );
CPPUNIT_ASSERT_EQUAL( wxSize(sizeRest.x, sizeChild.y), CHECK( children[1]->GetSize() == wxSize(sizeRest.x, sizeChild.y) );
children[1]->GetSize() ); CHECK( children[2]->GetSize() == wxSize(sizeChild.x, sizeRest.y) );
CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y), CHECK( children[3]->GetSize() == sizeRest );
children[2]->GetSize() );
CPPUNIT_ASSERT_EQUAL( sizeRest, children[3]->GetSize() );
// With expand and another alignment flag, they should expand only in the // With expand and another alignment flag, they should expand only in the
// direction in which the alignment is not given. // direction in which the alignment is not given.
SetChildren(children, wxSizerFlags().Expand().CentreVertical()); SetChildren(children, wxSizerFlags().Expand().CentreVertical());
CPPUNIT_ASSERT_EQUAL( sizeChild, children[0]->GetSize() ); CHECK( children[0]->GetSize() == sizeChild );
CPPUNIT_ASSERT_EQUAL( wxSize(sizeRest.x, sizeChild.y), CHECK( children[1]->GetSize() == wxSize(sizeRest.x, sizeChild.y) );
children[1]->GetSize() ); CHECK( children[2]->GetSize() == sizeChild );
CPPUNIT_ASSERT_EQUAL( sizeChild, children[2]->GetSize() ); CHECK( children[3]->GetSize() == wxSize(sizeRest.x, sizeChild.y) );
CPPUNIT_ASSERT_EQUAL( wxSize(sizeRest.x, sizeChild.y),
children[3]->GetSize() );
// Same as above but mirrored. // Same as above but mirrored.
SetChildren(children, wxSizerFlags().Expand().CentreHorizontal()); SetChildren(children, wxSizerFlags().Expand().CentreHorizontal());
CPPUNIT_ASSERT_EQUAL( sizeChild, children[0]->GetSize() ); CHECK( children[0]->GetSize() == sizeChild );
CPPUNIT_ASSERT_EQUAL( sizeChild, children[1]->GetSize() ); CHECK( children[1]->GetSize() == sizeChild );
CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y), CHECK( children[2]->GetSize() == wxSize(sizeChild.x, sizeRest.y) );
children[2]->GetSize() ); CHECK( children[3]->GetSize() == wxSize(sizeChild.x, sizeRest.y) );
CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y),
children[3]->GetSize() );
} }
void GridSizerTestCase::IncompatibleFlags() TEST_CASE_METHOD(GridSizerTestCase,
"wxGridSizer::IncompatibleFlags",
"[grid-sizer][sizer]")
{ {
WX_ASSERT_FAILS_WITH_ASSERT_MESSAGE WX_ASSERT_FAILS_WITH_ASSERT_MESSAGE
( (