From 5fb740fed823337ba1757f301c6af738edbf1edd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 15:02:46 +0100 Subject: [PATCH] Add a layout hack to PositionToCoords() unit test for wxGTK The text control needs a few event loop iterations in order to layout itself correctly, so give it up to 1 second to do it in order to avoid spurious test failures that occurred if just a single call to wxYield() were done (or, worse, none at all as it was the case before). Also log the value returned by PositionToCoords() in case of test failures. --- tests/controls/textctrltest.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index f824d92a82..f7877d3b0a 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -667,11 +667,31 @@ void TextCtrlTestCase::DoPositionToCoordsTestWithStyle(long style) // last position is in its bounds. m_text->SetInsertionPointEnd(); - CPPUNIT_ASSERT( m_text->PositionToCoords(0).y < 0 ); - CPPUNIT_ASSERT - ( - m_text->PositionToCoords(m_text->GetInsertionPoint()).y <= TEXT_HEIGHT - ); + const int pos = m_text->GetInsertionPoint(); + + // wxGTK needs to yield here to update the text control. +#ifdef __WXGTK__ + wxStopWatch sw; + while ( m_text->PositionToCoords(0).y == 0 || + m_text->PositionToCoords(pos).y > TEXT_HEIGHT ) + { + if ( sw.Time() > 1000 ) + { + FAIL("Timed out waiting for wxTextCtrl update."); + break; + } + + wxYield(); + } +#endif // __WXGTK__ + + wxPoint coords = m_text->PositionToCoords(0); + INFO("First position coords = " << coords); + CPPUNIT_ASSERT( coords.y < 0 ); + + coords = m_text->PositionToCoords(pos); + INFO("Position is " << pos << ", coords = " << coords); + CPPUNIT_ASSERT( coords.y <= TEXT_HEIGHT ); } void TextCtrlTestCase::PositionToXYMultiLine()