diff options
author | Benjamin Otte <otte@redhat.com> | 2017-01-08 01:42:03 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2017-01-08 03:36:05 +0100 |
commit | daf0270f1a5e8bca7b7c9cce66e2a10c17a17cb4 (patch) | |
tree | 86a1ced0211a392a3fc8170ac0e02192c01d11db /gtk/gtktestutils.c | |
parent | 507a1e4d7a21387f2b245e93d3e2cc395a41fbd4 (diff) | |
download | gtk+-daf0270f1a5e8bca7b7c9cce66e2a10c17a17cb4.tar.gz |
tests: Remove widget find functions
They are all unused by GTK.
And other people can write their own find functions if they need any in
their tests.
Diffstat (limited to 'gtk/gtktestutils.c')
-rw-r--r-- | gtk/gtktestutils.c | 180 |
1 files changed, 0 insertions, 180 deletions
diff --git a/gtk/gtktestutils.c b/gtk/gtktestutils.c index d8b0856106..45ff98774e 100644 --- a/gtk/gtktestutils.c +++ b/gtk/gtktestutils.c @@ -200,186 +200,6 @@ gtk_test_widget_send_key (GtkWidget *widget, return k1res && k2res; } -/** - * gtk_test_find_label: - * @widget: Valid label or container widget. - * @label_pattern: Shell-glob pattern to match a label string. - * - * This function will search @widget and all its descendants for a GtkLabel - * widget with a text string matching @label_pattern. - * The @label_pattern may contain asterisks “*” and question marks “?” as - * placeholders, g_pattern_match() is used for the matching. - * Note that locales other than "C“ tend to alter (translate” label strings, - * so this function is genrally only useful in test programs with - * predetermined locales, see gtk_test_init() for more details. - * - * Returns: (transfer none): a GtkLabel widget if any is found. - * - * Since: 2.14 - **/ -GtkWidget* -gtk_test_find_label (GtkWidget *widget, - const gchar *label_pattern) -{ - GtkWidget *label = NULL; - - if (GTK_IS_LABEL (widget)) - { - const gchar *text = gtk_label_get_text (GTK_LABEL (widget)); - if (g_pattern_match_simple (label_pattern, text)) - return widget; - } - - if (GTK_IS_CONTAINER (widget)) - { - GList *node, *list; - - list = gtk_container_get_children (GTK_CONTAINER (widget)); - for (node = list; node; node = node->next) - { - label = gtk_test_find_label (node->data, label_pattern); - if (label) - break; - } - g_list_free (list); - } - return label; -} - -static GList* -test_list_descendants (GtkWidget *widget, - GType widget_type) -{ - GList *results = NULL; - if (GTK_IS_CONTAINER (widget)) - { - GList *node, *list = gtk_container_get_children (GTK_CONTAINER (widget)); - for (node = list; node; node = node->next) - { - if (!widget_type || g_type_is_a (G_OBJECT_TYPE (node->data), widget_type)) - results = g_list_prepend (results, node->data); - else - results = g_list_concat (results, test_list_descendants (node->data, widget_type)); - } - g_list_free (list); - } - return results; -} - -static int -widget_geo_dist (GtkWidget *a, - GtkWidget *b, - GtkWidget *base) -{ - GtkAllocation allocation; - int ax0, ay0, ax1, ay1, bx0, by0, bx1, by1, xdist = 0, ydist = 0; - - gtk_widget_get_allocation (a, &allocation); - if (!gtk_widget_translate_coordinates (a, base, 0, 0, &ax0, &ay0) || - !gtk_widget_translate_coordinates (a, base, allocation.width, allocation.height, &ax1, &ay1)) - return -G_MAXINT; - - gtk_widget_get_allocation (b, &allocation); - if (!gtk_widget_translate_coordinates (b, base, 0, 0, &bx0, &by0) || - !gtk_widget_translate_coordinates (b, base, allocation.width, allocation.height, &bx1, &by1)) - return +G_MAXINT; - - if (bx0 >= ax1) - xdist = bx0 - ax1; - else if (ax0 >= bx1) - xdist = ax0 - bx1; - if (by0 >= ay1) - ydist = by0 - ay1; - else if (ay0 >= by1) - ydist = ay0 - by1; - - return xdist + ydist; -} - -static int -widget_geo_cmp (gconstpointer a, - gconstpointer b, - gpointer user_data) -{ - gpointer *data = user_data; - GtkWidget *wa = (void*) a, *wb = (void*) b, *toplevel = data[0], *base_widget = data[1]; - int adist = widget_geo_dist (wa, base_widget, toplevel); - int bdist = widget_geo_dist (wb, base_widget, toplevel); - return adist > bdist ? +1 : adist == bdist ? 0 : -1; -} - -/** - * gtk_test_find_sibling: - * @base_widget: Valid widget, part of a widget hierarchy - * @widget_type: Type of a aearched for sibling widget - * - * This function will search siblings of @base_widget and siblings of its - * ancestors for all widgets matching @widget_type. - * Of the matching widgets, the one that is geometrically closest to - * @base_widget will be returned. - * The general purpose of this function is to find the most likely “action” - * widget, relative to another labeling widget. Such as finding a - * button or text entry widget, given its corresponding label widget. - * - * Returns: (transfer none): a widget of type @widget_type if any is found. - * - * Since: 2.14 - **/ -GtkWidget* -gtk_test_find_sibling (GtkWidget *base_widget, - GType widget_type) -{ - GList *siblings = NULL; - GtkWidget *tmpwidget = base_widget; - gpointer data[2]; - /* find all sibling candidates */ - while (tmpwidget) - { - tmpwidget = gtk_widget_get_parent (tmpwidget); - siblings = g_list_concat (siblings, test_list_descendants (tmpwidget, widget_type)); - } - /* sort them by distance to base_widget */ - data[0] = gtk_widget_get_toplevel (base_widget); - data[1] = base_widget; - siblings = g_list_sort_with_data (siblings, widget_geo_cmp, data); - /* pick nearest != base_widget */ - siblings = g_list_remove (siblings, base_widget); - tmpwidget = siblings ? siblings->data : NULL; - g_list_free (siblings); - return tmpwidget; -} - -/** - * gtk_test_find_widget: - * @widget: Container widget, usually a GtkWindow. - * @label_pattern: Shell-glob pattern to match a label string. - * @widget_type: Type of a aearched for label sibling widget. - * - * This function will search the descendants of @widget for a widget - * of type @widget_type that has a label matching @label_pattern next - * to it. This is most useful for automated GUI testing, e.g. to find - * the “OK” button in a dialog and synthesize clicks on it. - * However see gtk_test_find_label(), gtk_test_find_sibling() and - * gtk_test_widget_click() for possible caveats involving the search of - * such widgets and synthesizing widget events. - * - * Returns: (nullable) (transfer none): a valid widget if any is found or %NULL. - * - * Since: 2.14 - **/ -GtkWidget* -gtk_test_find_widget (GtkWidget *widget, - const gchar *label_pattern, - GType widget_type) -{ - GtkWidget *label = gtk_test_find_label (widget, label_pattern); - if (!label) - label = gtk_test_find_label (gtk_widget_get_toplevel (widget), label_pattern); - if (label) - return gtk_test_find_sibling (label, widget_type); - return NULL; -} - static GType *all_registered_types = NULL; static guint n_all_registered_types = 0; |