filechooserbutton: In the tests, run through the dialog more than one time

This ensures that data maintained by the button while the dialog opens/closes remains consistent.

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
This commit is contained in:
Federico Mena Quintero 2013-02-20 18:28:59 -06:00
parent ac5cc19836
commit cefcafc508

View File

@ -382,6 +382,8 @@ test_file_chooser_button (gconstpointer data)
GtkWidget *window; GtkWidget *window;
GtkWidget *fc_button; GtkWidget *fc_button;
GtkWidget *fc_dialog; GtkWidget *fc_dialog;
int iterations;
int i;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@ -398,54 +400,66 @@ test_file_chooser_button (gconstpointer data)
gtk_widget_show_all (window); gtk_widget_show_all (window);
wait_for_idle (); wait_for_idle ();
/* If there is a dialog to be opened, we actually test going through it a
* couple of times. This ensures that any state that the button frobs for
* each appearance of the dialog will make sense.
*/
if (setup->open_dialog) if (setup->open_dialog)
iterations = 2;
else
iterations = 1;
for (i = 0; i < iterations; i++)
{ {
GList *children; if (setup->open_dialog)
{
GList *children;
/* Hack our way into the file chooser button; get its GtkButton child and click it */ /* Hack our way into the file chooser button; get its GtkButton child and click it */
children = gtk_container_get_children (GTK_CONTAINER (fc_button)); children = gtk_container_get_children (GTK_CONTAINER (fc_button));
g_assert (children && GTK_IS_BUTTON (children->data)); g_assert (children && GTK_IS_BUTTON (children->data));
gtk_button_clicked (GTK_BUTTON (children->data)); gtk_button_clicked (GTK_BUTTON (children->data));
g_list_free (children); g_list_free (children);
wait_for_idle (); wait_for_idle ();
/* Give me the internal dialog, damnit */ /* Give me the internal dialog, damnit */
fc_dialog = g_object_get_qdata (G_OBJECT (fc_button), delegate_get_quark ()); fc_dialog = g_object_get_qdata (G_OBJECT (fc_button), delegate_get_quark ());
g_assert (GTK_IS_FILE_CHOOSER (fc_dialog)); g_assert (GTK_IS_FILE_CHOOSER (fc_dialog));
g_assert (GTK_IS_DIALOG (fc_dialog)); g_assert (GTK_IS_DIALOG (fc_dialog));
} }
/* Okay, now frob the button and its optional dialog */ /* Okay, now frob the button and its optional dialog */
if (setup->tweak_current_folder) if (setup->tweak_current_folder)
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc_button), setup->tweak_current_folder); gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc_button), setup->tweak_current_folder);
if (setup->tweak_filename) if (setup->tweak_filename)
gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (fc_button), setup->tweak_filename); gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (fc_button), setup->tweak_filename);
sleep_in_main_loop (); sleep_in_main_loop ();
if (setup->open_dialog) if (setup->open_dialog)
{ {
gtk_dialog_response (GTK_DIALOG (fc_dialog), setup->dialog_response); gtk_dialog_response (GTK_DIALOG (fc_dialog), setup->dialog_response);
wait_for_idle (); wait_for_idle ();
} }
if (setup->final_current_folder) if (setup->final_current_folder)
{ {
char *folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (fc_button)); char *folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (fc_button));
g_assert_cmpstr (folder, ==, setup->final_current_folder); g_assert_cmpstr (folder, ==, setup->final_current_folder);
g_free (folder); g_free (folder);
} }
if (setup->final_filename) if (setup->final_filename)
{ {
char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fc_button)); char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fc_button));
g_assert_cmpstr (filename, ==, setup->final_filename); g_assert_cmpstr (filename, ==, setup->final_filename);
g_free (filename); g_free (filename);
}
} }
gtk_widget_destroy (window); gtk_widget_destroy (window);