Get rid of CppUnit boilerplate in wxButton unit tests

No real changes, just simplify the code by using CATCH directly.
This commit is contained in:
Vadim Zeitlin 2021-07-22 19:15:07 +02:00
parent c175b31630
commit e6bac095ca

View File

@ -19,62 +19,38 @@
#include "testableframe.h"
#include "wx/uiaction.h"
#include "wx/artprov.h"
//For CPPUNIT_ASSERT_EQUAL to work a class must have a stream output function
//for those classes which do not have them by default we define them in
//asserthelper.h so they can be reused
// Get operator<<(wxSize) so that wxSize values are shown correctly in case of
// a failure of a CHECK() involving them.
#include "asserthelper.h"
class ButtonTestCase : public CppUnit::TestCase
class ButtonTestCase
{
public:
ButtonTestCase() { }
void setUp() wxOVERRIDE;
void tearDown() wxOVERRIDE;
private:
CPPUNIT_TEST_SUITE( ButtonTestCase );
//We add tests that use wxUIActionSimulator with WXUISIM_TEST so they
//are not run on platofrms were wxUIActionSimulator isn't supported
WXUISIM_TEST( Click );
WXUISIM_TEST( Disabled );
CPPUNIT_TEST( Auth );
CPPUNIT_TEST( BitmapMargins );
CPPUNIT_TEST( Bitmap );
CPPUNIT_TEST_SUITE_END();
void Click();
void Disabled();
void Auth();
void BitmapMargins();
void Bitmap();
ButtonTestCase();
~ButtonTestCase();
protected:
wxButton* m_button;
wxDECLARE_NO_COPY_CLASS(ButtonTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( ButtonTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ButtonTestCase, "ButtonTestCase" );
void ButtonTestCase::setUp()
ButtonTestCase::ButtonTestCase()
{
//We use wxTheApp->GetTopWindow() as there is only a single testable frame
//so it will always be returned
m_button = new wxButton(wxTheApp->GetTopWindow(), wxID_ANY, "wxButton");
}
void ButtonTestCase::tearDown()
ButtonTestCase::~ButtonTestCase()
{
wxDELETE(m_button);
delete m_button;
}
#if wxUSE_UIACTIONSIMULATOR
void ButtonTestCase::Click()
TEST_CASE_METHOD(ButtonTestCase, "Button::Click", "[button]")
{
//We use the internal class EventCounter which handles connecting and
//disconnecting the control to the wxTestableFrame
@ -90,10 +66,10 @@ void ButtonTestCase::Click()
sim.MouseClick();
wxYield();
CPPUNIT_ASSERT_EQUAL( 1, clicked.GetCount() );
CHECK( clicked.GetCount() == 1 );
}
void ButtonTestCase::Disabled()
TEST_CASE_METHOD(ButtonTestCase, "Button::Disabled", "[button]")
{
wxUIActionSimulator sim;
@ -121,12 +97,12 @@ void ButtonTestCase::Disabled()
sim.MouseClick();
wxYield();
CPPUNIT_ASSERT_EQUAL( 0, clicked.GetCount() );
CHECK( clicked.GetCount() == 0 );
}
#endif // wxUSE_UIACTIONSIMULATOR
void ButtonTestCase::Auth()
TEST_CASE_METHOD(ButtonTestCase, "Button::Auth", "[button]")
{
//Some functions only work on specific operating system versions, for
//this we need a runtime check
@ -136,19 +112,19 @@ void ButtonTestCase::Auth()
return;
//We are running Windows Vista or newer
CPPUNIT_ASSERT(!m_button->GetAuthNeeded());
CHECK(!m_button->GetAuthNeeded());
m_button->SetAuthNeeded();
CPPUNIT_ASSERT(m_button->GetAuthNeeded());
CHECK(m_button->GetAuthNeeded());
//We test both states
m_button->SetAuthNeeded(false);
CPPUNIT_ASSERT(!m_button->GetAuthNeeded());
CHECK(!m_button->GetAuthNeeded());
}
void ButtonTestCase::BitmapMargins()
TEST_CASE_METHOD(ButtonTestCase, "Button::BitmapMargins", "[button]")
{
//Some functions only work on specific platforms in which case we can use
//a preprocessor check
@ -160,25 +136,25 @@ void ButtonTestCase::BitmapMargins()
m_button->SetBitmapMargins(15, 15);
CPPUNIT_ASSERT_EQUAL(wxSize(15, 15), m_button->GetBitmapMargins());
CHECK( m_button->GetBitmapMargins() == wxSize(15, 15) );
m_button->SetBitmapMargins(wxSize(20, 20));
CPPUNIT_ASSERT_EQUAL(wxSize(20, 20), m_button->GetBitmapMargins());
CHECK( m_button->GetBitmapMargins() == wxSize(20, 20) );
#endif
}
void ButtonTestCase::Bitmap()
TEST_CASE_METHOD(ButtonTestCase, "Button::Bitmap", "[button]")
{
//We start with no bitmaps
CPPUNIT_ASSERT(!m_button->GetBitmap().IsOk());
CHECK(!m_button->GetBitmap().IsOk());
// Some bitmap, doesn't really matter which.
const wxBitmap bmp = wxArtProvider::GetBitmap(wxART_INFORMATION);
m_button->SetBitmap(bmp);
CPPUNIT_ASSERT(m_button->GetBitmap().IsOk());
CHECK(m_button->GetBitmap().IsOk());
// Check that resetting the button label doesn't result in problems when
// updating the bitmap later, as it used to be the case in wxGTK (#18898).