diff --git a/tests/window/setsize.cpp b/tests/window/setsize.cpp index c12dc40761..37a10842c4 100644 --- a/tests/window/setsize.cpp +++ b/tests/window/setsize.cpp @@ -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 + 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() ); +}