mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-14 08:16:24 +01:00
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:
parent
2db7aa4799
commit
30fed3b906
@ -401,7 +401,10 @@ find_maximum_supported_tv_sec (void)
|
|||||||
|
|
||||||
/* Check that trying to create a #GDateTime too far in the future reliably
|
/* 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
|
* 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
|
static void
|
||||||
test_GDateTime_new_from_timeval_overflow (void)
|
test_GDateTime_new_from_timeval_overflow (void)
|
||||||
{
|
{
|
||||||
@ -410,29 +413,33 @@ test_GDateTime_new_from_timeval_overflow (void)
|
|||||||
|
|
||||||
g_test_bug ("782089");
|
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_sec = find_maximum_supported_tv_sec ();
|
||||||
tv.tv_usec = G_USEC_PER_SEC - 1;
|
tv.tv_usec = G_USEC_PER_SEC - 1;
|
||||||
|
|
||||||
g_test_message ("Maximum supported GTimeVal.tv_sec = %lu", tv.tv_sec);
|
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);
|
dt = g_date_time_new_from_timeval_utc (&tv);
|
||||||
g_assert_nonnull (dt);
|
g_assert_nonnull (dt);
|
||||||
g_date_time_unref (dt);
|
g_date_time_unref (dt);
|
||||||
|
|
||||||
tv.tv_sec++;
|
dt = g_date_time_new_from_timeval_local (&tv);
|
||||||
tv.tv_usec = 0;
|
g_assert_nonnull (dt);
|
||||||
|
g_date_time_unref (dt);
|
||||||
|
|
||||||
dt = g_date_time_new_from_timeval_utc (&tv);
|
if (tv.tv_sec < G_MAXLONG)
|
||||||
g_assert_null (dt);
|
{
|
||||||
|
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
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user