[libdazzle] tests: add test for event propagation with theme inheritance
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] tests: add test for event propagation with theme inheritance
- Date: Tue, 13 Jun 2017 06:48:55 +0000 (UTC)
commit 04082124388c5a4ae4c54564533f3328fc428c09
Author: Christian Hergert <chergert redhat com>
Date: Mon Jun 12 23:46:51 2017 -0700
tests: add test for event propagation with theme inheritance
tests/test-shortcut-theme.c | 58 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/tests/test-shortcut-theme.c b/tests/test-shortcut-theme.c
index 63f8340..8eef504 100644
--- a/tests/test-shortcut-theme.c
+++ b/tests/test-shortcut-theme.c
@@ -35,6 +35,63 @@ test_shortcut_theme_basic (void)
g_assert (context == NULL);
}
+static void
+key_callback (GtkWidget *widget,
+ gpointer data)
+{
+ gboolean *did_cb = data;
+ *did_cb = TRUE;
+ g_assert (GTK_IS_LABEL (widget));
+}
+
+static void
+test_shortcut_theme_manager (void)
+{
+ DzlShortcutController *controller;
+ DzlShortcutManager *manager;
+ DzlShortcutTheme *theme;
+ GtkWidget *window;
+ GtkWidget *label;
+ GdkEventKey *event;
+ GError *error = NULL;
+ gboolean did_cb = FALSE;
+ gboolean r;
+
+ manager = dzl_shortcut_manager_get_default ();
+ g_assert (DZL_IS_SHORTCUT_MANAGER (manager));
+
+ theme = dzl_shortcut_manager_get_theme_by_name (manager, NULL);
+ g_assert (DZL_IS_SHORTCUT_THEME (theme));
+ g_assert (theme == dzl_shortcut_manager_get_theme_by_name (manager, "__internal__"));
+ g_assert_cmpstr (dzl_shortcut_theme_get_parent_name (theme), ==, NULL);
+
+ theme = dzl_shortcut_manager_get_theme_by_name (manager, "default");
+ g_assert (theme == NULL);
+
+ g_assert (G_IS_INITABLE (manager));
+ r = g_initable_init (G_INITABLE (manager), NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (r, ==, TRUE);
+
+ theme = dzl_shortcut_manager_get_theme_by_name (manager, "default");
+ g_assert (DZL_IS_SHORTCUT_THEME (theme));
+ g_assert_cmpstr ("__internal__", ==, dzl_shortcut_theme_get_parent_name (theme));
+
+ /* Add a command and make sure we can resolve it */
+ window = gtk_offscreen_window_new ();
+ label = gtk_label_new (NULL);
+ gtk_container_add (GTK_CONTAINER (window), label);
+ gtk_widget_show_all (window);
+ controller = dzl_shortcut_controller_find (label);
+ g_assert (DZL_IS_SHORTCUT_CONTROLLER (controller));
+ dzl_shortcut_controller_add_command_callback (controller, "useless.command.here", "<Control>a",
key_callback, &did_cb, NULL);
+ event = dzl_gdk_synthesize_event_keyval (gtk_widget_get_window (label), GDK_KEY_a);
+ event->state |= GDK_CONTROL_MASK;
+ r = dzl_shortcut_controller_handle_event (controller, event);
+ g_assert_cmpint (did_cb, ==, TRUE);
+ g_assert_cmpint (r, ==, GDK_EVENT_STOP);
+}
+
gint
main (gint argc,
gchar *argv[])
@@ -42,5 +99,6 @@ main (gint argc,
gtk_init (&argc, &argv);
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/Dazzle/ShortcutTheme/basic", test_shortcut_theme_basic);
+ g_test_add_func ("/Dazzle/ShortcutTheme/manager", test_shortcut_theme_manager);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]