diff options
author | Benjamin Berg <bberg@redhat.com> | 2018-03-16 18:34:38 +0100 |
---|---|---|
committer | Benjamin Berg <bberg@redhat.com> | 2018-05-30 16:22:48 +0200 |
commit | 61d36ccc196853efa2ce3cce75d9e0f81ee790f3 (patch) | |
tree | 2439cfa453cac4e9768d41fc48fb8ce8a7330ce8 /plugins/color/gcm-self-test.c | |
parent | 74bf091f2410ae5484bd6d3f114bf2ceff396a64 (diff) | |
download | gnome-settings-daemon-61d36ccc196853efa2ce3cce75d9e0f81ee790f3.tar.gz |
color: Add test to check that smooth transitions are cancelled
Diffstat (limited to 'plugins/color/gcm-self-test.c')
-rw-r--r-- | plugins/color/gcm-self-test.c | 39 |
1 files changed, 38 insertions, 1 deletions
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 <glib.h> #include <glib-object.h> #include <stdlib.h> @@ -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); |