[glib] tests: Fix GDateTime overflow tests on 32-bit architectures
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] tests: Fix GDateTime overflow tests on 32-bit architectures
- Date: Wed, 21 Jun 2017 10:21:57 +0000 (UTC)
commit 30fed3b906f3408aa4fc9a7996fa03cf7b940ebe
Author: Philip Withnall <withnall endlessm com>
Date: Fri Jun 16 12:42:32 2017 +0100
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
glib/tests/gdatetime.c | 35 +++++++++++++++++++++--------------
1 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index db04870..3985445 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]