#include "gtk/gtkfilechooserdefault.h"
#include "gtk/gtkfilechooserentry.h"
+#if 0
+static const char *
+get_action_name (GtkFileChooserAction action)
+{
+ switch (action)
+ {
+ case GTK_FILE_CHOOSER_ACTION_OPEN: return "OPEN";
+ case GTK_FILE_CHOOSER_ACTION_SAVE: return "SAVE";
+ case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: return "SELECT_FOLDER";
+ case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: return "CREATE_FOLDER";
+
+ default:
+ g_assert_not_reached ();
+ return NULL;
+ }
+}
+#endif
+
+#ifdef BROKEN_TESTS
static void
log_test (gboolean passed, const char *test_name, ...)
{
return FALSE;
}
+#endif
static guint wait_for_idle_id = 0;
gtk_main_iteration ();
}
+#ifdef BROKEN_TESTS
static void
test_set_filename (GtkFileChooserAction action,
gboolean focus_button,
g_free (cwd);
}
+#endif
/* FIXME: fails in CREATE_FOLDER mode when FOLDER_NAME == "/" */
#if 0
#define FILE_NAME "/nonexistent"
+#define FILE_NAME_2 "/nonexistent2"
#define FOLDER_NAME "/etc"
+#define FOLDER_NAME_2 "/usr"
#else
#define FILE_NAME "/etc/passwd"
+#define FILE_NAME_2 "/etc/group"
#define FOLDER_NAME "/etc"
+#define FOLDER_NAME_2 "/usr"
#endif
#define CURRENT_NAME "parangaricutirimicuaro.txt"
* http://bugzilla.gnome.org/show_bug.cgi?id=346058
*/
+#ifdef BROKEN_TESTS
static void
setup_set_filename_tests (void)
{
for (i = 0; i < G_N_ELEMENTS (tests); i++)
g_test_add_data_func (tests[i].test_name, &tests[i], test_black_box_set_current_name);
}
+#endif
+
+typedef struct
+{
+ const char *shortname;
+ GtkFileChooserAction action;
+ const char *initial_current_folder;
+ const char *initial_filename;
+ gboolean open_dialog;
+ const char *tweak_current_folder;
+ const char *tweak_filename;
+ gint dialog_response;
+ const char *final_current_folder;
+ const char *final_filename;
+} FileChooserButtonTest;
+
+static char *
+make_button_test_name (FileChooserButtonTest *t)
+{
+ return g_strdup_printf ("/GtkFileChooserButton/%s", t->shortname);
+#if 0
+ GString *s = g_string_new ("/GtkFileChooserButton");
+
+ g_string_append_printf (s, "/%s/%s/%s/%s",
+ get_action_name (t->action),
+ t->initial_current_folder ? "set_initial_folder" : "no_default_folder",
+ t->initial_filename ? "set_initial_filename" : "no_initial_filename",
+ t->open_dialog ? "open_dialog" : "no_dialog");
+
+ if (t->tweak_current_folder)
+ g_string_append (s, "/tweak_current_folder");
+
+ if (t->tweak_filename)
+ g_string_append (s, "/tweak_filename");
+
+ if (t->open_dialog)
+ g_string_append_printf (s, "/%s",
+ t->dialog_response == GTK_RESPONSE_ACCEPT ? "accept" : "cancel");
+
+ if (t->final_current_folder)
+ g_string_append (s, "/final_current_folder");
+
+ if (t->final_filename)
+ g_string_append (s, "/final_filename");
+
+ return g_string_free (s, FALSE);
+#endif
+}
+
+/* Copied from gtkfilechooserutils.c:_gtk_file_chooser_delegate_get_quark() */
+static GQuark
+delegate_get_quark (void)
+{
+ static GQuark quark = 0;
+
+ if (G_UNLIKELY (quark == 0))
+ quark = g_quark_from_static_string ("gtk-file-chooser-delegate");
+
+ return quark;
+}
+
+static gboolean
+sleep_timeout_cb (gpointer data)
+{
+ gtk_main_quit ();
+ return FALSE;
+}
+
+static void
+sleep_in_main_loop (void)
+{
+ /* process all pending idles and events */
+ while (g_main_context_pending (NULL))
+ g_main_context_iteration (NULL, FALSE);
+ /* sleeping probably isn't strictly necessary here */
+ gdk_threads_add_timeout_full (G_MAXINT, 250, sleep_timeout_cb, NULL, NULL);
+ gtk_main ();
+ /* process any pending idles or events that arrived during sleep */
+ while (g_main_context_pending (NULL))
+ g_main_context_iteration (NULL, FALSE);
+}
+
+static void
+build_children_list (GtkWidget *widget, gpointer data)
+{
+ GList **list;
+
+ list = data;
+ *list = g_list_prepend (*list, widget);
+}
+
+static GtkWidget *
+find_child_widget_with_atk_role (GtkWidget *widget, AtkRole role)
+{
+ AtkObject *accessible;
+ AtkRole a_role;
+
+ accessible = gtk_widget_get_accessible (widget);
+ a_role = atk_object_get_role (accessible);
+
+ if (a_role == role)
+ return widget;
+ else
+ {
+ GtkWidget *found_child;
+
+ found_child = NULL;
+
+ if (GTK_IS_CONTAINER (widget))
+ {
+ GList *children;
+ GList *l;
+
+ children = NULL;
+ gtk_container_forall (GTK_CONTAINER (widget), build_children_list, &children);
+
+ l = children;
+
+ while (l && !found_child)
+ {
+ GtkWidget *child;
+
+ child = GTK_WIDGET (l->data);
+
+ found_child = find_child_widget_with_atk_role (child, role);
+
+ l = l->next;
+ }
+
+ g_list_free (children);
+ }
+
+ return found_child;
+ }
+}
+
+static const char *
+get_atk_name_for_filechooser_button (GtkFileChooserButton *button)
+{
+ GtkFileChooserAction action;
+ GtkWidget *widget;
+ AtkObject *accessible;
+
+ action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (button));
+ g_assert (action == GTK_FILE_CHOOSER_ACTION_OPEN || action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+
+ if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
+ widget = find_child_widget_with_atk_role (GTK_WIDGET (button), ATK_ROLE_PUSH_BUTTON);
+ else
+ widget = find_child_widget_with_atk_role (GTK_WIDGET (button), ATK_ROLE_COMBO_BOX);
+
+ accessible = gtk_widget_get_accessible (widget);
+ return atk_object_get_name (accessible);
+}
+
+static void
+check_that_basename_is_shown (GtkFileChooserButton *button, const char *expected_filename)
+{
+ GtkFileChooserAction action;
+ const char *name_on_button;
+ char *expected_basename;
+
+ name_on_button = get_atk_name_for_filechooser_button (button);
+
+ action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (button));
+ g_assert (action == GTK_FILE_CHOOSER_ACTION_OPEN || action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+
+ if (expected_filename)
+ expected_basename = g_path_get_basename (expected_filename);
+ else
+ expected_basename = NULL;
+
+ if (expected_basename)
+ g_assert_cmpstr (expected_basename, ==, name_on_button);
+ else
+ g_assert_cmpstr (name_on_button, ==, "(None)"); /* see gtkfilechooserbutton.c:FALLBACK_DISPLAY_NAME */ /* FIXME: how do we translate this? */
+
+ g_free (expected_basename);
+}
+
+static const char *
+get_expected_shown_filename (GtkFileChooserAction action, const char *folder_name, const char *filename)
+{
+ if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+ {
+ if (filename)
+ return filename;
+ else
+ return folder_name;
+ }
+ else
+ return filename;
+}
+
+static void
+test_file_chooser_button (gconstpointer data)
+{
+ const FileChooserButtonTest *setup = data;
+ GtkWidget *window;
+ GtkWidget *fc_button;
+ GtkWidget *fc_dialog;
+ int iterations;
+ int i;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ fc_button = gtk_file_chooser_button_new (setup->action == GTK_FILE_CHOOSER_ACTION_OPEN ? "Select a file" : "Select a folder",
+ setup->action);
+ gtk_container_add (GTK_CONTAINER (window), fc_button);
+
+ if (setup->initial_current_folder)
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc_button), setup->initial_current_folder);
+
+ if (setup->initial_filename)
+ gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (fc_button), setup->initial_filename);
+
+ gtk_widget_show_all (window);
+ sleep_in_main_loop ();
+
+ check_that_basename_is_shown (GTK_FILE_CHOOSER_BUTTON (fc_button),
+ get_expected_shown_filename (setup->action, setup->initial_current_folder, setup->initial_filename));
+
+ /* 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)
+ iterations = 2;
+ else
+ iterations = 1;
+
+ for (i = 0; i < iterations; i++)
+ {
+ if (setup->open_dialog)
+ {
+ GList *children;
+
+ /* Hack our way into the file chooser button; get its GtkButton child and click it */
+ children = gtk_container_get_children (GTK_CONTAINER (fc_button));
+ g_assert (children && GTK_IS_BUTTON (children->data));
+ gtk_button_clicked (GTK_BUTTON (children->data));
+ g_list_free (children);
+
+ sleep_in_main_loop ();
+
+ /* Give me the internal dialog, damnit */
+ 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_DIALOG (fc_dialog));
+ }
+
+ /* Okay, now frob the button and its optional dialog */
+
+ if (setup->tweak_current_folder)
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc_button), setup->tweak_current_folder);
+
+ if (setup->tweak_filename)
+ gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (fc_button), setup->tweak_filename);
+ sleep_in_main_loop ();
+
+ if (setup->open_dialog)
+ {
+ gtk_dialog_response (GTK_DIALOG (fc_dialog), setup->dialog_response);
+ wait_for_idle ();
+ }
+
+ if (setup->final_current_folder)
+ {
+ char *folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (fc_button));
+
+ g_assert_cmpstr (folder, ==, setup->final_current_folder);
+ g_free (folder);
+ }
+
+ if (setup->final_filename)
+ {
+ char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fc_button));
+
+ g_assert_cmpstr (filename, ==, setup->final_filename);
+ g_free (filename);
+ }
+
+ check_that_basename_is_shown (GTK_FILE_CHOOSER_BUTTON (fc_button),
+ get_expected_shown_filename (setup->action, setup->final_current_folder, setup->final_filename));
+ }
+
+ gtk_widget_destroy (window);
+}
+
+static FileChooserButtonTest button_tests[] =
+ {
+ /* OPEN tests without dialog */
+
+ {
+ "open-1",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ FALSE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ 0, /* dialog_response */
+ NULL, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "open-2",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ FILE_NAME, /* initial_filename */
+ FALSE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ 0, /* dialog_response */
+ NULL, /* final_current_folder */
+ FILE_NAME /* final_filename */
+ },
+ {
+ "open-3",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ FALSE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FILE_NAME, /* tweak_filename */
+ 0, /* dialog_response */
+ NULL, /* final_current_folder */
+ FILE_NAME /* final_filename */
+ },
+ {
+ "open-4",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ FILE_NAME, /* initial_filename */
+ FALSE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FILE_NAME_2, /* tweak_filename */
+ 0, /* dialog_response */
+ NULL, /* final_current_folder */
+ FILE_NAME_2 /* final_filename */
+ },
+ {
+ "open-5",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ FALSE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ 0, /* dialog_response */
+ FOLDER_NAME, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "open-6",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ FALSE, /* open_dialog */
+ FOLDER_NAME_2, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ 0, /* dialog_response */
+ FOLDER_NAME_2, /* final_current_folder */
+ NULL /* final_filename */
+ },
+
+ /* SELECT_FOLDER tests without dialog */
+
+ {
+ "select-folder-1",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ FALSE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ 0, /* dialog_response */
+ NULL, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "select-folder-2",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ FOLDER_NAME, /* initial_filename */
+ FALSE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ 0, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+ {
+ "select-folder-3",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ FOLDER_NAME, /* initial_filename */
+ FALSE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME_2, /* tweak_filename */
+ 0, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME_2 /* final_filename */
+ },
+ {
+ "select-folder-4",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ FALSE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ 0, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+ {
+ "select-folder-5",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ FALSE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ 0, /* dialog_response */
+ FOLDER_NAME, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "select-folder-6",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ FALSE, /* open_dialog */
+ FOLDER_NAME_2, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ 0, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME_2 /* final_filename */
+ },
+ {
+ "select-folder-7",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ FALSE, /* open_dialog */
+ FOLDER_NAME_2, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ 0, /* dialog_response */
+ FOLDER_NAME_2, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "select-folder-8",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ FALSE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME_2, /* tweak_filename */
+ 0, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME_2 /* final_filename */
+ },
+
+ /* OPEN tests with dialog, cancelled */
+
+ {
+ "open-dialog-cancel-1",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ NULL, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "open-dialog-cancel-2",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ FILE_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ NULL, /* final_current_folder */
+ FILE_NAME /* final_filename */
+ },
+ {
+ "open-dialog-cancel-3",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ FOLDER_NAME, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "open-dialog-cancel-4",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FILE_NAME, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ NULL, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "open-dialog-cancel-5",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ FILE_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FILE_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ NULL, /* final_current_folder */
+ FILE_NAME /* final_filename */
+ },
+ {
+ "open-dialog-cancel-6",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FILE_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ FOLDER_NAME, /* final_current_folder */
+ NULL /* final_filename */
+ },
+
+ /* OPEN tests with dialog, cancelled via closing the dialog (not by selecting the Cancel button) */
+
+ {
+ "open-dialog-close-1",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ NULL, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "open-dialog-close-2",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ FILE_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ NULL, /* final_current_folder */
+ FILE_NAME /* final_filename */
+ },
+ {
+ "open-dialog-close-3",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ FOLDER_NAME, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "open-dialog-close-4",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FILE_NAME, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ NULL, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "open-dialog-close-5",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ FILE_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FILE_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ NULL, /* final_current_folder */
+ FILE_NAME /* final_filename */
+ },
+ {
+ "open-dialog-close-6",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FILE_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ FOLDER_NAME, /* final_current_folder */
+ NULL /* final_filename */
+ },
+
+ /* SELECT_FOLDER tests with dialog, cancelled */
+
+ {
+ "select-folder-dialog-cancel-1",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ NULL, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "select-folder-dialog-cancel-2",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ FOLDER_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+ {
+ "select-folder-dialog-cancel-3",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ FOLDER_NAME, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "select-folder-dialog-cancel-4",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+ {
+ "select-folder-dialog-cancel-5",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ NULL, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "select-folder-dialog-cancel-6",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ FOLDER_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+ {
+ "select-folder-dialog-cancel-7",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ FOLDER_NAME, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "select-folder-dialog-cancel-8",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_CANCEL, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+
+ /* SELECT_FOLDER tests with dialog, cancelled via closing the dialog (not selecting the Cancel button) */
+
+ {
+ "select-folder-dialog-close-1",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ NULL, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "select-folder-dialog-close-2",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ FOLDER_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+ {
+ "select-folder-dialog-close-3",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ FOLDER_NAME, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "select-folder-dialog-close-4",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+ {
+ "select-folder-dialog-close-5",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ NULL, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "select-folder-dialog-close-6",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ FOLDER_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+ {
+ "select-folder-dialog-close-7",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ FOLDER_NAME, /* final_current_folder */
+ NULL /* final_filename */
+ },
+ {
+ "select-folder-dialog-close-8",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+
+ /* OPEN tests with dialog */
+
+ {
+ "open-dialog-1",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FILE_NAME, /* tweak_filename */
+ GTK_RESPONSE_ACCEPT, /* dialog_response */
+ NULL, /* final_current_folder */
+ FILE_NAME /* final_filename */
+ },
+ {
+ "open-dialog-2",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ FILE_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_ACCEPT, /* dialog_response */
+ NULL, /* final_current_folder */
+ FILE_NAME /* final_filename */
+ },
+ {
+ "open-dialog-3",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL, /* initial_current_folder */
+ FILE_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FILE_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_ACCEPT, /* dialog_response */
+ NULL, /* final_current_folder */
+ FILE_NAME_2 /* final_filename */
+ },
+ {
+ "open-dialog-4",
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FILE_NAME, /* tweak_filename */
+ GTK_RESPONSE_ACCEPT, /* dialog_response */
+ NULL, /* final_current_folder */
+ FILE_NAME /* final_filename */
+ },
+
+ /* SELECT_FOLDER tests with dialog */
+
+ {
+ "select-folder-dialog-1",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ FOLDER_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_ACCEPT, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+ {
+ "select-folder-dialog-2",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ NULL, /* tweak_filename */
+ GTK_RESPONSE_ACCEPT, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME /* final_filename */
+ },
+ {
+ "select-folder-dialog-3",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ NULL, /* initial_current_folder */
+ FOLDER_NAME, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_ACCEPT, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME_2 /* final_filename */
+ },
+ {
+ "select-folder-dialog-4",
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FOLDER_NAME, /* initial_current_folder */
+ NULL, /* initial_filename */
+ TRUE, /* open_dialog */
+ NULL, /* tweak_current_folder */
+ FOLDER_NAME_2, /* tweak_filename */
+ GTK_RESPONSE_ACCEPT, /* dialog_response */
+ NULL, /* final_current_folder */
+ FOLDER_NAME_2 /* final_filename */
+ },
+
+ };
+
+static void
+setup_file_chooser_button_tests (void)
+{
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS (button_tests); i++)
+ {
+ char *test_name;
+
+ test_name = make_button_test_name (&button_tests[i]);
+ g_test_add_data_func (test_name, &button_tests[i], test_file_chooser_button);
+ g_free (test_name);
+ }
+}
+
+#ifdef BROKEN_TESTS
struct confirm_overwrite_closure {
GtkWidget *chooser;
GtkWidget *accept_button;
passed = passed && test_confirm_overwrite_for_path ("/etc/resolv.conf", TRUE);
g_assert (passed);
}
+#endif
static const GtkFileChooserAction open_actions[] = {
GTK_FILE_CHOOSER_ACTION_OPEN,
};
+#ifdef BROKEN_TESTS
static gboolean
has_action (const GtkFileChooserAction *actions,
int n_actions,
return FALSE;
}
-static const char *
-get_action_name (GtkFileChooserAction action)
-{
- GEnumClass *enum_class;
- GEnumValue *enum_value;
-
- enum_class = g_type_class_peek (GTK_TYPE_FILE_CHOOSER_ACTION);
- if (!enum_class)
- g_error ("BUG: get_action_name(): no GEnumClass for GTK_TYPE_FILE_CHOOSER_ACTION");
-
- enum_value = g_enum_get_value (enum_class, (int) action);
- if (!enum_value)
- g_error ("BUG: get_action_name(): no GEnumValue for GtkFileChooserAction %d", (int) action);
-
- return enum_value->value_name;
-}
-
static GtkFileChooserDefault *
get_impl_from_dialog (GtkWidget *dialog)
{
return impl;
}
-#ifdef BROKEN_TESTS
+
static gboolean
test_widgets_for_current_action (GtkFileChooserDialog *dialog,
GtkFileChooserAction expected_action)
log_test (passed, "test_reload(): set a folder explicitly before mapping");
g_assert (passed);
}
-#endif
static gboolean
test_button_folder_states_for_action (GtkFileChooserAction action, gboolean use_dialog, gboolean set_folder_on_dialog)
log_test (passed, "test_button_folder_states(): all supported actions");
}
-static gboolean
-sleep_timeout_cb (gpointer data)
-{
- gtk_main_quit ();
- return FALSE;
-}
-
-static void
-sleep_in_main_loop (double fraction)
-{
- /* process all pending idles and events */
- while (g_main_context_pending (NULL))
- g_main_context_iteration (NULL, FALSE);
- /* sleeping probably isn't strictly necessary here */
- gdk_threads_add_timeout_full (G_MAXINT, fraction * SLEEP_DURATION, sleep_timeout_cb, NULL, NULL);
- gtk_main ();
- /* process any pending idles or events that arrived during sleep */
- while (g_main_context_pending (NULL))
- g_main_context_iteration (NULL, FALSE);
-}
-
static void
test_folder_switch_and_filters (void)
{
/* Test that filter is unchanged when we switch folders */
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd);
- sleep_in_main_loop (0.5);
+ sleep_in_main_loop ();
passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == txt_filter);
g_assert (passed);
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), base_dir);
- sleep_in_main_loop (0.25);
+ sleep_in_main_loop ();
g_signal_emit_by_name (impl->browse_path_bar, "path-clicked",
cwd_file,
base_dir_file,
FALSE);
- sleep_in_main_loop (0.25);
+ sleep_in_main_loop ();
passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == txt_filter);
log_test (passed, "test_folder_switch_and_filters(): filter after changing folder");
g_assert (passed);
log_test (passed, "test_folder_switch_and_filters(): all filter tests");
}
+#endif
int
main (int argc,
/* initialize test program */
gtk_test_init (&argc, &argv);
- /* register tests */
+ /* Register tests */
+
+ setup_file_chooser_button_tests ();
+#ifdef BROKEN_TESTS
setup_set_filename_tests ();
setup_set_current_name_tests ();
+
g_test_add_func ("/GtkFileChooser/confirm_overwrite", test_confirm_overwrite);
-#ifdef BROKEN_TESTS
g_test_add_func ("/GtkFileChooser/action_widgets", test_action_widgets);
-#endif
-#ifdef BROKEN_TESTS
g_test_add_func ("/GtkFileChooser/reload", test_reload);
-#endif
g_test_add_func ("/GtkFileChooser/button_folder_states", test_button_folder_states);
g_test_add_func ("/GtkFileChooser/folder_switch_and_filters", test_folder_switch_and_filters);
+#endif
/* run and check selected tests */
return g_test_run();