Add a unit test checking that Move() doesn't change frame size
This used to be broken in wxQt until it was fixed by the previous commit. See https://github.com/swig/swig/pull/1613
This commit is contained in:
parent
be22e8fa95
commit
da8cecbfe5
@ -18,10 +18,12 @@
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#include "wx/frame.h"
|
||||
#include "wx/window.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/scopedptr.h"
|
||||
#include "wx/stopwatch.h"
|
||||
|
||||
#include "asserthelper.h"
|
||||
|
||||
@ -45,6 +47,29 @@ protected:
|
||||
virtual wxSize DoGetBestSize() const wxOVERRIDE { return wxSize(50, 250); }
|
||||
};
|
||||
|
||||
// Class used to check if we received the (first) paint event.
|
||||
class WaitForPaint
|
||||
{
|
||||
public:
|
||||
// Note that we have to use a pointer here, i.e. we can't just store the
|
||||
// flag inside the class itself because it's going to be cloned inside wx
|
||||
// and querying the flag of the original copy is not going to work.
|
||||
explicit WaitForPaint(bool* painted)
|
||||
: m_painted(*painted)
|
||||
{
|
||||
m_painted = false;
|
||||
}
|
||||
|
||||
void operator()(wxPaintEvent& event)
|
||||
{
|
||||
event.Skip();
|
||||
m_painted = true;
|
||||
}
|
||||
|
||||
private:
|
||||
bool& m_painted;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -84,3 +109,38 @@ TEST_CASE("wxWindow::GetBestSize", "[window][size][best-size]")
|
||||
w->SetMaxSize(wxSize(200, 200));
|
||||
CHECK( wxSize(100, 200) == w->GetBestSize() );
|
||||
}
|
||||
|
||||
TEST_CASE("wxWindow::MovePreservesSize", "[window][size][move]")
|
||||
{
|
||||
wxScopedPtr<wxWindow>
|
||||
w(new wxFrame(wxTheApp->GetTopWindow(), wxID_ANY, "Test child frame"));
|
||||
|
||||
// Unfortunately showing the window is asynchronous, at least when using
|
||||
// X11, so we have to wait for some time before retrieving its true
|
||||
// geometry. And it's not clear how long should we wait, so we do it until
|
||||
// we get the first paint event -- by then the window really should have
|
||||
// its final size.
|
||||
bool painted;
|
||||
WaitForPaint waitForPaint(&painted);
|
||||
w->Bind(wxEVT_PAINT, waitForPaint);
|
||||
|
||||
w->Show();
|
||||
|
||||
wxStopWatch sw;
|
||||
while ( !painted )
|
||||
{
|
||||
wxYield();
|
||||
|
||||
if ( sw.Time() > 250 )
|
||||
{
|
||||
WARN("Didn't get a paint event until timeout expiration");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const wxRect rectOrig = w->GetRect();
|
||||
|
||||
// Check that moving the window doesn't change its size.
|
||||
w->Move(rectOrig.GetPosition() + wxPoint(100, 100));
|
||||
CHECK( w->GetSize() == rectOrig.GetSize() );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user