From 5447b92136f13ed107bfa9f105e6a23110549ebb Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Fri, 16 Mar 2018 18:34:38 +0100 Subject: color: Add test to check that smooth transitions are cancelled --- plugins/color/gcm-self-test.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/plugins/color/gcm-self-test.c b/plugins/color/gcm-self-test.c index 7f879208..f2971e87 100644 --- a/plugins/color/gcm-self-test.c +++ b/plugins/color/gcm-self-test.c @@ -21,6 +21,7 @@ #include "config.h" +#include #include #include @@ -29,6 +30,8 @@ #include "gsd-night-light.h" #include "gsd-night-light-common.h" +GMainLoop *mainloop; + static void on_notify (GsdNightLight *nlight, GParamSpec *pspec, @@ -38,6 +41,14 @@ on_notify (GsdNightLight *nlight, (*cnt)++; } +static gboolean +quit_mainloop (gpointer user_data) +{ + g_main_loop_quit (mainloop); + + return FALSE; +} + static void gcm_test_night_light (void) { @@ -78,6 +89,7 @@ gcm_test_night_light (void) /* switch off */ settings = g_settings_new ("org.gnome.settings-daemon.plugins.color"); g_settings_set_boolean (settings, "night-light-enabled", FALSE); + g_settings_set_uint (settings, "night-light-temperature", 4000); /* check default values */ g_assert (!gsd_night_light_get_active (nlight)); @@ -146,7 +158,7 @@ gcm_test_night_light (void) g_assert_cmpint (gsd_night_light_get_temperature (nlight), ==, GSD_COLOR_TEMPERATURE_DEFAULT); g_assert (!gsd_night_light_get_disabled_until_tmw (nlight)); - /* finally disable, with no changes */ + /* disable, with no changes */ g_settings_set_boolean (settings, "night-light-enabled", FALSE); g_assert (!gsd_night_light_get_active (nlight)); g_assert_cmpint (active_cnt, ==, 2); @@ -154,6 +166,29 @@ gcm_test_night_light (void) g_assert_cmpint (sunrise_cnt, ==, 1); g_assert_cmpint (temperature_cnt, ==, 4); g_assert_cmpint (disabled_until_tmw_cnt, ==, 2); + + + /* Finally, check that cancelling a smooth transition works */ + gsd_night_light_set_smooth_enabled (nlight, TRUE); + /* Enable night light and automatic scheduling */ + g_settings_set_boolean (settings, "night-light-schedule-automatic", TRUE); + g_settings_set_boolean (settings, "night-light-enabled", TRUE); + /* It should be active again, and a smooth transition is being done, + * so the color temperature is still the default at this point. */ + g_assert (gsd_night_light_get_active (nlight)); + g_assert_cmpint (gsd_night_light_get_temperature (nlight), ==, GSD_COLOR_TEMPERATURE_DEFAULT); + + /* Turn off immediately, before the first timeout event is fired. */ + g_settings_set_boolean (settings, "night-light-schedule-automatic", FALSE); + g_settings_set_boolean (settings, "night-light-enabled", FALSE); + g_assert (!gsd_night_light_get_active (nlight)); + + /* Now, sleep for a bit (the smooth transition time is 5 seconds) */ + g_timeout_add (5000, quit_mainloop, NULL); + g_main_loop_run (mainloop); + + /* Ensure that the color temperature is still the default one.*/ + g_assert_cmpint (gsd_night_light_get_temperature (nlight), ==, GSD_COLOR_TEMPERATURE_DEFAULT); } static void @@ -284,6 +319,8 @@ main (int argc, char **argv) g_test_init (&argc, &argv, NULL); + mainloop = g_main_loop_new (g_main_context_default (), FALSE); + 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); -- cgit v1.2.1