summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@novell.com>2006-07-18 16:36:19 +0000
committerFederico Mena Quintero <federico@src.gnome.org>2006-07-18 16:36:19 +0000
commit3f498adfb00525aa2af73889fc9c184f4ccadeb6 (patch)
treea4366b252170a20321adf0d3c44e8b86cc2c6db8 /tests
parent73e31871385ae59bc0a4a9910655c2f708d4e228 (diff)
downloadgtk+-3f498adfb00525aa2af73889fc9c184f4ccadeb6.tar.gz
Fix https://bugzilla.novell.com/show_bug.cgi?id=184875 - make the location
2006-07-18 Federico Mena Quintero <federico@novell.com> Fix https://bugzilla.novell.com/show_bug.cgi?id=184875 - make the location entry in Save mode preserve the stuff from set_filename(); it was overwriting it with $cwd. This is the same fix for http://bugzilla.gnome.org/show_bug.cgi?id=347066 * tests/autotestfilechooser.c: (test_black_box): Added black-box test for set_filename() and set_current_name(). * gtk/gtkfilechooser.c (gtk_file_chooser_get_type): Cast to GClassInitFunc in the call to g_type_register_static_simple(), to avoid a compiler warning. * gtk/gtkfilechooserprivate.h (struct _GtkFileChooserDefault): Added a browse_files_last_selected_name field. We'll copy the logic from gtkfilesel.c to see when to clear the location entry. (struct _GtkFileChooserDefault): Removed the processing_pending_selections field. * gtk/gtkfilechooserdefault.c (gtk_file_chooser_default_finalize): Free impl->browse_files_last_selected_name. (pending_select_paths_process): Don't use impl->processing_pending_selections. (update_chooser_entry): Keep track of the name that was last selected in the file list. We use this to know when to clear the location entry. The logic is similar to that of gtkfilesel.c:gtk_file_selection_file_changed(). This also lets us get rid of the processing_pending_selections flag. (update_chooser_entry): Clear the entry if we didn't have a selection before. (location_switch_to_filename_entry): Do not set $cwd as the contents of the location entry here... (location_popup_handler): ... but do it here instead, only as the result of the user asking to turn on the location entry. (gtk_file_chooser_default_get_paths): If the location entry is empty, do the fallback of seeing if it is sensible to say that $cwd is the selected path. (gtk_file_chooser_default_update_current_folder): Don't set the text of the location entry; this is no longer needed with the fixes above. (shortcuts_activate_iter): Clear the location entry when activating a shortcut if we are not in SAVE mode. This keeps the contents of the location entry consistent even when switching folders via the shortcuts.
Diffstat (limited to 'tests')
-rw-r--r--tests/autotestfilechooser.c205
1 files changed, 202 insertions, 3 deletions
diff --git a/tests/autotestfilechooser.c b/tests/autotestfilechooser.c
index bf654bccb5..bef08eadaa 100644
--- a/tests/autotestfilechooser.c
+++ b/tests/autotestfilechooser.c
@@ -23,9 +23,6 @@
/* TODO:
*
- * - Use g_log_set_default_handler() instead of the mess of specific handlers we
- * have in main().
- *
* - In test_reload_sequence(), test that the selection is preserved properly
* between unmap/map.
*
@@ -56,6 +53,207 @@ log_test (gboolean passed, const char *test_name, ...)
g_free (str);
}
+typedef void (* SetFilenameFn) (GtkFileChooser *chooser, gpointer data);
+typedef gboolean (* CompareFilenameFn) (GtkFileChooser *chooser, gpointer data);
+
+struct test_set_filename_closure {
+ GtkWidget *chooser;
+ GtkWidget *accept_button;
+ gboolean focus_button;
+};
+
+static gboolean
+timeout_cb (gpointer data)
+{
+ struct test_set_filename_closure *closure;
+
+ closure = data;
+
+ if (closure->focus_button)
+ gtk_widget_grab_focus (closure->accept_button);
+
+ gtk_button_clicked (GTK_BUTTON (closure->accept_button));
+
+ return FALSE;
+}
+
+static gboolean
+test_set_filename (GtkFileChooserAction action,
+ gboolean focus_button,
+ SetFilenameFn set_filename_fn,const
+ CompareFilenameFn compare_filename_fn,
+ gpointer data)
+{
+ GtkWidget *chooser;
+ struct test_set_filename_closure closure;
+ gboolean retval;
+
+ chooser = gtk_file_chooser_dialog_new ("hello", NULL, action,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ NULL);
+
+ closure.chooser = chooser;
+ closure.accept_button = gtk_dialog_add_button (GTK_DIALOG (chooser), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
+ closure.focus_button = focus_button;
+
+ gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT);
+
+ (* set_filename_fn) (GTK_FILE_CHOOSER (chooser), data);
+
+ g_timeout_add (2000, timeout_cb, &closure);
+ gtk_dialog_run (GTK_DIALOG (chooser));
+
+ retval = (* compare_filename_fn) (GTK_FILE_CHOOSER (chooser), data);
+
+ gtk_widget_destroy (chooser);
+
+ return retval;
+}
+
+static void
+set_filename_cb (GtkFileChooser *chooser, gpointer data)
+{
+ const char *filename;
+
+ filename = data;
+ gtk_file_chooser_set_filename (chooser, filename);
+}
+
+static gboolean
+compare_filename_cb (GtkFileChooser *chooser, gpointer data)
+{
+ const char *filename;
+ char *out_filename;
+ gboolean retval;
+
+ filename = data;
+ out_filename = gtk_file_chooser_get_filename (chooser);
+
+ if (out_filename)
+ {
+ retval = (strcmp (out_filename, filename) == 0);
+ g_free (out_filename);
+ } else
+ retval = FALSE;
+
+ return retval;
+}
+
+static gboolean
+test_black_box_set_filename (GtkFileChooserAction action, const char *filename, gboolean focus_button)
+{
+ gboolean passed;
+
+ passed = test_set_filename (action, focus_button, set_filename_cb, compare_filename_cb, (char *) filename);
+
+ log_test (passed, "set_filename: action %d, focus_button=%s",
+ (int) action,
+ focus_button ? "TRUE" : "FALSE");
+
+ return passed;
+
+}
+
+struct current_name_closure {
+ const char *path;
+ const char *current_name;
+};
+
+static void
+set_current_name_cb (GtkFileChooser *chooser, gpointer data)
+{
+ struct current_name_closure *closure;
+
+ closure = data;
+
+ gtk_file_chooser_set_current_folder (chooser, closure->path);
+ gtk_file_chooser_set_current_name (chooser, closure->current_name);
+}
+
+static gboolean
+compare_current_name_cb (GtkFileChooser *chooser, gpointer data)
+{
+ struct current_name_closure *closure;
+ char *out_filename;
+ gboolean retval;
+
+ closure = data;
+
+ out_filename = gtk_file_chooser_get_filename (chooser);
+
+ if (out_filename)
+ {
+ char *filename;
+
+ filename = g_build_filename (closure->path, closure->current_name, NULL);
+ retval = (strcmp (filename, out_filename) == 0);
+ g_free (filename);
+ g_free (out_filename);
+ } else
+ retval = FALSE;
+
+ return retval;
+}
+
+static gboolean
+test_black_box_set_current_name (const char *path, const char *current_name, gboolean focus_button)
+{
+ struct current_name_closure closure;
+ gboolean passed;
+
+ closure.path = path;
+ closure.current_name = current_name;
+
+ passed = test_set_filename (GTK_FILE_CHOOSER_ACTION_SAVE, focus_button,
+ set_current_name_cb, compare_current_name_cb, &closure);
+
+ log_test (passed, "set_current_name, focus_button=%s", focus_button ? "TRUE" : "FALSE");
+
+ return passed;
+}
+
+/* FIXME: fails in CREATE_FOLDER mode when FOLDER_NAME == "/" */
+
+#if 0
+#define FILE_NAME "/nonexistent"
+#define FOLDER_NAME "/etc"
+#else
+#define FILE_NAME "/etc/passwd"
+#define FOLDER_NAME "/etc"
+#endif
+
+#define CURRENT_NAME "parangaricutirimicuaro.txt"
+
+/* https://bugzilla.novell.com/show_bug.cgi?id=184875
+ * http://bugzilla.gnome.org/show_bug.cgi?id=347066
+ */
+static gboolean
+test_black_box (void)
+{
+ gboolean passed;
+ char *cwd;
+
+ passed = passed && test_black_box_set_filename (GTK_FILE_CHOOSER_ACTION_OPEN, FILE_NAME, FALSE);
+ passed = passed && test_black_box_set_filename (GTK_FILE_CHOOSER_ACTION_OPEN, FILE_NAME, TRUE);
+ passed = passed && test_black_box_set_filename (GTK_FILE_CHOOSER_ACTION_SAVE, FILE_NAME, FALSE);
+ passed = passed && test_black_box_set_filename (GTK_FILE_CHOOSER_ACTION_SAVE, FILE_NAME, TRUE);
+ passed = passed && test_black_box_set_filename (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, FOLDER_NAME, FALSE);
+ passed = passed && test_black_box_set_filename (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, FOLDER_NAME, TRUE);
+ passed = passed && test_black_box_set_filename (GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER, FOLDER_NAME, FALSE);
+ passed = passed && test_black_box_set_filename (GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER, FOLDER_NAME, TRUE);
+
+ cwd = g_get_current_dir ();
+
+ passed = passed && test_black_box_set_current_name (cwd, CURRENT_NAME, FALSE);
+ passed = passed && test_black_box_set_current_name (cwd, CURRENT_NAME, TRUE);
+
+ g_free (cwd);
+
+ log_test (passed, "Black box tests");
+
+ return passed;
+}
+
static const GtkFileChooserAction open_actions[] = {
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
@@ -707,6 +905,7 @@ main (int argc, char **argv)
gtk_init (&argc, &argv);
/* Start tests */
+ passed = passed && test_black_box ();
passed = passed && test_action_widgets ();
passed = passed && test_reload ();
passed = passed && test_button_folder_states ();