[glib] Improve GTimeZone test coverage



commit f47de7ec2c9f79edbb3e03f3112aa8cd1d286309
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jun 11 10:23:42 2012 -0400

    Improve GTimeZone test coverage

 glib/tests/gdatetime.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index 0dea323..b424254 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -1222,6 +1222,70 @@ test_strftime (void)
     }
 }
 
+static void
+test_find_interval (void)
+{
+  GTimeZone *tz;
+  GDateTime *dt;
+  gint64 u;
+  gint i1, i2;
+
+  tz = g_time_zone_new ("Canada/Eastern");
+  dt = g_date_time_new_utc (2010, 11, 7, 1, 30, 0);
+  u = g_date_time_to_unix (dt);
+
+  i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_STANDARD, u);
+  i2 = g_time_zone_find_interval (tz, G_TIME_TYPE_DAYLIGHT, u);
+
+  g_assert_cmpint (i1, !=, i2);
+
+  g_date_time_unref (dt);
+
+  dt = g_date_time_new_utc (2010, 3, 14, 2, 0, 0);
+  u = g_date_time_to_unix (dt);
+
+  i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_STANDARD, u);
+  g_assert_cmpint (i1, ==, -1);
+
+  g_date_time_unref (dt);
+  g_time_zone_unref (tz);
+}
+
+static void
+test_adjust_time (void)
+{
+  GTimeZone *tz;
+  GDateTime *dt;
+  gint64 u, u2;
+  gint i1, i2;
+
+  tz = g_time_zone_new ("Canada/Eastern");
+  dt = g_date_time_new_utc (2010, 11, 7, 1, 30, 0);
+  u = g_date_time_to_unix (dt);
+  u2 = u;
+
+  i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_DAYLIGHT, u);
+  i2 = g_time_zone_adjust_time (tz, G_TIME_TYPE_DAYLIGHT, &u2);
+
+  g_assert_cmpint (i1, ==, i2);
+  g_assert (u == u2);
+
+  g_date_time_unref (dt);
+
+  dt = g_date_time_new_utc (2010, 3, 14, 2, 30, 0);
+  u2 = g_date_time_to_unix (dt);
+  g_date_time_unref (dt);
+
+  dt = g_date_time_new_utc (2010, 3, 14, 3, 0, 0);
+  u = g_date_time_to_unix (dt);
+  g_date_time_unref (dt);
+
+  i1 = g_time_zone_adjust_time (tz, G_TIME_TYPE_DAYLIGHT, &u2);
+  g_assert (u == u2);
+
+  g_time_zone_unref (tz);
+}
+
 gint
 main (gint   argc,
       gchar *argv[])
@@ -1271,6 +1335,8 @@ main (gint   argc,
   g_test_add_func ("/GDateTime/dst", test_GDateTime_dst);
   g_test_add_func ("/GDateTime/test_z", test_z);
   g_test_add_func ("/GDateTime/test-all-dates", test_all_dates);
+  g_test_add_func ("/GDateTime/find-interval", test_find_interval);
+  g_test_add_func ("/GDateTime/adjust-time", test_adjust_time);
 
   return g_test_run ();
 }



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