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.
This commit is contained in:
Benjamin Otte 2017-01-08 01:42:03 +01:00
parent 507a1e4d7a
commit daf0270f1a
3 changed files with 0 additions and 194 deletions

View File

@ -6010,9 +6010,6 @@ gtk_page_setup_unix_dialog_get_type
<SECTION>
<FILE>gtktesting</FILE>
<TITLE>Testing</TITLE>
gtk_test_find_label
gtk_test_find_sibling
gtk_test_find_widget
gtk_test_init
gtk_test_list_all_types
gtk_test_register_all_types

View File

@ -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;

View File

@ -37,10 +37,6 @@ GDK_AVAILABLE_IN_ALL
void gtk_test_register_all_types (void);
GDK_AVAILABLE_IN_ALL
const GType* gtk_test_list_all_types (guint *n_types);
GDK_AVAILABLE_IN_ALL
GtkWidget* gtk_test_find_widget (GtkWidget *widget,
const gchar *label_pattern,
GType widget_type);
GDK_AVAILABLE_IN_3_10
void gtk_test_widget_wait_for_draw (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
@ -48,13 +44,6 @@ gboolean gtk_test_widget_send_key (GtkWidget *widget,
guint keyval,
GdkModifierType modifiers);
/* --- Gtk+ Test low-level API --- */
GDK_AVAILABLE_IN_ALL
GtkWidget* gtk_test_find_sibling (GtkWidget *base_widget,
GType widget_type);
GDK_AVAILABLE_IN_ALL
GtkWidget* gtk_test_find_label (GtkWidget *widget,
const gchar *label_pattern);
G_END_DECLS
#endif /* __GTK_TEST_UTILS_H__ */