From 8d405b80e43f0b314429fd1f8f9eaaeca8590022 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 15 Jul 2019 21:44:08 +0200 Subject: [PATCH] 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. --- tests/persistence/tlw.cpp | 41 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/persistence/tlw.cpp b/tests/persistence/tlw.cpp index e78d7e36ac..47a346d4af 100644 --- a/tests/persistence/tlw.cpp +++ b/tests/persistence/tlw.cpp @@ -20,6 +20,10 @@ #ifndef WX_PRECOMP #include "wx/frame.h" + + #ifdef __WXGTK__ + #include "wx/stopwatch.h" + #endif // __WXGTK__ #endif // WX_PRECOMP #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. + bool checkIconized = true; { wxFrame* const frame = CreatePersistenceTestFrame(); @@ -106,6 +111,21 @@ TEST_CASE_METHOD(PersistenceTests, "wxPersistTLW", "[persist][tlw]") frame->Iconize(); 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; } @@ -115,8 +135,27 @@ TEST_CASE_METHOD(PersistenceTests, "wxPersistTLW", "[persist][tlw]") 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->IsIconized()); + 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()); + } frame->Restore();