tests: Fix GDateTime overflow tests on 32-bit architectures

On architectures where sizeof(glong) == 32 bits, there are no problems
with overflow when constructing a GDateTime from a GTimeVal. Adjust the
test for this by basing it on the maximum supported tv_sec value it can
calculate, rather than a fixed ‘known unsupported’ value.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=783841
This commit is contained in:
Philip Withnall 2017-06-16 12:42:32 +01:00
parent 2db7aa4799
commit 30fed3b906

View File

@ -401,7 +401,10 @@ find_maximum_supported_tv_sec (void)
/* Check that trying to create a #GDateTime too far in the future reliably
* fails. With a #GTimeVal, this is subtle, as the tv_usec are added into the
* calculation part-way through. */
* calculation part-way through.
*
* This varies a bit between 32- and 64-bit architectures, due to the
* differences in the size of glong (tv.tv_sec). */
static void
test_GDateTime_new_from_timeval_overflow (void)
{
@ -410,29 +413,33 @@ test_GDateTime_new_from_timeval_overflow (void)
g_test_bug ("782089");
tv.tv_sec = G_MAXLONG;
tv.tv_usec = 0;
dt = g_date_time_new_from_timeval_utc (&tv);
g_assert_null (dt);
dt = g_date_time_new_from_timeval_local (&tv);
g_assert_null (dt);
tv.tv_sec = find_maximum_supported_tv_sec ();
tv.tv_usec = G_USEC_PER_SEC - 1;
g_test_message ("Maximum supported GTimeVal.tv_sec = %lu", tv.tv_sec);
/* Sanity check: do we support the year 2000? */
g_assert_cmpint (tv.tv_sec, >=, 946684800);
dt = g_date_time_new_from_timeval_utc (&tv);
g_assert_nonnull (dt);
g_date_time_unref (dt);
tv.tv_sec++;
tv.tv_usec = 0;
dt = g_date_time_new_from_timeval_local (&tv);
g_assert_nonnull (dt);
g_date_time_unref (dt);
dt = g_date_time_new_from_timeval_utc (&tv);
g_assert_null (dt);
if (tv.tv_sec < G_MAXLONG)
{
tv.tv_sec++;
tv.tv_usec = 0;
dt = g_date_time_new_from_timeval_utc (&tv);
g_assert_null (dt);
dt = g_date_time_new_from_timeval_local (&tv);
g_assert_null (dt);
}
}
static void