mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-11-05 16:04:31 +00:00
test: Add trash-or-delete test
This patch adds trash_or_delete synchronous alternative and a test including both of these functionalities.
This commit is contained in:
parent
2727c82900
commit
a54c98973f
7 changed files with 823 additions and 68 deletions
|
@ -1141,8 +1141,12 @@ should_skip_readdir_error (CommonJob *common,
|
|||
static gboolean
|
||||
can_delete_without_confirm (GFile *file)
|
||||
{
|
||||
/* In the case of testing, we want to be able to delete
|
||||
* without asking for confirmation from the user.
|
||||
*/
|
||||
if (g_file_has_uri_scheme (file, "burn") ||
|
||||
g_file_has_uri_scheme (file, "recent"))
|
||||
g_file_has_uri_scheme (file, "recent") ||
|
||||
!g_strcmp0 (g_getenv ("RUNNING_TESTS"), "TRUE"))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -2398,10 +2402,10 @@ delete_task_done (GObject *source_object,
|
|||
}
|
||||
|
||||
static void
|
||||
delete_task_thread_func (GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
trash_or_delete_internal (GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
DeleteJob *job = task_data;
|
||||
g_autoptr (GList) to_trash_files = NULL;
|
||||
|
@ -2486,18 +2490,16 @@ delete_task_thread_func (GTask *task,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
trash_or_delete_internal (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
gboolean try_trash,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
static DeleteJob *
|
||||
setup_delete_job (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
gboolean try_trash,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
{
|
||||
GTask *task;
|
||||
DeleteJob *job;
|
||||
|
||||
/* TODO: special case desktop icon link files ... */
|
||||
|
||||
job = op_job_new (DeleteJob, parent_window);
|
||||
job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
|
||||
job->try_trash = try_trash;
|
||||
|
@ -2505,13 +2507,16 @@ trash_or_delete_internal (GList *files,
|
|||
job->done_callback = done_callback;
|
||||
job->done_callback_data = done_callback_data;
|
||||
|
||||
if (try_trash)
|
||||
if (g_strcmp0 (g_getenv ("RUNNING_TESTS"), "TRUE"))
|
||||
{
|
||||
inhibit_power_manager ((CommonJob *) job, _("Trashing Files"));
|
||||
}
|
||||
else
|
||||
{
|
||||
inhibit_power_manager ((CommonJob *) job, _("Deleting Files"));
|
||||
if (try_trash)
|
||||
{
|
||||
inhibit_power_manager ((CommonJob *) job, _("Trashing Files"));
|
||||
}
|
||||
else
|
||||
{
|
||||
inhibit_power_manager ((CommonJob *) job, _("Deleting Files"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!nautilus_file_undo_manager_is_operating () && try_trash)
|
||||
|
@ -2519,32 +2524,95 @@ trash_or_delete_internal (GList *files,
|
|||
job->common.undo_info = nautilus_file_undo_info_trash_new (g_list_length (files));
|
||||
}
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
static void
|
||||
trash_or_delete_internal_sync (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
gboolean try_trash,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
{
|
||||
GTask *task;
|
||||
DeleteJob *job;
|
||||
|
||||
job = setup_delete_job (files,
|
||||
parent_window,
|
||||
try_trash,
|
||||
done_callback,
|
||||
done_callback_data);
|
||||
|
||||
task = g_task_new (NULL, NULL, delete_task_done, job);
|
||||
g_task_set_task_data (task, job, NULL);
|
||||
g_task_run_in_thread (task, delete_task_thread_func);
|
||||
g_task_run_in_thread_sync (task, trash_or_delete_internal);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static void
|
||||
trash_or_delete_internal_async (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
gboolean try_trash,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
{
|
||||
GTask *task;
|
||||
DeleteJob *job;
|
||||
|
||||
job = setup_delete_job (files,
|
||||
parent_window,
|
||||
try_trash,
|
||||
done_callback,
|
||||
done_callback_data);
|
||||
|
||||
task = g_task_new (NULL, NULL, delete_task_done, job);
|
||||
g_task_set_task_data (task, job, NULL);
|
||||
g_task_run_in_thread (task, trash_or_delete_internal);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_file_operations_trash_or_delete (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
nautilus_file_operations_trash_or_delete_sync (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
{
|
||||
trash_or_delete_internal (files, parent_window,
|
||||
TRUE,
|
||||
done_callback, done_callback_data);
|
||||
trash_or_delete_internal_sync (files, parent_window,
|
||||
TRUE,
|
||||
done_callback, done_callback_data);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_file_operations_delete (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
nautilus_file_operations_delete_sync (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
{
|
||||
trash_or_delete_internal (files, parent_window,
|
||||
FALSE,
|
||||
done_callback, done_callback_data);
|
||||
trash_or_delete_internal_sync (files, parent_window,
|
||||
FALSE,
|
||||
done_callback, done_callback_data);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_file_operations_trash_or_delete_async (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
{
|
||||
trash_or_delete_internal_async (files, parent_window,
|
||||
TRUE,
|
||||
done_callback, done_callback_data);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_file_operations_delete_async (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
{
|
||||
trash_or_delete_internal_async (files, parent_window,
|
||||
FALSE,
|
||||
done_callback, done_callback_data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -7121,10 +7189,10 @@ nautilus_file_operations_copy_move (const GList *item_uris,
|
|||
cb_data->real_callback = done_callback;
|
||||
cb_data->real_data = done_callback_data;
|
||||
|
||||
nautilus_file_operations_trash_or_delete (locations,
|
||||
parent_window,
|
||||
(NautilusDeleteCallback) callback_for_move_to_trash,
|
||||
cb_data);
|
||||
nautilus_file_operations_trash_or_delete_async (locations,
|
||||
parent_window,
|
||||
(NautilusDeleteCallback) callback_for_move_to_trash,
|
||||
cb_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -83,14 +83,23 @@ void nautilus_file_operations_new_file_from_template (GtkWidget *p
|
|||
NautilusCreateCallback done_callback,
|
||||
gpointer data);
|
||||
|
||||
void nautilus_file_operations_delete (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
void nautilus_file_operations_trash_or_delete (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
void nautilus_file_operations_trash_or_delete_sync (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
void nautilus_file_operations_delete_sync (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
void nautilus_file_operations_trash_or_delete_async (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
void nautilus_file_operations_delete_async (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusDeleteCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
|
||||
|
||||
void nautilus_file_set_permissions_recursive (const char *directory,
|
||||
guint32 file_permissions,
|
||||
|
|
|
@ -613,10 +613,10 @@ static void
|
|||
ext_restore_undo_func (NautilusFileUndoInfoExt *self,
|
||||
GtkWindow *parent_window)
|
||||
{
|
||||
nautilus_file_operations_trash_or_delete (g_queue_peek_head_link (self->priv->destinations),
|
||||
parent_window,
|
||||
file_undo_info_delete_callback,
|
||||
self);
|
||||
nautilus_file_operations_trash_or_delete_async (g_queue_peek_head_link (self->priv->destinations),
|
||||
parent_window,
|
||||
file_undo_info_delete_callback,
|
||||
self);
|
||||
}
|
||||
|
||||
|
||||
|
@ -640,8 +640,8 @@ ext_copy_duplicate_undo_func (NautilusFileUndoInfoExt *self,
|
|||
files = g_list_copy (g_queue_peek_head_link (self->priv->destinations));
|
||||
files = g_list_reverse (files); /* Deleting must be done in reverse */
|
||||
|
||||
nautilus_file_operations_delete (files, parent_window,
|
||||
file_undo_info_delete_callback, self);
|
||||
nautilus_file_operations_delete_async (files, parent_window,
|
||||
file_undo_info_delete_callback, self);
|
||||
|
||||
g_list_free (files);
|
||||
}
|
||||
|
@ -901,8 +901,8 @@ create_undo_func (NautilusFileUndoInfo *info,
|
|||
GList *files = NULL;
|
||||
|
||||
files = g_list_append (files, g_object_ref (self->priv->target_file));
|
||||
nautilus_file_operations_delete (files, parent_window,
|
||||
file_undo_info_delete_callback, self);
|
||||
nautilus_file_operations_delete_async (files, parent_window,
|
||||
file_undo_info_delete_callback, self);
|
||||
|
||||
g_list_free_full (files, g_object_unref);
|
||||
}
|
||||
|
@ -1633,8 +1633,8 @@ trash_redo_func (NautilusFileUndoInfo *info,
|
|||
GList *locations;
|
||||
|
||||
locations = g_hash_table_get_keys (self->priv->trashed);
|
||||
nautilus_file_operations_trash_or_delete (locations, parent_window,
|
||||
trash_redo_func_callback, self);
|
||||
nautilus_file_operations_trash_or_delete_async (locations, parent_window,
|
||||
trash_redo_func_callback, self);
|
||||
|
||||
g_list_free (locations);
|
||||
}
|
||||
|
@ -2356,8 +2356,8 @@ extract_undo_func (NautilusFileUndoInfo *info,
|
|||
{
|
||||
NautilusFileUndoInfoExtract *self = NAUTILUS_FILE_UNDO_INFO_EXTRACT (info);
|
||||
|
||||
nautilus_file_operations_delete (self->priv->outputs, parent_window,
|
||||
file_undo_info_delete_callback, self);
|
||||
nautilus_file_operations_delete_async (self->priv->outputs, parent_window,
|
||||
file_undo_info_delete_callback, self);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2519,8 +2519,8 @@ compress_undo_func (NautilusFileUndoInfo *info,
|
|||
|
||||
files = g_list_prepend (files, self->priv->output);
|
||||
|
||||
nautilus_file_operations_delete (files, parent_window,
|
||||
file_undo_info_delete_callback, self);
|
||||
nautilus_file_operations_delete_async (files, parent_window,
|
||||
file_undo_info_delete_callback, self);
|
||||
|
||||
g_list_free (files);
|
||||
}
|
||||
|
|
|
@ -1624,7 +1624,7 @@ delete_selected_files (NautilusFilesView *view)
|
|||
}
|
||||
locations = g_list_reverse (locations);
|
||||
|
||||
nautilus_file_operations_delete (locations, nautilus_files_view_get_containing_window (view), NULL, NULL);
|
||||
nautilus_file_operations_delete_async (locations, nautilus_files_view_get_containing_window (view), NULL, NULL);
|
||||
|
||||
g_list_free_full (locations, g_object_unref);
|
||||
nautilus_file_list_free (selection);
|
||||
|
@ -4848,10 +4848,10 @@ trash_or_delete_files (GtkWindow *parent_window,
|
|||
|
||||
locations = g_list_reverse (locations);
|
||||
|
||||
nautilus_file_operations_trash_or_delete (locations,
|
||||
parent_window,
|
||||
(NautilusDeleteCallback) trash_or_delete_done_cb,
|
||||
view);
|
||||
nautilus_file_operations_trash_or_delete_async (locations,
|
||||
parent_window,
|
||||
(NautilusDeleteCallback) trash_or_delete_done_cb,
|
||||
view);
|
||||
g_list_free_full (locations, g_object_unref);
|
||||
}
|
||||
|
||||
|
|
|
@ -513,9 +513,9 @@ trash_or_delete_files (GtkWindow *parent_window,
|
|||
|
||||
locations = g_list_reverse (locations);
|
||||
|
||||
nautilus_file_operations_trash_or_delete (locations,
|
||||
parent_window,
|
||||
NULL, NULL);
|
||||
nautilus_file_operations_trash_or_delete_async (locations,
|
||||
parent_window,
|
||||
NULL, NULL);
|
||||
g_list_free_full (locations, g_object_unref);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,9 @@ tests = [
|
|||
]],
|
||||
['test-file-operations-copy-files', [
|
||||
'test-file-operations-copy-files.c'
|
||||
]],
|
||||
['test-file-operations-trash-or-delete', [
|
||||
'test-file-operations-trash-or-delete.c'
|
||||
]]
|
||||
]
|
||||
|
||||
|
|
|
@ -0,0 +1,675 @@
|
|||
#include <glib.h>
|
||||
#include "src/nautilus-directory.h"
|
||||
#include "src/nautilus-file-utilities.h"
|
||||
#include "src/nautilus-search-directory.h"
|
||||
#include "src/nautilus-directory.h"
|
||||
#include "src/nautilus-file-operations.c"
|
||||
#include <unistd.h>
|
||||
#include "eel/eel-string.h"
|
||||
|
||||
static void
|
||||
test_trash_one_file (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
GFileOutputStream *out = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
|
||||
g_assert_true (file != NULL);
|
||||
out = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error);
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
|
||||
{
|
||||
g_object_unref (out);
|
||||
}
|
||||
files = g_list_prepend (files, g_object_ref (file));
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
TRUE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (first_dir, NULL, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
test_trash_more_files_func (gint files_to_trash)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
GFileOutputStream *out = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < files_to_trash; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (file != NULL);
|
||||
out = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error);
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
|
||||
{
|
||||
g_object_unref (out);
|
||||
}
|
||||
files = g_list_prepend (files, g_object_ref (file));
|
||||
}
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
TRUE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < files_to_trash; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_trash_more_files (void)
|
||||
{
|
||||
test_trash_more_files_func (100);
|
||||
}
|
||||
|
||||
static void
|
||||
test_delete_one_file (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
GFileOutputStream *out = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
|
||||
g_assert_true (file != NULL);
|
||||
out = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error);
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
|
||||
{
|
||||
g_object_unref (out);
|
||||
}
|
||||
files = g_list_prepend (files, g_object_ref (file));
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
TRUE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (first_dir, NULL, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
test_delete_more_files_func (gint files_to_delete)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
GFileOutputStream *out = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < files_to_delete; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (file != NULL);
|
||||
out = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error);
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
|
||||
{
|
||||
g_object_unref (out);
|
||||
}
|
||||
files = g_list_prepend (files, g_object_ref (file));
|
||||
}
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
FALSE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < files_to_delete; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_delete_more_files (void)
|
||||
{
|
||||
test_delete_more_files_func (100);
|
||||
}
|
||||
|
||||
static void
|
||||
test_trash_one_empty_directory (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
files = g_list_prepend (files, g_object_ref (first_dir));
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
TRUE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
g_assert_false (g_file_query_exists (first_dir, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
test_trash_more_empty_directories_func (gint directories_to_trash)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) dir = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < directories_to_trash; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
files = g_list_prepend (files, g_object_ref (file));
|
||||
}
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
TRUE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < directories_to_trash; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (file != NULL);
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_trash_more_empty_directories (void)
|
||||
{
|
||||
test_trash_more_empty_directories_func (100);
|
||||
}
|
||||
|
||||
static void
|
||||
test_delete_one_empty_directory (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
files = g_list_prepend (files, g_object_ref (first_dir));
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
FALSE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
g_assert_false (g_file_query_exists (first_dir, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
test_delete_more_empty_directories_func (gint directories_to_delete)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) dir = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < directories_to_delete; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
files = g_list_prepend (files, g_object_ref (file));
|
||||
}
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
FALSE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < directories_to_delete; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (file != NULL);
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_delete_more_empty_directories (void)
|
||||
{
|
||||
test_delete_more_empty_directories_func (100);
|
||||
}
|
||||
|
||||
static void
|
||||
test_trash_one_full_directory (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
GFileOutputStream *out = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
|
||||
g_assert_true (file != NULL);
|
||||
out = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error);
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
|
||||
{
|
||||
g_object_unref (out);
|
||||
}
|
||||
|
||||
files = g_list_prepend (files, g_object_ref (first_dir));
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
TRUE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
g_assert_false (g_file_query_exists (first_dir, NULL));
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
}
|
||||
|
||||
/* The hierarchy looks like this:
|
||||
* /tmp/first_dir/first_dir_child
|
||||
* We're trashing first_dir.
|
||||
*/
|
||||
static void
|
||||
test_trash_first_hierarchy (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
|
||||
files = g_list_prepend (files, g_object_ref (first_dir));
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
TRUE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
|
||||
g_assert_false (g_file_query_exists (first_dir, NULL));
|
||||
}
|
||||
|
||||
/* The hierarchy looks like this:
|
||||
* /tmp/first_dir/first_child
|
||||
* /tmp/first_dir/second_child
|
||||
* We're trashing first_dir.
|
||||
*/
|
||||
static void
|
||||
test_trash_second_hierarchy (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
|
||||
files = g_list_prepend (files, g_object_ref (first_dir));
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_first_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_second_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
TRUE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_second_dir_child");
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
|
||||
g_assert_false (g_file_query_exists (first_dir, NULL));
|
||||
}
|
||||
|
||||
/* We're creating 50 directories each containing one file
|
||||
* and trashing all of the directories.
|
||||
*/
|
||||
static void
|
||||
test_trash_third_hierarchy (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) directory = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_directory_%i", i);
|
||||
|
||||
directory = g_file_get_child (root, file_name);
|
||||
g_file_make_directory (directory, NULL, NULL);
|
||||
files = g_list_prepend (files, g_object_ref (directory));
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (directory, file_name);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
}
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
TRUE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_directory_%i", i);
|
||||
|
||||
directory = g_file_get_child (root, file_name);
|
||||
g_assert_false (g_file_query_exists (directory, NULL));
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (directory, file_name);
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_delete_one_full_directory (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
GFileOutputStream *out = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
|
||||
g_assert_true (file != NULL);
|
||||
out = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error);
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
|
||||
{
|
||||
g_object_unref (out);
|
||||
}
|
||||
|
||||
files = g_list_prepend (files, g_object_ref (first_dir));
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
FALSE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
g_assert_false (g_file_query_exists (first_dir, NULL));
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
}
|
||||
|
||||
/* The hierarchy looks like this:
|
||||
* /tmp/first_dir/first_dir_child
|
||||
* We're deleting first_dir.
|
||||
*/
|
||||
static void
|
||||
test_delete_first_hierarchy (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
|
||||
files = g_list_prepend (files, g_object_ref (first_dir));
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
FALSE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
|
||||
g_assert_false (g_file_query_exists (first_dir, NULL));
|
||||
}
|
||||
|
||||
/* The hierarchy looks like this:
|
||||
* /tmp/first_dir/first_child
|
||||
* /tmp/first_dir/second_child
|
||||
* We're deleting first_dir.
|
||||
*/
|
||||
static void
|
||||
test_delete_second_hierarchy (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
|
||||
files = g_list_prepend (files, g_object_ref (first_dir));
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_first_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_second_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
FALSE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
|
||||
file = g_file_get_child (first_dir, "trash_or_delete_second_dir_child");
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
|
||||
g_assert_false (g_file_query_exists (first_dir, NULL));
|
||||
}
|
||||
|
||||
/* We're creating 50 directories each containing one file
|
||||
* and deleting all of the directories.
|
||||
*/
|
||||
static void
|
||||
test_delete_third_hierarchy (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) directory = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_directory_%i", i);
|
||||
|
||||
directory = g_file_get_child (root, file_name);
|
||||
g_file_make_directory (directory, NULL, NULL);
|
||||
files = g_list_prepend (files, g_object_ref (directory));
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (directory, file_name);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
}
|
||||
|
||||
trash_or_delete_internal_sync (files,
|
||||
NULL,
|
||||
FALSE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_directory_%i", i);
|
||||
|
||||
directory = g_file_get_child (root, file_name);
|
||||
g_assert_false (g_file_query_exists (directory, NULL));
|
||||
|
||||
file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
|
||||
file = g_file_get_child (directory, file_name);
|
||||
g_assert_false (g_file_query_exists (file, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
setup_test_suite (void)
|
||||
{
|
||||
g_test_add_func ("/test-trash-one-file/1.0",
|
||||
test_trash_one_file);
|
||||
g_test_add_func ("/test-trash-more-files/1.0",
|
||||
test_trash_more_files);
|
||||
g_test_add_func ("/test-delete-one-file/1.0",
|
||||
test_delete_one_file);
|
||||
g_test_add_func ("/test-delete-more-files/1.0",
|
||||
test_delete_more_files);
|
||||
g_test_add_func ("/test-trash-one-empty-directory/1.0",
|
||||
test_trash_one_empty_directory);
|
||||
g_test_add_func ("/test-trash-more-empty-directories/1.0",
|
||||
test_trash_more_empty_directories);
|
||||
g_test_add_func ("/test-delete-one-empty-directory/1.0",
|
||||
test_delete_one_empty_directory);
|
||||
g_test_add_func ("/test-delete-more-directories/1.0",
|
||||
test_delete_more_empty_directories);
|
||||
g_test_add_func ("/test-trash-one-full-directory/1.0",
|
||||
test_trash_one_full_directory);
|
||||
g_test_add_func ("/test-trash-one-full-directory/1.1",
|
||||
test_trash_first_hierarchy);
|
||||
g_test_add_func ("/test-trash-one-full-directory/1.2",
|
||||
test_trash_second_hierarchy);
|
||||
g_test_add_func ("/test-trash-more-full-directories/1.6",
|
||||
test_trash_third_hierarchy);
|
||||
g_test_add_func ("/test-delete-one-full-directory/1.0",
|
||||
test_delete_one_full_directory);
|
||||
g_test_add_func ("/test-delete-one-full-directory/1.1",
|
||||
test_delete_first_hierarchy);
|
||||
g_test_add_func ("/test-delete-one-full-directory/1.2",
|
||||
test_delete_second_hierarchy);
|
||||
g_test_add_func ("/test-delete-more-full-directories/1.6",
|
||||
test_delete_third_hierarchy);
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
g_autoptr (NautilusFileUndoManager) undo_manager = NULL;
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_set_nonfatal_assertions ();
|
||||
nautilus_ensure_extension_points();
|
||||
undo_manager = nautilus_file_undo_manager_new ();
|
||||
|
||||
setup_test_suite ();
|
||||
|
||||
return g_test_run ();
|
||||
}
|
Loading…
Reference in a new issue