Rewrite wxBoxSizer unit test without CppUnit::TestCase
No real changes, just get rid of the old CppUnit-compatible machinery in this unit test.
This commit is contained in:
@@ -25,76 +25,35 @@
|
|||||||
#include "asserthelper.h"
|
#include "asserthelper.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// test class
|
// test fixture
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BoxSizerTestCase : public CppUnit::TestCase
|
class BoxSizerTestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BoxSizerTestCase() { }
|
BoxSizerTestCase()
|
||||||
|
: m_win(new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY)),
|
||||||
virtual void setUp() wxOVERRIDE;
|
m_sizer(new wxBoxSizer(wxHORIZONTAL))
|
||||||
virtual void tearDown() wxOVERRIDE;
|
|
||||||
|
|
||||||
private:
|
|
||||||
CPPUNIT_TEST_SUITE( BoxSizerTestCase );
|
|
||||||
CPPUNIT_TEST( Size1 );
|
|
||||||
CPPUNIT_TEST( Size3 );
|
|
||||||
CPPUNIT_TEST( CalcMin );
|
|
||||||
CPPUNIT_TEST( SetMinSize );
|
|
||||||
CPPUNIT_TEST( BestSizeRespectsMaxSize );
|
|
||||||
CPPUNIT_TEST( RecalcSizesRespectsMaxSize1 );
|
|
||||||
CPPUNIT_TEST( RecalcSizesRespectsMaxSize2 );
|
|
||||||
CPPUNIT_TEST( IncompatibleFlags );
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
|
||||||
|
|
||||||
void Size1();
|
|
||||||
void Size3();
|
|
||||||
void CalcMin();
|
|
||||||
void SetMinSize();
|
|
||||||
void BestSizeRespectsMaxSize();
|
|
||||||
void RecalcSizesRespectsMaxSize1();
|
|
||||||
void RecalcSizesRespectsMaxSize2();
|
|
||||||
void IncompatibleFlags();
|
|
||||||
|
|
||||||
wxWindow *m_win;
|
|
||||||
wxSizer *m_sizer;
|
|
||||||
|
|
||||||
wxDECLARE_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 its 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_win->SetClientSize(127, 35);
|
||||||
|
|
||||||
m_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
||||||
m_win->SetSizer(m_sizer);
|
m_win->SetSizer(m_sizer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxSizerTestCase::tearDown()
|
~BoxSizerTestCase()
|
||||||
{
|
{
|
||||||
delete m_win;
|
delete m_win;
|
||||||
m_win = NULL;
|
|
||||||
|
|
||||||
m_sizer = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
wxWindow* const m_win;
|
||||||
|
wxSizer* const m_sizer;
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// tests themselves
|
// tests themselves
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BoxSizerTestCase::Size1()
|
TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::Size1", "[sizer]")
|
||||||
{
|
{
|
||||||
const wxSize sizeTotal = m_win->GetClientSize();
|
const wxSize sizeTotal = m_win->GetClientSize();
|
||||||
const wxSize sizeChild = sizeTotal / 2;
|
const wxSize sizeChild = sizeTotal / 2;
|
||||||
@@ -128,7 +87,7 @@ void BoxSizerTestCase::Size1()
|
|||||||
CPPUNIT_ASSERT_EQUAL( sizeTotal, child->GetSize() );
|
CPPUNIT_ASSERT_EQUAL( sizeTotal, child->GetSize() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxSizerTestCase::Size3()
|
TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::Size3", "[sizer]")
|
||||||
{
|
{
|
||||||
wxGCC_WARNING_SUPPRESS(missing-field-initializers)
|
wxGCC_WARNING_SUPPRESS(missing-field-initializers)
|
||||||
|
|
||||||
@@ -262,7 +221,7 @@ void BoxSizerTestCase::Size3()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxSizerTestCase::CalcMin()
|
TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::CalcMin", "[sizer]")
|
||||||
{
|
{
|
||||||
static const unsigned NUM_TEST_ITEM = 3;
|
static const unsigned NUM_TEST_ITEM = 3;
|
||||||
|
|
||||||
@@ -313,7 +272,7 @@ void BoxSizerTestCase::CalcMin()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxSizerTestCase::SetMinSize()
|
TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::SetMinSize", "[sizer]")
|
||||||
{
|
{
|
||||||
wxWindow* const child = new wxWindow(m_win, wxID_ANY);
|
wxWindow* const child = new wxWindow(m_win, wxID_ANY);
|
||||||
child->SetInitialSize(wxSize(10, -1));
|
child->SetInitialSize(wxSize(10, -1));
|
||||||
@@ -328,7 +287,7 @@ void BoxSizerTestCase::SetMinSize()
|
|||||||
CPPUNIT_ASSERT_EQUAL( 100, m_sizer->GetMinSize().x );
|
CPPUNIT_ASSERT_EQUAL( 100, m_sizer->GetMinSize().x );
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxSizerTestCase::BestSizeRespectsMaxSize()
|
TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::BestSizeRespectsMaxSize", "[sizer]")
|
||||||
{
|
{
|
||||||
m_sizer->Clear();
|
m_sizer->Clear();
|
||||||
|
|
||||||
@@ -346,7 +305,7 @@ void BoxSizerTestCase::BestSizeRespectsMaxSize()
|
|||||||
CPPUNIT_ASSERT_EQUAL(maxWidth, listbox->GetSize().GetWidth());
|
CPPUNIT_ASSERT_EQUAL(maxWidth, listbox->GetSize().GetWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxSizerTestCase::RecalcSizesRespectsMaxSize1()
|
TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::RecalcSizesRespectsMaxSize1", "[sizer]")
|
||||||
{
|
{
|
||||||
m_sizer->Clear();
|
m_sizer->Clear();
|
||||||
|
|
||||||
@@ -374,7 +333,7 @@ void BoxSizerTestCase::RecalcSizesRespectsMaxSize1()
|
|||||||
CPPUNIT_ASSERT_EQUAL(maxWidth, listbox2->GetSize().GetWidth());
|
CPPUNIT_ASSERT_EQUAL(maxWidth, listbox2->GetSize().GetWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxSizerTestCase::RecalcSizesRespectsMaxSize2()
|
TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::RecalcSizesRespectsMaxSize2", "[sizer]")
|
||||||
{
|
{
|
||||||
m_sizer->Clear();
|
m_sizer->Clear();
|
||||||
|
|
||||||
@@ -400,12 +359,13 @@ void BoxSizerTestCase::RecalcSizesRespectsMaxSize2()
|
|||||||
CPPUNIT_ASSERT_EQUAL(125, child3->GetSize().GetHeight());
|
CPPUNIT_ASSERT_EQUAL(125, child3->GetSize().GetHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxSizerTestCase::IncompatibleFlags()
|
TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::IncompatibleFlags", "[sizer]")
|
||||||
{
|
{
|
||||||
|
// This unhygienic macro relies on having a local variable called "sizer".
|
||||||
#define ASSERT_SIZER_INVALID_FLAGS(f, msg) \
|
#define ASSERT_SIZER_INVALID_FLAGS(f, msg) \
|
||||||
WX_ASSERT_FAILS_WITH_ASSERT_MESSAGE( \
|
WX_ASSERT_FAILS_WITH_ASSERT_MESSAGE( \
|
||||||
"Expected assertion not generated for " msg, \
|
"Expected assertion not generated for " msg, \
|
||||||
m_sizer->Add(10, 10, 0, f) \
|
sizer->Add(10, 10, 0, f) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define ASSERT_SIZER_INCOMPATIBLE_FLAGS(f1, f2) \
|
#define ASSERT_SIZER_INCOMPATIBLE_FLAGS(f1, f2) \
|
||||||
@@ -413,6 +373,9 @@ void BoxSizerTestCase::IncompatibleFlags()
|
|||||||
"using incompatible flags " #f1 " and " #f2 \
|
"using incompatible flags " #f1 " and " #f2 \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// First check with the horizontal sizer, which is what we use by default.
|
||||||
|
wxSizer* sizer = m_sizer;
|
||||||
|
|
||||||
// In horizontal sizers alignment is only used in vertical direction.
|
// In horizontal sizers alignment is only used in vertical direction.
|
||||||
ASSERT_SIZER_INVALID_FLAGS(
|
ASSERT_SIZER_INVALID_FLAGS(
|
||||||
wxALIGN_RIGHT,
|
wxALIGN_RIGHT,
|
||||||
@@ -426,7 +389,7 @@ void BoxSizerTestCase::IncompatibleFlags()
|
|||||||
|
|
||||||
// However using wxALIGN_CENTRE_HORIZONTAL together with
|
// However using wxALIGN_CENTRE_HORIZONTAL together with
|
||||||
// wxALIGN_CENTRE_VERTICAL as done by wxSizerFlags::Centre() should work.
|
// wxALIGN_CENTRE_VERTICAL as done by wxSizerFlags::Centre() should work.
|
||||||
m_sizer->Add(10, 10, wxSizerFlags().Centre());
|
sizer->Add(10, 10, wxSizerFlags().Centre());
|
||||||
|
|
||||||
// Combining two vertical alignment flags doesn't make sense.
|
// Combining two vertical alignment flags doesn't make sense.
|
||||||
ASSERT_SIZER_INCOMPATIBLE_FLAGS(wxALIGN_BOTTOM, wxALIGN_CENTRE_VERTICAL);
|
ASSERT_SIZER_INCOMPATIBLE_FLAGS(wxALIGN_BOTTOM, wxALIGN_CENTRE_VERTICAL);
|
||||||
@@ -437,8 +400,8 @@ void BoxSizerTestCase::IncompatibleFlags()
|
|||||||
|
|
||||||
|
|
||||||
// And now exactly the same thing in the other direction.
|
// And now exactly the same thing in the other direction.
|
||||||
m_sizer = new wxBoxSizer(wxVERTICAL);
|
sizer = new wxBoxSizer(wxVERTICAL);
|
||||||
m_win->SetSizer(m_sizer);
|
m_win->SetSizer(sizer);
|
||||||
|
|
||||||
ASSERT_SIZER_INVALID_FLAGS(
|
ASSERT_SIZER_INVALID_FLAGS(
|
||||||
wxALIGN_BOTTOM,
|
wxALIGN_BOTTOM,
|
||||||
@@ -450,7 +413,7 @@ void BoxSizerTestCase::IncompatibleFlags()
|
|||||||
"using wxALIGN_CENTRE_VERTICAL in a vertical sizer"
|
"using wxALIGN_CENTRE_VERTICAL in a vertical sizer"
|
||||||
);
|
);
|
||||||
|
|
||||||
m_sizer->Add(10, 10, wxSizerFlags().Centre());
|
sizer->Add(10, 10, wxSizerFlags().Centre());
|
||||||
|
|
||||||
ASSERT_SIZER_INCOMPATIBLE_FLAGS(wxALIGN_RIGHT, wxALIGN_CENTRE_HORIZONTAL);
|
ASSERT_SIZER_INCOMPATIBLE_FLAGS(wxALIGN_RIGHT, wxALIGN_CENTRE_HORIZONTAL);
|
||||||
ASSERT_SIZER_INCOMPATIBLE_FLAGS(wxEXPAND, wxALIGN_CENTRE_HORIZONTAL);
|
ASSERT_SIZER_INCOMPATIBLE_FLAGS(wxEXPAND, wxALIGN_CENTRE_HORIZONTAL);
|
||||||
|
Reference in New Issue
Block a user