* Boston, MA 02111-1307, USA.
*/
-/* need to get the prototypes of all get_type functions */
-#define GTK_ENABLE_BROKEN
-#include "gtktestutils.h"
+#include "config.h"
+
#include <gtk/gtk.h>
-#include <gdk/gdktestutils.h>
-#include "gtkalias.h"
+#include "gtkspinbutton.h"
#include <locale.h>
#include <string.h>
#include <math.h>
-/* --- test utilities --- */
+/**
+ * SECTION:gtktesting
+ * @Short_description: Utilities for testing GTK+ applications
+ * @Title: Testing
+ */
+
/**
* gtk_test_init:
* @argcp: Address of the <parameter>argc</parameter> parameter of the
* @argvp: Address of the <parameter>argv</parameter> parameter of main().
* Any parameters understood by g_test_init() or gtk_init() are
* stripped before return.
+ * @Varargs: currently unused
+ *
+ * This function is used to initialize a GTK+ test program.
*
- * This function is used to initialize a Gtk+ test program.
* It will in turn call g_test_init() and gtk_init() to properly
- * initialize the testing framework and graphical toolkit.
- * It'll also set the program's locale to "C" and prevent loading of
- * rc files and Gtk+ modules. This is done to make tets program
+ * initialize the testing framework and graphical toolkit. It'll
+ * also set the program's locale to "C" and prevent loading of rc
+ * files and Gtk+ modules. This is done to make tets program
* environments as deterministic as possible.
+ *
* Like gtk_init() and g_test_init(), any known arguments will be
* processed and stripped from @argc and @argv.
+ *
+ * Since: 2.14
**/
void
gtk_test_init (int *argcp,
* - this function could install a mock object around GtkSettings
*/
g_setenv ("GTK_MODULES", "", TRUE);
- g_setenv ("GTK2_RC_FILES", "/dev/null", TRUE);
gtk_disable_setlocale();
setlocale (LC_ALL, "C");
g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=%s");
+
+ /* XSendEvent() doesn't work yet on XI2 events.
+ * So at the moment gdk_test_simulate_* can only
+ * send events that GTK+ understands if XI2 is
+ * disabled, bummer.
+ */
+ gdk_disable_multidevice ();
+
gtk_init (argcp, argvp);
}
test_find_widget_input_windows (GtkWidget *widget,
gboolean input_only)
{
+ GdkWindow *window;
GList *node, *children;
GSList *matches = NULL;
gpointer udata;
- gdk_window_get_user_data (widget->window, &udata);
- if (udata == widget && (!input_only || (GDK_IS_WINDOW (widget->window) && GDK_WINDOW_OBJECT (widget->window)->input_only)))
- matches = g_slist_prepend (matches, widget->window);
+
+ window = gtk_widget_get_window (widget);
+
+ gdk_window_get_user_data (window, &udata);
+ if (udata == widget && (!input_only || (GDK_IS_WINDOW (window) && gdk_window_is_input_only (GDK_WINDOW (window)))))
+ matches = g_slist_prepend (matches, window);
children = gdk_window_get_children (gtk_widget_get_parent_window (widget));
for (node = children; node; node = node->next)
{
gdk_window_get_user_data (node->data, &udata);
- if (udata == widget && (!input_only || (GDK_IS_WINDOW (node->data) && GDK_WINDOW_OBJECT (node->data)->input_only)))
+ if (udata == widget && (!input_only || (GDK_IS_WINDOW (node->data) && gdk_window_is_input_only (GDK_WINDOW (node->data)))))
matches = g_slist_prepend (matches, node->data);
}
return g_slist_reverse (matches);
* location, see gdk_test_simulate_key() for details.
*
* Returns: wether all actions neccessary for the key event simulation were carried out successfully.
+ *
+ * Since: 2.14
**/
gboolean
gtk_test_widget_send_key (GtkWidget *widget,
* location, see gdk_test_simulate_button() for details.
*
* Returns: wether all actions neccessary for the button click simulation were carried out successfully.
+ *
+ * Since: 2.14
**/
gboolean
gtk_test_widget_click (GtkWidget *widget,
* spin button's value.
*
* Returns: wether all actions neccessary for the button click simulation were carried out successfully.
+ *
+ * Since: 2.14
**/
gboolean
gtk_test_spin_button_click (GtkSpinButton *spinner,
guint button,
gboolean upwards)
{
+ GdkWindow *panel;
gboolean b1res = FALSE, b2res = FALSE;
- if (spinner->panel)
+
+ panel = _gtk_spin_button_get_panel (spinner);
+
+ if (panel)
{
- gint width, height, pos;
- gdk_drawable_get_size (spinner->panel, &width, &height);
- pos = upwards ? 0 : height - 1;
- b1res = gdk_test_simulate_button (spinner->panel, width - 1, pos, button, 0, GDK_BUTTON_PRESS);
- b2res = gdk_test_simulate_button (spinner->panel, width - 1, pos, button, 0, GDK_BUTTON_RELEASE);
+ gint width, pos;
+ width = gdk_window_get_width (panel);
+ pos = upwards ? 0 : gdk_window_get_height (panel) - 1;
+ b1res = gdk_test_simulate_button (panel, width - 1, pos, button, 0, GDK_BUTTON_PRESS);
+ b2res = gdk_test_simulate_button (panel, width - 1, pos, button, 0, GDK_BUTTON_RELEASE);
}
return b1res && b2res;
}
* predetermined locales, see gtk_test_init() for more details.
*
* Returns: a GtkLabel widget if any is found.
+ *
+ * Since: 2.14
**/
GtkWidget*
gtk_test_find_label (GtkWidget *widget,
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, a->allocation.width, a->allocation.height, &ax1, &ay1))
+ !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, b->allocation.width, b->allocation.height, &bx1, &by1))
+ !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)
ydist = by0 - ay1;
else if (ay0 >= by1)
ydist = ay0 - by1;
+
return xdist + ydist;
}
* button or text entry widget, given it's corresponding label widget.
*
* Returns: a widget of type @widget_type if any is found.
+ *
+ * Since: 2.14
**/
GtkWidget*
gtk_test_find_sibling (GtkWidget *base_widget,
/* find all sibling candidates */
while (tmpwidget)
{
- tmpwidget = tmpwidget->parent;
+ tmpwidget = gtk_widget_get_parent (tmpwidget);
siblings = g_list_concat (siblings, test_list_descendants (tmpwidget, widget_type));
}
/* sort them by distance to base_widget */
* such widgets and synthesizing widget events.
*
* Returns: a valid widget if any is found or %NULL.
+ *
+ * Since: 2.14
**/
GtkWidget*
gtk_test_find_widget (GtkWidget *widget,
* @widget: valid widget pointer.
* @percentage: value between 0 and 100.
*
- * This function will adjust theslider position of all GtkRange
+ * This function will adjust the slider position of all GtkRange
* based widgets, such as scrollbars or scales, it'll also adjust
- * spin buttons. The adjustment value of tehse widgets is set to
+ * spin buttons. The adjustment value of these widgets is set to
* a value between the lower and upper limits, according to the
* @percentage argument.
+ *
+ * Since: 2.14
**/
void
gtk_test_slider_set_perc (GtkWidget *widget,
else if (GTK_IS_SPIN_BUTTON (widget))
adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
if (adjustment)
- gtk_adjustment_set_value (adjustment, adjustment->lower + (adjustment->upper - adjustment->lower - adjustment->page_size) * percentage * 0.01);
+ gtk_adjustment_set_value (adjustment,
+ gtk_adjustment_get_lower (adjustment)
+ + (gtk_adjustment_get_upper (adjustment)
+ - gtk_adjustment_get_lower (adjustment)
+ - gtk_adjustment_get_page_size (adjustment))
+ * percentage * 0.01);
}
/**
* of the adjustment belonging to @widget, and is not a percentage
* as passed in to gtk_test_slider_set_perc().
*
- * Returns: adjustment->value for an adjustment belonging to @widget.
+ * Returns: gtk_adjustment_get_value (adjustment) for an adjustment belonging to @widget.
+ *
+ * Since: 2.14
**/
double
gtk_test_slider_get_value (GtkWidget *widget)
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget));
else if (GTK_IS_SPIN_BUTTON (widget))
adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
- return adjustment ? adjustment->value : 0;
+ return adjustment ? gtk_adjustment_get_value (adjustment) : 0;
}
/**
*
* Set the text string of @widget to @string if it is a GtkLabel,
* GtkEditable (entry and text widgets) or GtkTextView.
+ *
+ * Since: 2.14
**/
void
gtk_test_text_set (GtkWidget *widget,
* Retrive the text string of @widget if it is a GtkLabel,
* GtkEditable (entry and text widgets) or GtkTextView.
*
- * Returns: new 0-terminated C string, needs to be releaed with g_free().
+ * Returns: new 0-terminated C string, needs to be released with g_free().
+ *
+ * Since: 2.14
**/
gchar*
gtk_test_text_get (GtkWidget *widget)
/**
* gtk_test_create_widget
- * @widget_type: valid widget type.
- * @first_property_name: Name of first property to set or %NULL
+ * @widget_type: a valid widget type.
+ * @first_property_name: (allow-none): Name of first property to set or %NULL
+ * @Varargs: value to set the first property to, followed by more
+ * name-value pairs, terminated by %NULL
*
* This function wraps g_object_new() for widget types.
* It'll automatically show all created non window widgets, also
* and set them up for destruction during the next test teardown phase.
*
* Returns: a newly created widget.
+ *
+ * Since: 2.14
*/
GtkWidget*
gtk_test_create_widget (GType widget_type,
static int
test_increment_intp (int *intp)
{
- *intp += 1;
+ if (intp != NULL)
+ *intp += 1;
return 1; /* TRUE in case we're connected to event signals */
}
* will automatically be destroyed upon test function teardown.
*
* Returns: a widget pointer to the newly created GtkWindow.
+ *
+ * Since: 2.14
**/
GtkWidget*
gtk_test_display_button_window (const gchar *window_title,
* will automatically be destroyed upon test function teardown.
*
* Returns: a widget pointer to the newly created GtkWindow.
+ *
+ * Since: 2.14
**/
GtkWidget*
gtk_test_create_simple_window (const gchar *window_title,
*
* Return the type ids that have been registered after
* calling gtk_test_register_all_types().
+ *
+ * Since: 2.14
**/
const GType*
gtk_test_list_all_types (guint *n_types)
* Force registration of all core Gtk+ and Gdk object types.
* This allowes to refer to any of those object types via
* g_type_from_name() after calling this function.
+ *
+ * Since: 2.14
**/
void
gtk_test_register_all_types (void)
*tp = 0;
}
}
-
-#define __GTK_TEST_UTILS_C__
-#include "gtkaliasdef.c"