Merge branch 'more-tests-fixes'
Miscellaneous minor tests fixes/improvements. See https://github.com/wxWidgets/wxWidgets/pull/2442
This commit is contained in:
@@ -19,62 +19,38 @@
|
|||||||
#include "testableframe.h"
|
#include "testableframe.h"
|
||||||
#include "wx/uiaction.h"
|
#include "wx/uiaction.h"
|
||||||
#include "wx/artprov.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
|
// Get operator<<(wxSize) so that wxSize values are shown correctly in case of
|
||||||
//asserthelper.h so they can be reused
|
// a failure of a CHECK() involving them.
|
||||||
#include "asserthelper.h"
|
#include "asserthelper.h"
|
||||||
|
|
||||||
class ButtonTestCase : public CppUnit::TestCase
|
class ButtonTestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ButtonTestCase() { }
|
ButtonTestCase();
|
||||||
|
~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();
|
|
||||||
|
|
||||||
|
protected:
|
||||||
wxButton* m_button;
|
wxButton* m_button;
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(ButtonTestCase);
|
wxDECLARE_NO_COPY_CLASS(ButtonTestCase);
|
||||||
};
|
};
|
||||||
|
|
||||||
// register in the unnamed registry so that these tests are run by default
|
ButtonTestCase::ButtonTestCase()
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
//We use wxTheApp->GetTopWindow() as there is only a single testable frame
|
//We use wxTheApp->GetTopWindow() as there is only a single testable frame
|
||||||
//so it will always be returned
|
//so it will always be returned
|
||||||
m_button = new wxButton(wxTheApp->GetTopWindow(), wxID_ANY, "wxButton");
|
m_button = new wxButton(wxTheApp->GetTopWindow(), wxID_ANY, "wxButton");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonTestCase::tearDown()
|
ButtonTestCase::~ButtonTestCase()
|
||||||
{
|
{
|
||||||
wxDELETE(m_button);
|
delete m_button;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_UIACTIONSIMULATOR
|
#if wxUSE_UIACTIONSIMULATOR
|
||||||
|
|
||||||
void ButtonTestCase::Click()
|
TEST_CASE_METHOD(ButtonTestCase, "Button::Click", "[button]")
|
||||||
{
|
{
|
||||||
//We use the internal class EventCounter which handles connecting and
|
//We use the internal class EventCounter which handles connecting and
|
||||||
//disconnecting the control to the wxTestableFrame
|
//disconnecting the control to the wxTestableFrame
|
||||||
@@ -90,10 +66,10 @@ void ButtonTestCase::Click()
|
|||||||
sim.MouseClick();
|
sim.MouseClick();
|
||||||
wxYield();
|
wxYield();
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( 1, clicked.GetCount() );
|
CHECK( clicked.GetCount() == 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonTestCase::Disabled()
|
TEST_CASE_METHOD(ButtonTestCase, "Button::Disabled", "[button]")
|
||||||
{
|
{
|
||||||
wxUIActionSimulator sim;
|
wxUIActionSimulator sim;
|
||||||
|
|
||||||
@@ -121,12 +97,12 @@ void ButtonTestCase::Disabled()
|
|||||||
sim.MouseClick();
|
sim.MouseClick();
|
||||||
wxYield();
|
wxYield();
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( 0, clicked.GetCount() );
|
CHECK( clicked.GetCount() == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_UIACTIONSIMULATOR
|
#endif // wxUSE_UIACTIONSIMULATOR
|
||||||
|
|
||||||
void ButtonTestCase::Auth()
|
TEST_CASE_METHOD(ButtonTestCase, "Button::Auth", "[button]")
|
||||||
{
|
{
|
||||||
//Some functions only work on specific operating system versions, for
|
//Some functions only work on specific operating system versions, for
|
||||||
//this we need a runtime check
|
//this we need a runtime check
|
||||||
@@ -136,19 +112,19 @@ void ButtonTestCase::Auth()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
//We are running Windows Vista or newer
|
//We are running Windows Vista or newer
|
||||||
CPPUNIT_ASSERT(!m_button->GetAuthNeeded());
|
CHECK(!m_button->GetAuthNeeded());
|
||||||
|
|
||||||
m_button->SetAuthNeeded();
|
m_button->SetAuthNeeded();
|
||||||
|
|
||||||
CPPUNIT_ASSERT(m_button->GetAuthNeeded());
|
CHECK(m_button->GetAuthNeeded());
|
||||||
|
|
||||||
//We test both states
|
//We test both states
|
||||||
m_button->SetAuthNeeded(false);
|
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
|
//Some functions only work on specific platforms in which case we can use
|
||||||
//a preprocessor check
|
//a preprocessor check
|
||||||
@@ -160,25 +136,25 @@ void ButtonTestCase::BitmapMargins()
|
|||||||
|
|
||||||
m_button->SetBitmapMargins(15, 15);
|
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));
|
m_button->SetBitmapMargins(wxSize(20, 20));
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(wxSize(20, 20), m_button->GetBitmapMargins());
|
CHECK( m_button->GetBitmapMargins() == wxSize(20, 20) );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonTestCase::Bitmap()
|
TEST_CASE_METHOD(ButtonTestCase, "Button::Bitmap", "[button]")
|
||||||
{
|
{
|
||||||
//We start with no bitmaps
|
//We start with no bitmaps
|
||||||
CPPUNIT_ASSERT(!m_button->GetBitmap().IsOk());
|
CHECK(!m_button->GetBitmap().IsOk());
|
||||||
|
|
||||||
// Some bitmap, doesn't really matter which.
|
// Some bitmap, doesn't really matter which.
|
||||||
const wxBitmap bmp = wxArtProvider::GetBitmap(wxART_INFORMATION);
|
const wxBitmap bmp = wxArtProvider::GetBitmap(wxART_INFORMATION);
|
||||||
|
|
||||||
m_button->SetBitmap(bmp);
|
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
|
// 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).
|
// updating the bitmap later, as it used to be the case in wxGTK (#18898).
|
||||||
|
@@ -464,7 +464,21 @@ private:
|
|||||||
void SimulateEnter()
|
void SimulateEnter()
|
||||||
{
|
{
|
||||||
wxUIActionSimulator sim;
|
wxUIActionSimulator sim;
|
||||||
|
|
||||||
|
// Calling SetFocus() is somehow not enough to give the focus to this
|
||||||
|
// window when running this test with wxGTK, apparently because the
|
||||||
|
// dialog itself needs to be raised to the front first, so simulate a
|
||||||
|
// click doing this.
|
||||||
|
sim.MouseMove(m_control->GetScreenPosition() + wxPoint(5, 5));
|
||||||
|
wxYield();
|
||||||
|
sim.MouseClick();
|
||||||
|
wxYield();
|
||||||
|
|
||||||
|
// Note that clicking it is still not enough to give it focus with
|
||||||
|
// wxGTK neither, so we still need to call SetFocus() nevertheless: but
|
||||||
|
// now it works.
|
||||||
m_control->SetFocus();
|
m_control->SetFocus();
|
||||||
|
|
||||||
sim.Char(WXK_RETURN);
|
sim.Char(WXK_RETURN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user