From c4e914784aab41984836a5708be2c970df3ba5a3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 19 Oct 2019 20:02:42 +0200 Subject: [PATCH] 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. --- tests/datetime/datetimetest.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/datetime/datetimetest.cpp b/tests/datetime/datetimetest.cpp index 22b4f8dfcd..2a259ea8a9 100644 --- a/tests/datetime/datetimetest.cpp +++ b/tests/datetime/datetimetest.cpp @@ -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() );