diff options
-rw-r--r-- | docs/reference/gtk/gtk4-sections.txt | 9 | ||||
-rw-r--r-- | gtk/gtktestutils.c | 343 | ||||
-rw-r--r-- | gtk/gtktestutils.h | 30 |
3 files changed, 0 insertions, 382 deletions
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 5568c41b56..341c46bef1 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -6339,21 +6339,12 @@ gtk_page_setup_unix_dialog_get_type <SECTION> <FILE>gtktesting</FILE> <TITLE>Testing</TITLE> -gtk_test_create_simple_window -gtk_test_create_widget -gtk_test_display_button_window 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 -gtk_test_slider_get_value -gtk_test_slider_set_perc -gtk_test_spin_button_click -gtk_test_text_get -gtk_test_text_set -gtk_test_widget_click gtk_test_widget_send_key gtk_test_widget_wait_for_draw </SECTION> diff --git a/gtk/gtktestutils.c b/gtk/gtktestutils.c index d0fe541ff3..d8b0856106 100644 --- a/gtk/gtktestutils.c +++ b/gtk/gtktestutils.c @@ -201,82 +201,6 @@ gtk_test_widget_send_key (GtkWidget *widget, } /** - * gtk_test_widget_click: - * @widget: Widget to generate a button click on. - * @button: Number of the pointer button for the event, usually 1, 2 or 3. - * @modifiers: Keyboard modifiers the event is setup with. - * - * This function will generate a @button click (button press and button - * release event) in the middle of the first GdkWindow found that belongs - * to @widget. - * For windowless widgets like #GtkButton (which returns %FALSE from - * gtk_widget_get_has_window()), this will often be an - * input-only event window. For other widgets, this is usually widget->window. - * Certain caveats should be considered when using this function, in - * particular because the mouse pointer is warped to the button click - * location, see gdk_test_simulate_button() for details. - * - * Returns: whether all actions neccessary for the button click simulation were carried out successfully. - * - * Since: 2.14 - * - * Deprecated: 3.20: This testing infrastructure is phased out in favor of reftests. - **/ -gboolean -gtk_test_widget_click (GtkWidget *widget, - guint button, - GdkModifierType modifiers) -{ - gboolean b1res, b2res; - GSList *iwindows = test_find_widget_input_windows (widget, FALSE); - if (!iwindows) - iwindows = test_find_widget_input_windows (widget, TRUE); - if (!iwindows) - return FALSE; - b1res = gdk_test_simulate_button (iwindows->data, -1, -1, button, modifiers, GDK_BUTTON_PRESS); - b2res = gdk_test_simulate_button (iwindows->data, -1, -1, button, modifiers, GDK_BUTTON_RELEASE); - g_slist_free (iwindows); - return b1res && b2res; -} - -/** - * gtk_test_spin_button_click: - * @spinner: valid GtkSpinButton widget. - * @button: Number of the pointer button for the event, usually 1, 2 or 3. - * @upwards: %TRUE for upwards arrow click, %FALSE for downwards arrow click. - * - * This function will generate a @button click in the upwards or downwards - * spin button arrow areas, usually leading to an increase or decrease of - * spin button’s value. - * - * Returns: whether all actions neccessary for the button click simulation were carried out successfully. - * - * Since: 2.14 - * - * Deprecated: 3.20: This testing infrastructure is phased out in favor of reftests. - **/ -gboolean -gtk_test_spin_button_click (GtkSpinButton *spinner, - guint button, - gboolean upwards) -{ - GdkWindow *down_panel = NULL, *up_panel = NULL, *panel; - gboolean b1res = FALSE, b2res = FALSE; - - _gtk_spin_button_get_panels (spinner, &down_panel, &up_panel); - - panel = (upwards) ? up_panel : down_panel; - - if (panel) - { - gint width = gdk_window_get_width (panel); - b1res = gdk_test_simulate_button (panel, width - 1, 1, button, 0, GDK_BUTTON_PRESS); - b2res = gdk_test_simulate_button (panel, width - 1, 1, button, 0, GDK_BUTTON_RELEASE); - } - return b1res && b2res; -} - -/** * gtk_test_find_label: * @widget: Valid label or container widget. * @label_pattern: Shell-glob pattern to match a label string. @@ -456,273 +380,6 @@ gtk_test_find_widget (GtkWidget *widget, return NULL; } -/** - * gtk_test_slider_set_perc: - * @widget: valid widget pointer. - * @percentage: value between 0 and 100. - * - * 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 these widgets is set to - * a value between the lower and upper limits, according to the - * @percentage argument. - * - * Since: 2.14 - * - * Deprecated: 3.20: This testing infrastructure is phased out in favor of reftests. - **/ -void -gtk_test_slider_set_perc (GtkWidget *widget, - double percentage) -{ - GtkAdjustment *adjustment = NULL; - if (GTK_IS_RANGE (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)); - if (adjustment) - 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); -} - -/** - * gtk_test_slider_get_value: - * @widget: valid widget pointer. - * - * Retrive the literal adjustment value for GtkRange based - * widgets and spin buttons. Note that the value returned by - * this function is anything between the lower and upper bounds - * of the adjustment belonging to @widget, and is not a percentage - * as passed in to gtk_test_slider_set_perc(). - * - * Returns: gtk_adjustment_get_value (adjustment) for an adjustment belonging to @widget. - * - * Since: 2.14 - * - * Deprecated: 3.20: This testing infrastructure is phased out in favor of reftests. - **/ -double -gtk_test_slider_get_value (GtkWidget *widget) -{ - GtkAdjustment *adjustment = NULL; - if (GTK_IS_RANGE (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 ? gtk_adjustment_get_value (adjustment) : 0; -} - -/** - * gtk_test_text_set: - * @widget: valid widget pointer. - * @string: a 0-terminated C string - * - * Set the text string of @widget to @string if it is a GtkLabel, - * GtkEditable (entry and text widgets) or GtkTextView. - * - * Since: 2.14 - * - * Deprecated: 3.20: This testing infrastructure is phased out in favor of reftests. - **/ -void -gtk_test_text_set (GtkWidget *widget, - const gchar *string) -{ - if (GTK_IS_LABEL (widget)) - gtk_label_set_text (GTK_LABEL (widget), string); - else if (GTK_IS_EDITABLE (widget)) - { - int pos = 0; - gtk_editable_delete_text (GTK_EDITABLE (widget), 0, -1); - gtk_editable_insert_text (GTK_EDITABLE (widget), string, -1, &pos); - } - else if (GTK_IS_TEXT_VIEW (widget)) - { - GtkTextBuffer *tbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)); - gtk_text_buffer_set_text (tbuffer, string, -1); - } -} - -/** - * gtk_test_text_get: - * @widget: valid widget pointer. - * - * 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 released with g_free(). - * - * Since: 2.14 - * - * Deprecated: 3.20: This testing infrastructure is phased out in favor of reftests. - **/ -gchar* -gtk_test_text_get (GtkWidget *widget) -{ - if (GTK_IS_LABEL (widget)) - return g_strdup (gtk_label_get_text (GTK_LABEL (widget))); - else if (GTK_IS_EDITABLE (widget)) - { - return g_strdup (gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1)); - } - else if (GTK_IS_TEXT_VIEW (widget)) - { - GtkTextBuffer *tbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)); - GtkTextIter start, end; - gtk_text_buffer_get_start_iter (tbuffer, &start); - gtk_text_buffer_get_end_iter (tbuffer, &end); - return gtk_text_buffer_get_text (tbuffer, &start, &end, FALSE); - } - return NULL; -} - -/** - * gtk_test_create_widget: - * @widget_type: a valid widget type. - * @first_property_name: (allow-none): Name of first property to set or %NULL - * @...: 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 - * g_object_ref_sink() them (to keep them alive across a running test) - * and set them up for destruction during the next test teardown phase. - * - * Returns: (transfer none): a newly created widget. - * - * Since: 2.14 - * - * Deprecated: 3.20: This testing infrastructure is phased out in favor of reftests. - */ -GtkWidget* -gtk_test_create_widget (GType widget_type, - const gchar *first_property_name, - ...) -{ - GtkWidget *widget; - va_list var_args; - g_return_val_if_fail (g_type_is_a (widget_type, GTK_TYPE_WIDGET), NULL); - va_start (var_args, first_property_name); - widget = (GtkWidget*) g_object_new_valist (widget_type, first_property_name, var_args); - va_end (var_args); - if (widget) - { - if (!GTK_IS_WINDOW (widget)) - gtk_widget_show (widget); - g_object_ref_sink (widget); - g_test_queue_unref (widget); - g_test_queue_destroy ((GDestroyNotify) gtk_widget_destroy, widget); - } - return widget; -} - -static void -try_main_quit (void) -{ - if (gtk_main_level()) - gtk_main_quit(); -} - -static int -test_increment_intp (int *intp) -{ - if (intp != NULL) - *intp += 1; - return 1; /* TRUE in case we're connected to event signals */ -} - -/** - * gtk_test_display_button_window: - * @window_title: Title of the window to be displayed. - * @dialog_text: Text inside the window to be displayed. - * @...: %NULL terminated list of (const char *label, int *nump) pairs. - * - * Create a window with window title @window_title, text contents @dialog_text, - * and a number of buttons, according to the paired argument list given - * as @... parameters. - * Each button is created with a @label and a ::clicked signal handler that - * incremrents the integer stored in @nump. - * The window will be automatically shown with gtk_widget_show_now() after - * creation, so when this function returns it has already been mapped, - * resized and positioned on screen. - * The window will quit any running gtk_main()-loop when destroyed, and it - * will automatically be destroyed upon test function teardown. - * - * Returns: (transfer full): a widget pointer to the newly created GtkWindow. - * - * Since: 2.14 - * - * Deprecated: 3.20: This testing infrastructure is phased out in favor of reftests. - **/ -GtkWidget* -gtk_test_display_button_window (const gchar *window_title, - const gchar *dialog_text, - ...) /* NULL terminated list of (label, &int) pairs */ -{ - va_list var_args; - GtkWidget *window, *vbox; - const char *arg1; -G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - window = gtk_test_create_widget (GTK_TYPE_WINDOW, "title", window_title, NULL); - vbox = gtk_test_create_widget (GTK_TYPE_BOX, "parent", window, "orientation", GTK_ORIENTATION_VERTICAL, NULL); - gtk_test_create_widget (GTK_TYPE_LABEL, "label", dialog_text, "parent", vbox, NULL); -G_GNUC_END_IGNORE_DEPRECATIONS; - g_signal_connect (window, "destroy", G_CALLBACK (try_main_quit), NULL); - va_start (var_args, dialog_text); - arg1 = va_arg (var_args, const char*); - while (arg1) - { - int *arg2 = va_arg (var_args, int*); - GtkWidget *button; -G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - button = gtk_test_create_widget (GTK_TYPE_BUTTON, "label", arg1, "parent", vbox, NULL); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - g_signal_connect_swapped (button, "clicked", G_CALLBACK (test_increment_intp), arg2); - arg1 = va_arg (var_args, const char*); - } - va_end (var_args); - gtk_widget_show_all (vbox); - gtk_widget_show_now (window); - while (gtk_events_pending ()) - gtk_main_iteration (); - return window; -} - -/** - * gtk_test_create_simple_window: - * @window_title: Title of the window to be displayed. - * @dialog_text: Text inside the window to be displayed. - * - * Create a simple window with window title @window_title and - * text contents @dialog_text. - * The window will quit any running gtk_main()-loop when destroyed, and it - * will automatically be destroyed upon test function teardown. - * - * Returns: (transfer none): a widget pointer to the newly created GtkWindow. - * - * Since: 2.14 - * - * Deprecated: 3.20: This testing infrastructure is phased out in favor of reftests. - **/ -GtkWidget* -gtk_test_create_simple_window (const gchar *window_title, - const gchar *dialog_text) -{ - GtkWidget *window, *vbox; -G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - window = gtk_test_create_widget (GTK_TYPE_WINDOW, "title", window_title, NULL); - vbox = gtk_test_create_widget (GTK_TYPE_BOX, "parent", window, "orientation", GTK_ORIENTATION_VERTICAL, NULL); - gtk_test_create_widget (GTK_TYPE_LABEL, "label", dialog_text, "parent", vbox, NULL); -G_GNUC_END_IGNORE_DEPRECATIONS; - g_signal_connect (window, "destroy", G_CALLBACK (try_main_quit), NULL); - gtk_widget_show_all (vbox); - return window; -} - static GType *all_registered_types = NULL; static guint n_all_registered_types = 0; diff --git a/gtk/gtktestutils.h b/gtk/gtktestutils.h index bdf2515fcc..a7482f272b 100644 --- a/gtk/gtktestutils.h +++ b/gtk/gtktestutils.h @@ -41,42 +41,12 @@ GDK_AVAILABLE_IN_ALL GtkWidget* gtk_test_find_widget (GtkWidget *widget, const gchar *label_pattern, GType widget_type); -GDK_DEPRECATED_IN_3_20 -GtkWidget* gtk_test_create_widget (GType widget_type, - const gchar *first_property_name, - ...); -GDK_DEPRECATED_IN_3_20 -GtkWidget* gtk_test_create_simple_window (const gchar *window_title, - const gchar *dialog_text); -GDK_DEPRECATED_IN_3_20 -GtkWidget* gtk_test_display_button_window (const gchar *window_title, - const gchar *dialog_text, - ...); /* NULL terminated list of (label, &int) pairs */ -GDK_DEPRECATED_IN_3_20 -void gtk_test_slider_set_perc (GtkWidget *widget, /* GtkRange-alike */ - double percentage); -GDK_DEPRECATED_IN_3_20 -double gtk_test_slider_get_value (GtkWidget *widget); -GDK_DEPRECATED_IN_3_20 -gboolean gtk_test_spin_button_click (GtkSpinButton *spinner, - guint button, - gboolean upwards); GDK_AVAILABLE_IN_3_10 void gtk_test_widget_wait_for_draw (GtkWidget *widget); -GDK_DEPRECATED_IN_3_20 -gboolean gtk_test_widget_click (GtkWidget *widget, - guint button, - GdkModifierType modifiers); GDK_AVAILABLE_IN_ALL gboolean gtk_test_widget_send_key (GtkWidget *widget, guint keyval, GdkModifierType modifiers); -/* operate on GtkEntry, GtkText, GtkTextView or GtkLabel */ -GDK_DEPRECATED_IN_3_20 -void gtk_test_text_set (GtkWidget *widget, - const gchar *string); -GDK_DEPRECATED_IN_3_20 -gchar* gtk_test_text_get (GtkWidget *widget); /* --- Gtk+ Test low-level API --- */ GDK_AVAILABLE_IN_ALL |