Improve GTimeZone test coverage

This commit is contained in:
Matthias Clasen 2012-06-11 10:23:42 -04:00
parent d4f8854785
commit f47de7ec2c

View File

@ -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 ();
}