mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-11-05 16:04:31 +00:00
test: Add copy operations unit test
This patch adds both a sync alternative to the copy operations and a test for it.
This commit is contained in:
parent
1be08bd3a0
commit
2727c82900
7 changed files with 906 additions and 64 deletions
|
@ -105,7 +105,7 @@ handle_copy_uris (NautilusDBusFileOperations *object,
|
|||
g_file_new_for_uri (sources[idx]));
|
||||
}
|
||||
|
||||
nautilus_file_operations_copy (source_files, dest_dir, NULL, NULL, NULL);
|
||||
nautilus_file_operations_copy_async (source_files, dest_dir, NULL, NULL, NULL);
|
||||
|
||||
g_list_free_full (source_files, g_object_unref);
|
||||
g_object_unref (dest_dir);
|
||||
|
|
|
@ -255,6 +255,16 @@ static void empty_trash_task_done (GObject *source_object,
|
|||
|
||||
static char *query_fs_type (GFile *file,
|
||||
GCancellable *cancellable);
|
||||
static CopyMoveJob *copy_job_setup (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
|
||||
static void nautilus_file_operations_copy (GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable);
|
||||
|
||||
static void nautilus_file_operations_move (GTask *task,
|
||||
gpointer source_object,
|
||||
|
@ -5652,11 +5662,33 @@ copy_task_done (GObject *source_object,
|
|||
nautilus_file_changes_consume_changes (TRUE);
|
||||
}
|
||||
|
||||
static CopyMoveJob *
|
||||
copy_job_setup (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
{
|
||||
CopyMoveJob *job;
|
||||
|
||||
job = op_job_new (CopyMoveJob, parent_window);
|
||||
job->done_callback = done_callback;
|
||||
job->done_callback_data = done_callback_data;
|
||||
job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
|
||||
job->destination = g_object_ref (target_dir);
|
||||
/* Need to indicate the destination for the operation notification open
|
||||
* button. */
|
||||
nautilus_progress_info_set_destination (((CommonJob *) job)->progress, target_dir);
|
||||
job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
static void
|
||||
copy_task_thread_func (GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
nautilus_file_operations_copy (GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
CopyMoveJob *job;
|
||||
CommonJob *common;
|
||||
|
@ -5668,6 +5700,23 @@ copy_task_thread_func (GTask *task,
|
|||
job = task_data;
|
||||
common = &job->common;
|
||||
|
||||
if (g_strcmp0 (g_getenv ("RUNNING_TESTS"), "TRUE"))
|
||||
{
|
||||
inhibit_power_manager ((CommonJob *) job, _("Copying Files"));
|
||||
}
|
||||
|
||||
if (!nautilus_file_undo_manager_is_operating ())
|
||||
{
|
||||
GFile *src_dir;
|
||||
|
||||
src_dir = g_file_get_parent (job->files->data);
|
||||
job->common.undo_info = nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_COPY,
|
||||
g_list_length (job->files),
|
||||
src_dir, job->destination);
|
||||
|
||||
g_object_unref (src_dir);
|
||||
}
|
||||
|
||||
nautilus_progress_info_start (job->common.progress);
|
||||
|
||||
scan_sources (job->files,
|
||||
|
@ -5746,47 +5795,51 @@ nautilus_file_operations_copy_file (GFile *source_file,
|
|||
|
||||
task = g_task_new (NULL, job->common.cancellable, copy_task_done, job);
|
||||
g_task_set_task_data (task, job, NULL);
|
||||
g_task_run_in_thread (task, copy_task_thread_func);
|
||||
g_task_run_in_thread (task, nautilus_file_operations_copy);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_file_operations_copy (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
nautilus_file_operations_copy_sync (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
{
|
||||
GTask *task;
|
||||
CopyMoveJob *job;
|
||||
|
||||
job = op_job_new (CopyMoveJob, parent_window);
|
||||
job->done_callback = done_callback;
|
||||
job->done_callback_data = done_callback_data;
|
||||
job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
|
||||
job->destination = g_object_ref (target_dir);
|
||||
/* Need to indicate the destination for the operation notification open
|
||||
* button. */
|
||||
nautilus_progress_info_set_destination (((CommonJob *) job)->progress, target_dir);
|
||||
job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
|
||||
|
||||
inhibit_power_manager ((CommonJob *) job, _("Copying Files"));
|
||||
|
||||
if (!nautilus_file_undo_manager_is_operating ())
|
||||
{
|
||||
GFile *src_dir;
|
||||
|
||||
src_dir = g_file_get_parent (files->data);
|
||||
job->common.undo_info = nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_COPY,
|
||||
g_list_length (files),
|
||||
src_dir, target_dir);
|
||||
|
||||
g_object_unref (src_dir);
|
||||
}
|
||||
job = copy_job_setup (files,
|
||||
target_dir,
|
||||
parent_window,
|
||||
done_callback,
|
||||
done_callback_data);
|
||||
|
||||
task = g_task_new (NULL, job->common.cancellable, copy_task_done, job);
|
||||
g_task_set_task_data (task, job, NULL);
|
||||
g_task_run_in_thread (task, copy_task_thread_func);
|
||||
g_task_run_in_thread_sync (task, nautilus_file_operations_copy);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_file_operations_copy_async (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data)
|
||||
{
|
||||
GTask *task;
|
||||
CopyMoveJob *job;
|
||||
|
||||
job = copy_job_setup (files,
|
||||
target_dir,
|
||||
parent_window,
|
||||
done_callback,
|
||||
done_callback_data);
|
||||
|
||||
task = g_task_new (NULL, job->common.cancellable, copy_task_done, job);
|
||||
g_task_set_task_data (task, job, NULL);
|
||||
g_task_run_in_thread (task, nautilus_file_operations_copy);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
|
@ -6773,7 +6826,7 @@ nautilus_file_operations_duplicate (GList *files,
|
|||
|
||||
task = g_task_new (NULL, job->common.cancellable, copy_task_done, job);
|
||||
g_task_set_task_data (task, job, NULL);
|
||||
g_task_run_in_thread (task, copy_task_thread_func);
|
||||
g_task_run_in_thread (task, nautilus_file_operations_copy);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -7048,10 +7101,10 @@ nautilus_file_operations_copy_move (const GList *item_uris,
|
|||
}
|
||||
else
|
||||
{
|
||||
nautilus_file_operations_copy (locations,
|
||||
dest,
|
||||
parent_window,
|
||||
done_callback, done_callback_data);
|
||||
nautilus_file_operations_copy_async (locations,
|
||||
dest,
|
||||
parent_window,
|
||||
done_callback, done_callback_data);
|
||||
}
|
||||
if (src_dir)
|
||||
{
|
||||
|
|
|
@ -118,21 +118,28 @@ void nautilus_file_operations_mount_volume_full (GtkWindow
|
|||
NautilusMountCallback mount_callback,
|
||||
GObject *mount_callback_data_object);
|
||||
|
||||
void nautilus_file_operations_copy (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
void nautilus_file_operations_move_async (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
void nautilus_file_operations_move_sync (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
void nautilus_file_operations_copy_async (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
void nautilus_file_operations_copy_sync (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
|
||||
void nautilus_file_operations_move_async (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
void nautilus_file_operations_move_sync (GList *files,
|
||||
GFile *target_dir,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
gpointer done_callback_data);
|
||||
|
||||
void nautilus_file_operations_duplicate (GList *files,
|
||||
GtkWindow *parent_window,
|
||||
NautilusCopyCallback done_callback,
|
||||
|
|
|
@ -561,11 +561,11 @@ static void
|
|||
ext_copy_redo_func (NautilusFileUndoInfoExt *self,
|
||||
GtkWindow *parent_window)
|
||||
{
|
||||
nautilus_file_operations_copy (g_queue_peek_head_link (self->priv->sources),
|
||||
self->priv->dest_dir,
|
||||
parent_window,
|
||||
file_undo_info_transfer_callback,
|
||||
self);
|
||||
nautilus_file_operations_copy_async (g_queue_peek_head_link (self->priv->sources),
|
||||
self->priv->dest_dir,
|
||||
parent_window,
|
||||
file_undo_info_transfer_callback,
|
||||
self);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -17,6 +17,9 @@ tests = [
|
|||
['test-nautilus-search-engine', [
|
||||
'test-nautilus-search-engine.c'
|
||||
]],
|
||||
['test-file-operations-copy-files', [
|
||||
'test-file-operations-copy-files.c'
|
||||
]]
|
||||
]
|
||||
|
||||
foreach t: tests
|
||||
|
|
779
test/automated/displayless/test-file-operations-copy-files.c
Normal file
779
test/automated/displayless/test-file-operations-copy-files.c
Normal file
|
@ -0,0 +1,779 @@
|
|||
#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_copy_one_file (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) second_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) result_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, "first_dir");
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "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));
|
||||
|
||||
second_dir = g_file_get_child (root, "second_dir");
|
||||
g_assert_true (second_dir != NULL);
|
||||
g_file_make_directory (second_dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
second_dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
result_file = g_file_get_child (second_dir, "first_dir_child");
|
||||
g_assert_true (g_file_query_exists (result_file, NULL));
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
|
||||
g_assert_true (g_file_delete (result_file, NULL, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
g_assert_true (g_file_delete (first_dir, NULL, NULL));
|
||||
g_assert_true (g_file_delete (second_dir, NULL, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
test_copy_one_empty_directory (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) second_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) result_file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "first_dir");
|
||||
g_assert_true (first_dir != NULL);
|
||||
g_file_make_directory (first_dir, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "first_dir_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
files = g_list_prepend (files, g_object_ref (file));
|
||||
|
||||
second_dir = g_file_get_child (root, "second_dir");
|
||||
g_assert_true (second_dir != NULL);
|
||||
g_file_make_directory (second_dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
second_dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
result_file = g_file_get_child (second_dir, "first_dir_child");
|
||||
g_assert_true (g_file_query_exists (result_file, NULL));
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
|
||||
g_assert_true (g_file_delete (result_file, NULL, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
g_assert_true (g_file_delete (first_dir, NULL, NULL));
|
||||
g_assert_true (g_file_delete (second_dir, NULL, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
test_copy_directories_small (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) dir = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
file_name = g_strdup_printf ("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));
|
||||
}
|
||||
|
||||
dir = g_file_get_child (root, "dir");
|
||||
g_assert_true (dir != NULL);
|
||||
g_file_make_directory (dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
file_name = g_strdup_printf ("file_%i", i);
|
||||
file = g_file_get_child (dir, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
}
|
||||
|
||||
g_assert_true (g_file_query_exists (dir, NULL));
|
||||
g_assert_true (g_file_delete (dir, NULL, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
test_copy_directories_medium (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) dir = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
file_name = g_strdup_printf ("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));
|
||||
}
|
||||
|
||||
dir = g_file_get_child (root, "dir");
|
||||
g_assert_true (dir != NULL);
|
||||
g_file_make_directory (dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
file_name = g_strdup_printf ("file_%i", i);
|
||||
file = g_file_get_child (dir, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
}
|
||||
|
||||
g_assert_true (g_file_query_exists (dir, NULL));
|
||||
g_assert_true (g_file_delete (dir, NULL, NULL));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_copy_directories_large (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) dir = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
g_autofree gchar *file_name = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
file_name = g_strdup_printf ("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));
|
||||
}
|
||||
|
||||
dir = g_file_get_child (root, "dir");
|
||||
g_assert_true (dir != NULL);
|
||||
g_file_make_directory (dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
file_name = g_strdup_printf ("file_%i", i);
|
||||
file = g_file_get_child (dir, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
}
|
||||
|
||||
g_assert_true (g_file_query_exists (dir, NULL));
|
||||
g_assert_true (g_file_delete (dir, NULL, NULL));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_copy_files_small (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) dir = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
g_autofree gchar *file_name = NULL;
|
||||
GFileOutputStream *out = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("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));
|
||||
}
|
||||
|
||||
dir = g_file_get_child (root, "dir");
|
||||
g_assert_true (dir != NULL);
|
||||
g_file_make_directory (dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
file_name = g_strdup_printf ("file_%i", i);
|
||||
file = g_file_get_child (dir, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
}
|
||||
|
||||
g_assert_true (g_file_query_exists (dir, NULL));
|
||||
g_assert_true (g_file_delete (dir, NULL, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
test_copy_files_medium (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) dir = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
g_autofree gchar *file_name = NULL;
|
||||
GFileOutputStream *out = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("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));
|
||||
}
|
||||
|
||||
dir = g_file_get_child (root, "dir");
|
||||
g_assert_true (dir != NULL);
|
||||
g_file_make_directory (dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
file_name = g_strdup_printf ("file_%i", i);
|
||||
file = g_file_get_child (dir, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
}
|
||||
|
||||
g_assert_true (g_file_query_exists (dir, NULL));
|
||||
g_assert_true (g_file_delete (dir, NULL, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
test_copy_files_large (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) dir = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
g_autofree gchar *file_name = NULL;
|
||||
GFileOutputStream *out = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
file_name = g_strdup_printf ("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));
|
||||
}
|
||||
|
||||
dir = g_file_get_child (root, "dir");
|
||||
g_assert_true (dir != NULL);
|
||||
g_file_make_directory (dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
file_name = g_strdup_printf ("file_%i", i);
|
||||
file = g_file_get_child (dir, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
file = g_file_get_child (root, file_name);
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
}
|
||||
|
||||
g_assert_true (g_file_query_exists (dir, NULL));
|
||||
g_assert_true (g_file_delete (dir, NULL, NULL));
|
||||
}
|
||||
|
||||
/* The hierarchy looks like this:
|
||||
* /tmp/first_dir/first_dir_child
|
||||
* /tmp/second_dir
|
||||
* We're copying first_dir to second_dir.
|
||||
*/
|
||||
static void
|
||||
test_copy_first_hierarchy (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) second_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) result_file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "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, "first_dir_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
second_dir = g_file_get_child (root, "second_dir");
|
||||
g_assert_true (second_dir != NULL);
|
||||
g_file_make_directory (second_dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
second_dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
result_file = g_file_get_child (second_dir, "first_dir");
|
||||
g_assert_true (g_file_query_exists (result_file, NULL));
|
||||
file = g_file_get_child (result_file, "first_dir_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
g_assert_true (g_file_delete (result_file, NULL, NULL));
|
||||
g_assert_true (g_file_delete (second_dir, NULL, NULL));
|
||||
|
||||
file = g_file_get_child (first_dir, "first_dir_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
g_assert_true (g_file_query_exists (first_dir, NULL));
|
||||
}
|
||||
|
||||
/* The hierarchy looks like this:
|
||||
* /tmp/first_dir/first_child
|
||||
* /tmp/first_dir/second_child
|
||||
* /tmp/second_dir
|
||||
* We're copying first_dir to second_dir.
|
||||
*/
|
||||
static void
|
||||
test_copy_second_hierarchy (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) second_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) result_file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "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, "first_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
file = g_file_get_child (first_dir, "second_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
second_dir = g_file_get_child (root, "second_dir");
|
||||
g_assert_true (second_dir != NULL);
|
||||
g_file_make_directory (second_dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
second_dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
result_file = g_file_get_child (second_dir, "first_dir");
|
||||
g_assert_true (g_file_query_exists (result_file, NULL));
|
||||
file = g_file_get_child (result_file, "first_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
|
||||
file = g_file_get_child (result_file, "second_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
|
||||
g_assert_true (g_file_delete (result_file, NULL, NULL));
|
||||
|
||||
file = g_file_get_child (first_dir, "first_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_file_delete (file, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "second_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_file_delete (file, NULL, NULL);
|
||||
|
||||
g_assert_true (g_file_query_exists (first_dir, NULL));
|
||||
g_file_delete (first_dir, NULL, NULL);
|
||||
g_assert_true (g_file_delete (second_dir, NULL, NULL));
|
||||
}
|
||||
|
||||
/* The hierarchy looks like this:
|
||||
* /tmp/first_dir/first_child/second_child
|
||||
* /tmp/second_dir
|
||||
* We're copying first_dir to second_dir.
|
||||
*/
|
||||
static void
|
||||
test_copy_third_hierarchy (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) second_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) result_file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "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, "first_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
file = g_file_get_child (file, "second_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
second_dir = g_file_get_child (root, "second_dir");
|
||||
g_assert_true (second_dir != NULL);
|
||||
g_file_make_directory (second_dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
second_dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
result_file = g_file_get_child (second_dir, "first_dir");
|
||||
g_assert_true (g_file_query_exists (result_file, NULL));
|
||||
file = g_file_get_child (result_file, "first_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
|
||||
file = g_file_get_child (file, "second_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
|
||||
file = g_file_get_child (result_file, "first_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
|
||||
g_assert_true (g_file_delete (result_file, NULL, NULL));
|
||||
|
||||
file = g_file_get_child (first_dir, "first_child");
|
||||
file = g_file_get_child (file, "second_child");
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
|
||||
file = g_file_get_child (first_dir, "first_child");
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
|
||||
g_assert_true (g_file_delete (first_dir, NULL, NULL));
|
||||
|
||||
g_assert_true (g_file_delete (second_dir, NULL, NULL));
|
||||
}
|
||||
|
||||
/* The hierarchy looks like this:
|
||||
* /tmp/first_dir/first_dir_dir1/dir1_child
|
||||
* /tmp/first_dir/first_dir_dir2/dir2_child
|
||||
* /tmp/second_dir
|
||||
* We're copying first_dir to second_dir.
|
||||
*/
|
||||
static void
|
||||
test_copy_fourth_hierarchy (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) second_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) result_file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "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, "first_dir_dir1");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (file, "dir1_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (first_dir, "first_dir_dir2");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (file, "dir2_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
second_dir = g_file_get_child (root, "second_dir");
|
||||
g_assert_true (second_dir != NULL);
|
||||
g_file_make_directory (second_dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
second_dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
result_file = g_file_get_child (second_dir, "first_dir");
|
||||
|
||||
g_assert_true (g_file_query_exists (result_file, NULL));
|
||||
file = g_file_get_child (result_file, "first_dir_dir1");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
file = g_file_get_child (file, "dir1_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
file = g_file_get_child (result_file, "first_dir_dir1");
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
|
||||
file = g_file_get_child (result_file, "first_dir_dir2");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
file = g_file_get_child (file, "dir2_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
file = g_file_get_child (result_file, "first_dir_dir2");
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
|
||||
g_assert_true (g_file_delete (result_file, NULL, NULL));
|
||||
|
||||
file = g_file_get_child (first_dir, "first_dir_dir1");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
file = g_file_get_child (file, "dir1_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
file = g_file_get_child (first_dir, "first_dir_dir1");
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
|
||||
file = g_file_get_child (first_dir, "first_dir_dir2");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
file = g_file_get_child (file, "dir2_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
file = g_file_get_child (first_dir, "first_dir_dir2");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
|
||||
g_assert_true (g_file_query_exists (first_dir, NULL));
|
||||
g_assert_true (g_file_delete (first_dir, NULL, NULL));
|
||||
|
||||
g_assert_true (g_file_delete (second_dir, NULL, NULL));
|
||||
}
|
||||
|
||||
/* The hierarchy looks like this:
|
||||
* /tmp/first_dir/first_dir_child
|
||||
* /tmp/second_dir/second_dir_child
|
||||
* /tmp/third_dir
|
||||
* We're copying first_dir and second_dir to third_dir.
|
||||
*/
|
||||
static void
|
||||
test_copy_fifth_hierarchy (void)
|
||||
{
|
||||
g_autoptr (GFile) root = NULL;
|
||||
g_autoptr (GFile) first_dir = NULL;
|
||||
g_autoptr (GFile) second_dir = NULL;
|
||||
g_autoptr (GFile) third_dir = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autoptr (GFile) result_file = NULL;
|
||||
g_autolist (GFile) files = NULL;
|
||||
|
||||
root = g_file_new_for_path (g_get_tmp_dir ());
|
||||
first_dir = g_file_get_child (root, "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, "first_dir_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
second_dir = g_file_get_child (root, "second_dir");
|
||||
files = g_list_prepend (files, g_object_ref (second_dir));
|
||||
g_assert_true (second_dir != NULL);
|
||||
g_file_make_directory (second_dir, NULL, NULL);
|
||||
|
||||
file = g_file_get_child (second_dir, "second_dir_child");
|
||||
g_assert_true (file != NULL);
|
||||
g_file_make_directory (file, NULL, NULL);
|
||||
|
||||
third_dir = g_file_get_child (root, "third_dir");
|
||||
g_assert_true (third_dir != NULL);
|
||||
g_file_make_directory (third_dir, NULL, NULL);
|
||||
|
||||
nautilus_file_operations_copy_sync (files,
|
||||
third_dir,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
result_file = g_file_get_child (third_dir, "first_dir");
|
||||
g_assert_true (g_file_query_exists (result_file, NULL));
|
||||
file = g_file_get_child (result_file, "first_dir_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
g_assert_true (g_file_delete (result_file, NULL, NULL));
|
||||
|
||||
result_file = g_file_get_child (third_dir, "second_dir");
|
||||
g_assert_true (g_file_query_exists (result_file, NULL));
|
||||
file = g_file_get_child (result_file, "second_dir_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
g_assert_true (g_file_delete (result_file, NULL, NULL));
|
||||
|
||||
file = g_file_get_child (first_dir, "first_dir_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
g_assert_true (g_file_query_exists (first_dir, NULL));
|
||||
g_assert_true (g_file_delete (first_dir, NULL, NULL));
|
||||
|
||||
file = g_file_get_child (second_dir, "second_dir_child");
|
||||
g_assert_true (g_file_query_exists (file, NULL));
|
||||
g_assert_true (g_file_delete (file, NULL, NULL));
|
||||
g_assert_true (g_file_query_exists (second_dir, NULL));
|
||||
g_assert_true (g_file_delete (second_dir, NULL, NULL));
|
||||
|
||||
g_assert_true (g_file_delete (third_dir, NULL, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
setup_test_suite (void)
|
||||
{
|
||||
g_test_add_func ("/test-copy-one-file/1.0",
|
||||
test_copy_one_file);
|
||||
g_test_add_func ("/test-copy-one-empty-directory/1.0",
|
||||
test_copy_one_empty_directory);
|
||||
g_test_add_func ("/test-copy-files/1.0",
|
||||
test_copy_files_small);
|
||||
g_test_add_func ("/test-copy-files/1.1",
|
||||
test_copy_files_medium);
|
||||
g_test_add_func ("/test-copy-files/1.2",
|
||||
test_copy_files_large);
|
||||
g_test_add_func ("/test-copy-directories/1.0",
|
||||
test_copy_directories_small);
|
||||
g_test_add_func ("/test-copy-directories/1.1",
|
||||
test_copy_directories_medium);
|
||||
g_test_add_func ("/test-copy-directories/1.2",
|
||||
test_copy_directories_large);
|
||||
g_test_add_func ("/test-copy-hierarchy/1.0",
|
||||
test_copy_first_hierarchy);
|
||||
g_test_add_func ("/test-copy-hierarchy/1.1",
|
||||
test_copy_second_hierarchy);
|
||||
g_test_add_func ("/test-copy-hierarchy/1.2",
|
||||
test_copy_third_hierarchy);
|
||||
g_test_add_func ("/test-copy-hierarchy/1.3",
|
||||
test_copy_fourth_hierarchy);
|
||||
g_test_add_func ("/test-copy-hierarchy/1.4",
|
||||
test_copy_fifth_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 ();
|
||||
}
|
|
@ -74,10 +74,10 @@ main (int argc,
|
|||
|
||||
manager = nautilus_progress_info_manager_dup_singleton ();
|
||||
|
||||
nautilus_file_operations_copy (sources,
|
||||
dest,
|
||||
GTK_WINDOW (window),
|
||||
copy_done, NULL);
|
||||
nautilus_file_operations_copy_async (sources,
|
||||
dest,
|
||||
GTK_WINDOW (window),
|
||||
copy_done, NULL);
|
||||
|
||||
infos = nautilus_progress_info_manager_get_all_infos (manager);
|
||||
|
||||
|
|
Loading…
Reference in a new issue