summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2018-03-16 18:34:38 +0100
committerBenjamin Berg <bberg@redhat.com>2018-04-30 12:08:01 +0200
commit5447b92136f13ed107bfa9f105e6a23110549ebb (patch)
tree97c390d5f7bf3dd76fa51b4b5ada53effa8d67e6
parent635afc8b6959ea7c157f5ecc03418e392d06c49c (diff)
downloadgnome-settings-daemon-benzea/color-transition-fix.tar.gz
color: Add test to check that smooth transitions are cancelledbenzea/color-transition-fix
-rw-r--r--plugins/color/gcm-self-test.c39
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);