diff options
author | Philip Withnall <withnall@endlessm.com> | 2017-03-27 12:29:10 +0100 |
---|---|---|
committer | Philip Withnall <withnall@endlessm.com> | 2017-03-29 13:51:22 +0100 |
commit | e86132563c09bdc6a38cbaa6e1c01a28d52098d5 (patch) | |
tree | df0566a85fdd29dc8f78ea6f65eac072e68504b0 /plugins/color/gcm-self-test.c | |
parent | d0bc039706410ca57379a62cfa65381575d70091 (diff) | |
download | gnome-settings-daemon-e86132563c09bdc6a38cbaa6e1c01a28d52098d5.tar.gz |
color: Potentially fix sunrise calcs for fractional timezone offsets
If a timezone is offset by a non-integer number of hours, the value of
tz_offset would be truncated. Fix that by casting to double first.
Add a unit test for it.
Coverity ID: 1418246
https://bugzilla.gnome.org/show_bug.cgi?id=780587
Diffstat (limited to 'plugins/color/gcm-self-test.c')
-rw-r--r-- | plugins/color/gcm-self-test.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/plugins/color/gcm-self-test.c b/plugins/color/gcm-self-test.c index 8827ca46..83c06c52 100644 --- a/plugins/color/gcm-self-test.c +++ b/plugins/color/gcm-self-test.c @@ -232,6 +232,27 @@ gcm_test_sunset_sunrise (void) } static void +gcm_test_sunset_sunrise_fractional_timezone (void) +{ + gdouble sunrise; + gdouble sunrise_actual = 7.6 + 1.5; + gdouble sunset; + gdouble sunset_actual = 16.8 + 1.5; + g_autoptr(GTimeZone) tz = NULL; + g_autoptr(GDateTime) dt = NULL; + + tz = g_time_zone_new ("+01:30"); + dt = g_date_time_new (tz, 2007, 2, 1, 0, 0, 0); + + /* get for our made up timezone, today */ + gsd_night_light_get_sunrise_sunset (dt, 51.5, -0.1278, &sunrise, &sunset); + g_assert_cmpfloat (sunrise, <, sunrise_actual + 0.1); + g_assert_cmpfloat (sunrise, >, sunrise_actual - 0.1); + g_assert_cmpfloat (sunset, <, sunset_actual + 0.1); + g_assert_cmpfloat (sunset, >, sunset_actual - 0.1); +} + +static void gcm_test_frac_day (void) { g_autoptr(GDateTime) dt = g_date_time_new_utc (2007, 2, 1, 12, 59, 59); @@ -267,6 +288,7 @@ main (int argc, char **argv) g_test_add_func ("/color/edid", gcm_test_edid_func); g_test_add_func ("/color/sunset-sunrise", gcm_test_sunset_sunrise); + g_test_add_func ("/color/sunset-sunrise/fractional-timezone", gcm_test_sunset_sunrise_fractional_timezone); g_test_add_func ("/color/fractional-day", gcm_test_frac_day); g_test_add_func ("/color/night-light", gcm_test_night_light); |