Guard against Now() and UNow() returning different second values

Avoid spurious error in the unit test by calling Now() and UNow() a few
times in a row until they return the same second, as we may be unlucky
enough for this not to be the case when we call them just once.
This commit is contained in:
Vadim Zeitlin 2019-10-19 20:02:42 +02:00
parent b2ad5aa1d9
commit c4e914784a

View File

@ -1703,8 +1703,17 @@ TEST_CASE("wxDateTime-BST-bugs", "[datetime][dst][BST][.]")
TEST_CASE("wxDateTime::UNow", "[datetime][now][unow]")
{
const wxDateTime now = wxDateTime::Now();
const wxDateTime unow = wxDateTime::UNow();
// It's unlikely, but possible, that the consecutive functions are called
// on different sides of some second boundary, but it really shouldn't
// happen more than once in a row.
wxDateTime now, unow;
for ( int i = 0; i < 3; ++i )
{
now = wxDateTime::Now();
unow = wxDateTime::UNow();
if ( now.GetSecond() == unow.GetSecond() )
break;
}
CHECK( now.GetYear() == unow.GetYear() );
CHECK( now.GetMonth() == unow.GetMonth() );