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.
This commit is contained in:
Vadim Zeitlin
2017-11-07 15:02:46 +01:00
parent 407d38d9ed
commit 5fb740fed8

View File

@@ -667,11 +667,31 @@ void TextCtrlTestCase::DoPositionToCoordsTestWithStyle(long style)
// last position is in its bounds. // last position is in its bounds.
m_text->SetInsertionPointEnd(); m_text->SetInsertionPointEnd();
CPPUNIT_ASSERT( m_text->PositionToCoords(0).y < 0 ); const int pos = m_text->GetInsertionPoint();
CPPUNIT_ASSERT
( // wxGTK needs to yield here to update the text control.
m_text->PositionToCoords(m_text->GetInsertionPoint()).y <= TEXT_HEIGHT #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() void TextCtrlTestCase::PositionToXYMultiLine()