From 5c339f2844dfc7adcd54fc5ff2cbe5ab553daf8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Wed, 16 May 2018 17:56:34 +0200 Subject: [PATCH] Add basic searchbar set_key_capture_widget tests Make sure we're correctly resetting the internal key capture widget pointer when the widget goes away. --- testsuite/gtk/meson.build | 1 + testsuite/gtk/searchbar.c | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 testsuite/gtk/searchbar.c diff --git a/testsuite/gtk/meson.build b/testsuite/gtk/meson.build index e8adb56336..116a945ebd 100644 --- a/testsuite/gtk/meson.build +++ b/testsuite/gtk/meson.build @@ -36,6 +36,7 @@ tests = [ ['recentmanager'], ['regression-tests'], ['scrolledwindow'], + ['searchbar'], ['spinbutton'], ['stylecontext'], ['templates'], diff --git a/testsuite/gtk/searchbar.c b/testsuite/gtk/searchbar.c new file mode 100644 index 0000000000..0e1427f2a7 --- /dev/null +++ b/testsuite/gtk/searchbar.c @@ -0,0 +1,54 @@ +#include + +static void +capture_widget_destroy (void) +{ + GtkWidget *searchbar = gtk_search_bar_new (); + GtkWidget *button = gtk_button_new (); + + g_object_ref_sink (searchbar); + g_object_ref_sink (button); + + gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (searchbar), button); + + g_assert (gtk_search_bar_get_key_capture_widget (GTK_SEARCH_BAR (searchbar)) == button); + + g_object_unref (button); + + g_assert (gtk_search_bar_get_key_capture_widget (GTK_SEARCH_BAR (searchbar)) == NULL); + + g_object_unref (searchbar); +} + +static void +capture_widget_unset (void) +{ + GtkWidget *searchbar = gtk_search_bar_new (); + GtkWidget *button = gtk_button_new (); + + g_object_ref_sink (searchbar); + g_object_ref_sink (button); + + gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (searchbar), button); + + g_assert (gtk_search_bar_get_key_capture_widget (GTK_SEARCH_BAR (searchbar)) == button); + + gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (searchbar), NULL); + + g_assert (gtk_search_bar_get_key_capture_widget (GTK_SEARCH_BAR (searchbar)) == NULL); + + g_object_unref (searchbar); + g_object_unref (button); +} + +int +main (int argc, + char *argv[]) +{ + gtk_test_init (&argc, &argv); + + g_test_add_func ("/searchbar/capture-widget-destroy", capture_widget_destroy); + g_test_add_func ("/searchbar/capture-widget-unset", capture_widget_unset); + + return g_test_run(); +}