Wait for the TLW to become iconized under GTK in the test

Iconize() doesn't take effect immediately, so wait until it does for up
to some reasonable amount of time.
This commit is contained in:
Vadim Zeitlin
2019-07-15 21:44:08 +02:00
parent 8cdd20667f
commit 8d405b80e4

View File

@@ -20,6 +20,10 @@
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/frame.h" #include "wx/frame.h"
#ifdef __WXGTK__
#include "wx/stopwatch.h"
#endif // __WXGTK__
#endif // WX_PRECOMP #endif // WX_PRECOMP
#include "wx/persist/toplevel.h" #include "wx/persist/toplevel.h"
@@ -88,6 +92,7 @@ TEST_CASE_METHOD(PersistenceTests, "wxPersistTLW", "[persist][tlw]")
} }
// Now try recreating the frame using the restored values. // Now try recreating the frame using the restored values.
bool checkIconized = true;
{ {
wxFrame* const frame = CreatePersistenceTestFrame(); wxFrame* const frame = CreatePersistenceTestFrame();
@@ -106,6 +111,21 @@ TEST_CASE_METHOD(PersistenceTests, "wxPersistTLW", "[persist][tlw]")
frame->Iconize(); frame->Iconize();
frame->Show(); frame->Show();
#ifdef __WXGTK__
wxStopWatch sw;
while ( !frame->IsIconized() )
{
wxYield();
if ( sw.Time() > 500 )
{
// 500ms should be enough for the window to end up iconized.
WARN("Frame wasn't iconized as expected");
checkIconized = false;
break;
}
}
#endif // __WXGTK__
delete frame; delete frame;
} }
@@ -115,8 +135,27 @@ TEST_CASE_METHOD(PersistenceTests, "wxPersistTLW", "[persist][tlw]")
CHECK(wxPersistenceManager::Get().RegisterAndRestore(frame)); CHECK(wxPersistenceManager::Get().RegisterAndRestore(frame));
// As above, we need to show the frame for it to be actually iconized.
frame->Show();
CHECK(!frame->IsMaximized()); CHECK(!frame->IsMaximized());
if ( checkIconized )
{
#ifdef __WXGTK__
wxStopWatch sw;
while ( !frame->IsIconized() )
{
wxYield();
if ( sw.Time() > 500 )
{
INFO("Abandoning wait after " << sw.Time() << "ms");
break;
}
}
#endif // __WXGTK__
CHECK(frame->IsIconized()); CHECK(frame->IsIconized());
}
frame->Restore(); frame->Restore();