[glib: 1/4] tests: Add test for overflow handling in g_time_val_to_iso8601()



commit 725eb1c86bed3a1f6be532fe4cdbb07543b9add6
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Aug 7 11:00:00 2018 +0100

    tests: Add test for overflow handling in g_time_val_to_iso8601()
    
    While I’m here…
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 glib/tests/timer.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
diff --git a/glib/tests/timer.c b/glib/tests/timer.c
index f40a278b4..f0d070684 100644
--- a/glib/tests/timer.c
+++ b/glib/tests/timer.c
@@ -230,6 +230,22 @@ test_timeval_to_iso8601 (void)
     }
 }
 
+/* Test error handling for g_time_val_to_iso8601() on dates which are too large. */
+static void
+test_timeval_to_iso8601_overflow (void)
+{
+  GTimeVal val;
+  gchar *out = NULL;
+
+  g_unsetenv ("TZ");
+
+  val.tv_sec = G_MAXLONG;
+  val.tv_usec = G_USEC_PER_SEC - 1;
+
+  out = g_time_val_to_iso8601 (&val);
+  g_assert_null (out);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -242,6 +258,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/timeval/add", test_timeval_add);
   g_test_add_func ("/timeval/from-iso8601", test_timeval_from_iso8601);
   g_test_add_func ("/timeval/to-iso8601", test_timeval_to_iso8601);
+  g_test_add_func ("/timeval/to-iso8601/overflow", test_timeval_to_iso8601_overflow);
 
   return g_test_run ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]