summaryrefslogtreecommitdiffstats
path: root/test/automated/displayless
diff options
context:
space:
mode:
Diffstat (limited to 'test/automated/displayless')
-rw-r--r--test/automated/displayless/meson.build74
-rw-r--r--test/automated/displayless/test-eel-string-get-common-prefix.c190
-rw-r--r--test/automated/displayless/test-file-operations-copy-files.c1316
-rw-r--r--test/automated/displayless/test-file-operations-dir-has-files.c87
-rw-r--r--test/automated/displayless/test-file-operations-move-files.c1947
-rw-r--r--test/automated/displayless/test-file-operations-trash-or-delete.c582
-rw-r--r--test/automated/displayless/test-file-utilities-get-common-filename-prefix.c459
-rw-r--r--test/automated/displayless/test-file-utilities.c240
-rw-r--r--test/automated/displayless/test-nautilus-search-engine-model.c79
-rw-r--r--test/automated/displayless/test-nautilus-search-engine-simple.c74
-rw-r--r--test/automated/displayless/test-nautilus-search-engine-tracker.c185
-rw-r--r--test/automated/displayless/test-nautilus-search-engine.c74
-rw-r--r--test/automated/displayless/test-utilities.c558
-rw-r--r--test/automated/displayless/test-utilities.h34
14 files changed, 5899 insertions, 0 deletions
diff --git a/test/automated/displayless/meson.build b/test/automated/displayless/meson.build
new file mode 100644
index 0000000..64b23bd
--- /dev/null
+++ b/test/automated/displayless/meson.build
@@ -0,0 +1,74 @@
+trackertestutils = dependency('tracker-testutils-3.0')
+
+tracker_sandbox = find_program(trackertestutils.get_pkgconfig_variable('command'))
+
+tests = [
+ ['test-file-utilities-get-common-filename-prefix', [
+ 'test-file-utilities-get-common-filename-prefix.c'
+ ]],
+ ['test-eel-string-get-common-prefix', [
+ 'test-eel-string-get-common-prefix.c'
+ ]],
+ ['test-file-utilities', [
+ 'test-file-utilities.c'
+ ]],
+ ['test-file-operations-dir-has-files', [
+ 'test-file-operations-dir-has-files.c'
+ ]],
+ ['test-file-operations-move-files', [
+ 'test-file-operations-move-files.c'
+ ]],
+ ['test-nautilus-search-engine', [
+ 'test-nautilus-search-engine.c'
+ ]],
+ ['test-nautilus-search-engine-simple', [
+ 'test-nautilus-search-engine-simple.c'
+ ]],
+ ['test-nautilus-search-engine-model', [
+ 'test-nautilus-search-engine-model.c'
+ ]],
+ ['test-file-operations-copy-files', [
+ 'test-file-operations-copy-files.c'
+ ]],
+ ['test-file-operations-trash-or-delete', [
+ 'test-file-operations-trash-or-delete.c'
+ ]]
+]
+
+tracker_tests = [
+ ['test-nautilus-search-engine-tracker', [
+ 'test-nautilus-search-engine-tracker.c',
+ ]],
+]
+
+foreach t: tests
+ test(
+ t[0],
+ executable(t[0], t[1], files('test-utilities.c'), dependencies: libnautilus_dep),
+ env: [
+ test_env,
+ 'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
+ 'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir())
+ ],
+ timeout: 480
+ )
+endforeach
+
+
+
+# Tests that read and write from the Tracker index are run using 'tracker-sandbox'
+# script to use a temporary instance of tracker-miner-fs instead of the session one.
+foreach t: tracker_tests
+ test_exe = executable(t[0], t[1], files('test-utilities.c'), dependencies: libnautilus_dep)
+ test(
+ t[0],
+ tracker_sandbox,
+ args: ['--store-tmpdir', '--index-recursive-tmpdir', test_exe],
+ env: [
+ test_env,
+ 'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
+ 'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir())
+ ],
+ timeout: 480
+ )
+endforeach
diff --git a/test/automated/displayless/test-eel-string-get-common-prefix.c b/test/automated/displayless/test-eel-string-get-common-prefix.c
new file mode 100644
index 0000000..6634c68
--- /dev/null
+++ b/test/automated/displayless/test-eel-string-get-common-prefix.c
@@ -0,0 +1,190 @@
+#include <glib.h>
+#include <glib/gprintf.h>
+
+#include "eel/eel-string.h"
+
+
+static void
+free_list_and_result (GList *list,
+ char *result)
+{
+ g_list_free (list);
+ g_free (result);
+}
+
+static void
+test_has_large_enough_common_prefix (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "foo-1.txt");
+ list = g_list_append (list, "foo-1.tar");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("foo-1.t", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_common_prefix_that_equals_the_min_required_length (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "food");
+ list = g_list_append (list, "foody");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("food", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_common_prefix_that_equals_the_min_required_length2 (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "foody");
+ list = g_list_append (list, "food");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("food", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_many_strings_with_common_prefix (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "some text that matches abcde");
+ list = g_list_append (list, "some text that matches abc22");
+ list = g_list_append (list, "some text that 11");
+ list = g_list_append (list, "some text that matches---");
+ list = g_list_append (list, "some text that matches £$$");
+ list = g_list_append (list, "some text that matches.txt");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("some text that ", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_strings_with_unicode_characters_that_have_common_prefix (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "ƹƱƱƬ");
+ list = g_list_append (list, "ƹƱƱƬƧƥƧ");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("ƹƱƱƬ", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_no_common_prefix (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "fyod");
+ list = g_list_append (list, "completely different string");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_common_prefix_but_smaller_than_min_required_length (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "fyod");
+ list = g_list_append (list, "fyoa");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_first_character_differs (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "tyodaa");
+ list = g_list_append (list, "fyodaa");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_strings_with_unicode_characters_that_dont_have_common_prefix (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "ƹƱƱƬ");
+ list = g_list_append (list, "ƹƱƢƱƬƧƥƧ");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+
+static void
+setup_test_suite (void)
+{
+ g_test_add_func ("/get-common-prefix/1.0",
+ test_has_large_enough_common_prefix);
+ g_test_add_func ("/get-common-prefix/1.1",
+ test_has_common_prefix_that_equals_the_min_required_length);
+ g_test_add_func ("/get-common-prefix/1.2",
+ test_has_common_prefix_that_equals_the_min_required_length2);
+ g_test_add_func ("/get-common-prefix/1.3",
+ test_many_strings_with_common_prefix);
+ g_test_add_func ("/get-common-prefix/1.4",
+ test_strings_with_unicode_characters_that_have_common_prefix);
+
+ g_test_add_func ("/get-common-prefix/2.0",
+ test_no_common_prefix);
+ g_test_add_func ("/get-common-prefix/2.1",
+ test_has_common_prefix_but_smaller_than_min_required_length);
+ g_test_add_func ("/get-common-prefix/2.2",
+ test_first_character_differs);
+ g_test_add_func ("/get-common-prefix/2.3",
+ test_strings_with_unicode_characters_that_dont_have_common_prefix);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=747907");
+ g_test_set_nonfatal_assertions ();
+
+ setup_test_suite ();
+
+ return g_test_run ();
+}
diff --git a/test/automated/displayless/test-file-operations-copy-files.c b/test/automated/displayless/test-file-operations-copy-files.c
new file mode 100644
index 0000000..1a7d802
--- /dev/null
+++ b/test/automated/displayless/test-file-operations-copy-files.c
@@ -0,0 +1,1316 @@
+#include "test-utilities.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;
+
+ create_one_file ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir_child");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_one_file_undo (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;
+
+ create_one_file ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir_child");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+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;
+
+ create_one_empty_directory ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir_child");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_one_empty_directory_undo (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;
+
+ create_one_empty_directory ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir_child");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+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;
+ gchar *file_name;
+
+ create_multiple_files ("copy", 10);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_files_small_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("copy", 10);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+
+ test_operation_undo ();
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+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;
+ gchar *file_name;
+
+ create_multiple_files ("copy", 1000);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 1000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+
+ for (int i = 0; i < 1000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_files_medium_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("copy", 1000);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 1000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+ test_operation_undo ();
+
+ for (int i = 0; i < 1000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+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;
+ gchar *file_name;
+
+ create_multiple_files ("copy", 10000);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+
+ for (int i = 0; i < 10000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_files_large_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("copy", 10000);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+
+ test_operation_undo ();
+
+ for (int i = 0; i < 10000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+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;
+ gchar *file_name;
+
+ create_multiple_directories ("copy", 10);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_directories_small_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_directories ("copy", 10);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+
+ test_operation_undo ();
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+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;
+ gchar *file_name;
+
+ create_multiple_directories ("copy", 1000);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 1000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+
+ for (int i = 0; i < 1000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_directories_medium_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_directories ("copy", 1000);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 1000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+
+ test_operation_undo ();
+
+ for (int i = 0; i < 1000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+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;
+ gchar *file_name;
+
+ create_multiple_directories ("copy", 10000);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+
+ for (int i = 0; i < 10000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_directories_large_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_directories ("copy", 10000);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_assert_true (file != NULL);
+ g_free (file_name);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "copy_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ dir);
+
+ test_operation_undo ();
+
+ for (int i = 0; i < 10000; i++)
+ {
+ file_name = g_strdup_printf ("copy_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, 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_full_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;
+
+ create_one_file ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_full_directory_undo (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;
+
+ create_one_file ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_first_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+/* 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_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;
+
+ create_first_hierarchy ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_child");
+ g_assert_true (file != NULL);
+ file = g_file_get_child (first_dir, "copy_second_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (result_file, "copy_second_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "copy_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "copy_second_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_first_hierarchy_undo (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;
+
+ create_first_hierarchy ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_child");
+ g_assert_true (file != NULL);
+ file = g_file_get_child (first_dir, "copy_second_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_first_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (result_file, "copy_second_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "copy_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "copy_second_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+/* 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_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;
+
+ create_second_hierarchy ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_child");
+ g_assert_true (file != NULL);
+ file = g_file_get_child (file, "copy_second_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (file, "copy_second_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (result_file, "copy_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "copy_first_child");
+ file = g_file_get_child (file, "copy_second_child");
+
+ file = g_file_get_child (first_dir, "copy_first_child");
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_second_hierarchy_undo (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;
+
+ create_second_hierarchy ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_child");
+ g_assert_true (file != NULL);
+ file = g_file_get_child (file, "copy_second_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_first_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (file, "copy_second_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (result_file, "copy_first_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "copy_first_child");
+ file = g_file_get_child (file, "copy_second_child");
+
+ file = g_file_get_child (first_dir, "copy_first_child");
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+/* 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_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;
+
+ create_third_hierarchy ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_dir1");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (file, "copy_dir1_child");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_dir2");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (file, "copy_dir2_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir");
+
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_first_dir_dir1");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "copy_dir1_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (result_file, "copy_first_dir_dir1");
+
+ file = g_file_get_child (result_file, "copy_first_dir_dir2");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "copy_dir2_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (result_file, "copy_first_dir_dir2");
+
+ file = g_file_get_child (first_dir, "copy_first_dir_dir1");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "copy_dir1_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (first_dir, "copy_first_dir_dir1");
+
+ file = g_file_get_child (first_dir, "copy_first_dir_dir2");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "copy_dir2_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (first_dir, "copy_first_dir_dir2");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_third_hierarchy_undo (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;
+
+ create_third_hierarchy ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_dir1");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (file, "copy_dir1_child");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_dir2");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (file, "copy_dir2_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "copy_first_dir");
+
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_first_dir_dir1");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "copy_dir1_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (result_file, "copy_first_dir_dir2");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "copy_dir2_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "copy_first_dir_dir1");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "copy_dir1_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (first_dir, "copy_first_dir_dir1");
+
+ file = g_file_get_child (first_dir, "copy_first_dir_dir2");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "copy_dir2_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (first_dir, "copy_first_dir_dir2");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+/* 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_fourth_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;
+
+ create_fourth_hierarchy ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ files = g_list_prepend (files, g_object_ref (second_dir));
+ g_assert_true (second_dir != NULL);
+
+ file = g_file_get_child (second_dir, "copy_second_dir_child");
+ g_assert_true (file != NULL);
+
+ third_dir = g_file_get_child (root, "copy_third_dir");
+ g_assert_true (third_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ third_dir);
+
+ result_file = g_file_get_child (third_dir, "copy_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ result_file = g_file_get_child (third_dir, "copy_second_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_second_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ file = g_file_get_child (second_dir, "copy_second_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ g_assert_true (g_file_query_exists (second_dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+static void
+test_copy_fourth_hierarchy_undo (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;
+
+ create_fourth_hierarchy ("copy");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "copy_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "copy_second_dir");
+ files = g_list_prepend (files, g_object_ref (second_dir));
+ g_assert_true (second_dir != NULL);
+
+ file = g_file_get_child (second_dir, "copy_second_dir_child");
+ g_assert_true (file != NULL);
+
+ third_dir = g_file_get_child (root, "copy_third_dir");
+ g_assert_true (third_dir != NULL);
+
+ nautilus_file_operations_copy_sync (files,
+ third_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (third_dir, "copy_first_dir");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_first_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ result_file = g_file_get_child (third_dir, "copy_second_dir");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "copy_second_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "copy_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ file = g_file_get_child (second_dir, "copy_second_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ g_assert_true (g_file_query_exists (second_dir, NULL));
+
+ empty_directory_by_prefix (root, "copy");
+}
+
+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-file-undo/1.0",
+ test_copy_one_file_undo);
+ g_test_add_func ("/test-copy-one-empty-directory/1.0",
+ test_copy_one_empty_directory);
+ g_test_add_func ("/test-copy-one-empty-directory-undo/1.0",
+ test_copy_one_empty_directory_undo);
+ g_test_add_func ("/test-copy-files/1.0",
+ test_copy_files_small);
+ g_test_add_func ("/test-copy-files-undo/1.0",
+ test_copy_files_small_undo);
+ g_test_add_func ("/test-copy-files/1.1",
+ test_copy_files_medium);
+ g_test_add_func ("/test-copy-files-undo/1.1",
+ test_copy_files_medium_undo);
+ g_test_add_func ("/test-copy-files/1.2",
+ test_copy_files_large);
+ g_test_add_func ("/test-copy-files-undo/1.2",
+ test_copy_files_large_undo);
+ g_test_add_func ("/test-copy-directories/1.0",
+ test_copy_directories_small);
+ g_test_add_func ("/test-copy-directories-undo/1.0",
+ test_copy_directories_small_undo);
+ g_test_add_func ("/test-copy-directories/1.1",
+ test_copy_directories_medium);
+ g_test_add_func ("/test-copy-directories-undo/1.1",
+ test_copy_directories_medium_undo);
+ g_test_add_func ("/test-copy-directories/1.2",
+ test_copy_directories_large);
+ g_test_add_func ("/test-copy-directories-undo/1.2",
+ test_copy_directories_large_undo);
+ g_test_add_func ("/test-copy-hierarchy/1.0",
+ test_copy_full_directory);
+ g_test_add_func ("/test-copy-hierarchy-undo/1.0",
+ test_copy_full_directory_undo);
+ g_test_add_func ("/test-copy-hierarchy/1.1",
+ test_copy_first_hierarchy);
+ g_test_add_func ("/test-copy-hierarchy-undo/1.1",
+ test_copy_first_hierarchy_undo);
+ g_test_add_func ("/test-copy-hierarchy/1.2",
+ test_copy_second_hierarchy);
+ g_test_add_func ("/test-copy-hierarchy-undo/1.2",
+ test_copy_second_hierarchy_undo);
+ g_test_add_func ("/test-copy-hierarchy/1.3",
+ test_copy_third_hierarchy);
+ g_test_add_func ("/test-copy-hierarchy-undo/1.3",
+ test_copy_third_hierarchy_undo);
+ g_test_add_func ("/test-copy-hierarchy/1.4",
+ test_copy_fourth_hierarchy);
+ g_test_add_func ("/test-copy-hierarchy-undo/1.4",
+ test_copy_fourth_hierarchy_undo);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_autoptr (NautilusFileUndoManager) undo_manager = NULL;
+
+ undo_manager = nautilus_file_undo_manager_new ();
+ g_test_init (&argc, &argv, NULL);
+ g_test_set_nonfatal_assertions ();
+ nautilus_ensure_extension_points ();
+
+ setup_test_suite ();
+
+ return g_test_run ();
+}
diff --git a/test/automated/displayless/test-file-operations-dir-has-files.c b/test/automated/displayless/test-file-operations-dir-has-files.c
new file mode 100644
index 0000000..06c7df2
--- /dev/null
+++ b/test/automated/displayless/test-file-operations-dir-has-files.c
@@ -0,0 +1,87 @@
+#include <glib.h>
+#include <glib/gprintf.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"
+
+/* Tests the function for a simple file */
+static void
+test_simple_file (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ file = g_file_get_child (root, "simple_file");
+ g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL);
+ g_assert_false (dir_has_files (file));
+ g_assert_true (g_file_delete (file, NULL, NULL));
+}
+
+/* Tests the function for an empty directory */
+static void
+test_empty_directory (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) child = NULL;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ child = g_file_get_child (root, "empty_dir");
+
+ g_assert_true (child != NULL);
+
+ g_file_make_directory (child, NULL, NULL);
+
+ g_assert_false (dir_has_files (child));
+ g_assert_true (g_file_delete (child, NULL, NULL));
+}
+
+/* Tests the function for a directory containing one directory */
+static void
+test_directory_one_file (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) parent_dir = NULL;
+ g_autoptr (GFile) child_file = NULL;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ parent_dir = g_file_get_child (root, "parent_dir");
+ g_assert_true (parent_dir != NULL);
+ g_file_make_directory (parent_dir, NULL, NULL);
+
+ child_file = g_file_get_child (parent_dir, "child_file");
+ g_assert_true (child_file != NULL);
+ g_file_make_directory (child_file, NULL, NULL);
+
+ g_assert_true (dir_has_files (parent_dir));
+ g_assert_true (g_file_delete (child_file, NULL, NULL));
+ g_assert_true (g_file_delete (parent_dir, NULL, NULL));
+}
+
+static void
+setup_test_suite (void)
+{
+ g_test_add_func ("/dir-has-files-simple-file/1.0",
+ test_simple_file);
+ g_test_add_func ("/dir-has-files-empty-dir/1.0",
+ test_empty_directory);
+ g_test_add_func ("/dir-has-files-directroy-one-file/1.0",
+ test_directory_one_file);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_set_nonfatal_assertions ();
+ nautilus_ensure_extension_points ();
+
+ setup_test_suite ();
+
+ return g_test_run ();
+}
diff --git a/test/automated/displayless/test-file-operations-move-files.c b/test/automated/displayless/test-file-operations-move-files.c
new file mode 100644
index 0000000..5ad8ccb
--- /dev/null
+++ b/test/automated/displayless/test-file-operations-move-files.c
@@ -0,0 +1,1947 @@
+#include "test-utilities.h"
+
+static void
+test_move_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;
+
+ create_one_file ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "move_first_dir_child");
+
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_one_file_undo (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;
+
+ create_one_file ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir_child");
+
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_one_file_undo_redo (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;
+
+ create_one_file ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo_redo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir_child");
+
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_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;
+
+ create_one_empty_directory ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "move_first_dir_child");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_one_empty_directory_undo (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;
+
+ create_one_empty_directory ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir_child");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_one_empty_directory_undo_redo (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;
+
+ create_one_empty_directory ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo_redo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir_child");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_files_small (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("move", 10);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_files_small_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("move", 10);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo ();
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_files_small_undo_redo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("move", 10);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo_redo ();
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_files_medium (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("move", 50);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_files_medium_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("move", 50);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo ();
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_files_medium_undo_redo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("move", 50);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo_redo ();
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_files_large (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("move", 500);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo ();
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_files_large_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("move", 500);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+ test_operation_undo_redo ();
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_files_large_undo_redo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("move", 500);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo_redo ();
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_directories_small (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_directories ("move", 10);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_directories_small_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_directories ("move", 10);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo ();
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_directories_small_undo_redo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("move", 10);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo_redo ();
+
+ for (int i = 0; i < 10; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_directories_medium (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_directories ("move", 50);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_directories_medium_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_directories ("move", 50);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo ();
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_directories_medium_undo_redo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_files ("move", 50);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo_redo ();
+
+ for (int i = 0; i < 50; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_directories_large (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_directories ("move", 500);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_directories_large_undo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_directories ("move", 500);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo ();
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_directories_large_undo_redo (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ g_autolist (GFile) files = NULL;
+ gchar *file_name;
+
+ create_multiple_directories ("move", 500);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ dir = g_file_get_child (root, "move_dir");
+ g_assert_true (dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ dir);
+
+ test_operation_undo_redo ();
+
+ for (int i = 0; i < 500; i++)
+ {
+ file_name = g_strdup_printf ("move_file_%i", i);
+ file = g_file_get_child (dir, file_name);
+ g_free (file_name);
+ g_assert_true (g_file_query_exists (file, NULL));
+ }
+
+ g_assert_true (g_file_query_exists (dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+/* The hierarchy looks like this:
+ * /tmp/first_dir/first_dir_child
+ * /tmp/second_dir
+ * We're moving first_dir to second_dir.
+ */
+static void
+test_move_full_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;
+
+ create_one_file ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_full_directory_undo (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;
+
+ create_one_file ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_full_directory_undo_redo (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;
+
+ create_one_file ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo_redo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+/* The hierarchy looks like this:
+ * /tmp/first_dir/first_child
+ * /tmp/first_dir/second_child
+ * /tmp/second_dir
+ * We're moving first_dir to second_dir.
+ */
+static void
+test_move_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;
+
+ create_first_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ g_assert_true (file != NULL);
+ file = g_file_get_child (first_dir, "move_second_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (result_file, "move_second_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_second_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_first_hierarchy_undo (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;
+
+ create_first_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ g_assert_true (file != NULL);
+ file = g_file_get_child (first_dir, "move_second_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (result_file, "move_second_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_second_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_first_hierarchy_undo_redo (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;
+
+ create_first_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ g_assert_true (file != NULL);
+ file = g_file_get_child (first_dir, "move_second_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo_redo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (result_file, "move_second_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_second_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+/* The hierarchy looks like this:
+ * /tmp/first_dir/first_child/second_child
+ * /tmp/second_dir
+ * We're moving first_dir to second_dir.
+ */
+static void
+test_move_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;
+
+ create_second_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ g_assert_true (file != NULL);
+ file = g_file_get_child (file, "move_second_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (file, "move_second_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (result_file, "move_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_second_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_second_hierarchy_undo (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;
+
+ create_second_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ g_assert_true (file != NULL);
+ file = g_file_get_child (file, "move_second_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (file, "move_second_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ file = g_file_get_child (file, "move_second_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_second_hierarchy_undo_redo (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;
+
+ create_second_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_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, "move_first_child");
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+ file = g_file_get_child (file, "move_second_child");
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+ g_file_make_directory (second_dir, NULL, NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo_redo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (file, "move_second_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (result_file, "move_first_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_second_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+/* 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 moving first_dir to second_dir.
+ */
+static void
+test_move_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;
+
+ create_third_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir1");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (file, "move_dir1_child");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir2");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (file, "move_dir2_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_dir_dir1");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir1_child");
+ file = g_file_get_child (result_file, "move_first_dir_dir1");
+
+ file = g_file_get_child (result_file, "move_first_dir_dir2");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir2_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (result_file, "move_first_dir_dir2");
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir1");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir1_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (first_dir, "move_first_dir_dir1");
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir2");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir2_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (first_dir, "move_first_dir_dir2");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_third_hierarchy_undo (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;
+
+ create_third_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir1");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (file, "move_dir1_child");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir2");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (file, "move_dir2_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_dir_dir1");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir1_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (result_file, "move_first_dir_dir2");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir2_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir1");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir1_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (first_dir, "move_first_dir_dir1");
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir2");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir2_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (first_dir, "move_first_dir_dir2");
+
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ g_assert_true (g_file_delete (second_dir, NULL, NULL));
+}
+
+static void
+test_move_third_hierarchy_undo_redo (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;
+
+ create_third_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir1");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (file, "move_dir1_child");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir2");
+ g_assert_true (file != NULL);
+
+ file = g_file_get_child (file, "move_dir2_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ g_assert_true (second_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ second_dir);
+
+ test_operation_undo_redo ();
+
+ result_file = g_file_get_child (second_dir, "move_first_dir");
+
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_dir_dir1");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir1_child");
+ file = g_file_get_child (result_file, "move_first_dir_dir1");
+
+ file = g_file_get_child (result_file, "move_first_dir_dir2");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir2_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ file = g_file_get_child (result_file, "move_first_dir_dir2");
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir1");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir1_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (first_dir, "move_first_dir_dir1");
+
+ file = g_file_get_child (first_dir, "move_first_dir_dir2");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (file, "move_dir2_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ file = g_file_get_child (first_dir, "move_first_dir_dir2");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+/* The hierarchy looks like this:
+ * /tmp/first_dir/first_dir_child
+ * /tmp/second_dir/second_dir_child
+ * /tmp/third_dir
+ * We're moving first_dir and second_dir to third_dir.
+ */
+static void
+test_move_fourth_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;
+
+ create_fourth_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ files = g_list_prepend (files, g_object_ref (second_dir));
+ g_assert_true (second_dir != NULL);
+
+ file = g_file_get_child (second_dir, "move_second_dir_child");
+ g_assert_true (file != NULL);
+
+ third_dir = g_file_get_child (root, "move_third_dir");
+ g_assert_true (third_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ third_dir);
+
+ result_file = g_file_get_child (third_dir, "move_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ result_file = g_file_get_child (third_dir, "move_second_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_second_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+
+ file = g_file_get_child (second_dir, "move_second_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ g_assert_false (g_file_query_exists (second_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_fourth_hierarchy_undo (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;
+
+ create_fourth_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ files = g_list_prepend (files, g_object_ref (second_dir));
+ g_assert_true (second_dir != NULL);
+
+ file = g_file_get_child (second_dir, "move_second_dir_child");
+ g_assert_true (file != NULL);
+
+ third_dir = g_file_get_child (root, "move_third_dir");
+ g_assert_true (third_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ third_dir);
+
+ test_operation_undo ();
+
+ result_file = g_file_get_child (third_dir, "move_first_dir");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ result_file = g_file_get_child (third_dir, "move_second_dir");
+ g_assert_false (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_second_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ g_assert_true (g_file_query_exists (first_dir, NULL));
+
+ file = g_file_get_child (second_dir, "move_second_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+ g_assert_true (g_file_query_exists (second_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+test_move_fourth_hierarchy_undo_redo (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;
+
+ create_fourth_hierarchy ("move");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ first_dir = g_file_get_child (root, "move_first_dir");
+ files = g_list_prepend (files, g_object_ref (first_dir));
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_true (file != NULL);
+
+ second_dir = g_file_get_child (root, "move_second_dir");
+ files = g_list_prepend (files, g_object_ref (second_dir));
+ g_assert_true (second_dir != NULL);
+
+ file = g_file_get_child (second_dir, "move_second_dir_child");
+ g_assert_true (file != NULL);
+
+ third_dir = g_file_get_child (root, "move_third_dir");
+ g_assert_true (third_dir != NULL);
+
+ nautilus_file_operations_move_sync (files,
+ third_dir);
+
+ test_operation_undo_redo ();
+
+ result_file = g_file_get_child (third_dir, "move_first_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_first_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ result_file = g_file_get_child (third_dir, "move_second_dir");
+ g_assert_true (g_file_query_exists (result_file, NULL));
+ file = g_file_get_child (result_file, "move_second_dir_child");
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ file = g_file_get_child (first_dir, "move_first_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+
+ file = g_file_get_child (second_dir, "move_second_dir_child");
+ g_assert_false (g_file_query_exists (file, NULL));
+ g_assert_false (g_file_query_exists (second_dir, NULL));
+
+ empty_directory_by_prefix (root, "move");
+}
+
+static void
+setup_test_suite (void)
+{
+ g_test_add_func ("/test-move-one-file/1.0",
+ test_move_one_file);
+ g_test_add_func ("/test-move-one-file-undo/1.0",
+ test_move_one_file_undo);
+ g_test_add_func ("/test-move-one-file-undo-redo/1.0",
+ test_move_one_file_undo_redo);
+ g_test_add_func ("/test-move-one-empty-directory/1.0",
+ test_move_one_empty_directory);
+ g_test_add_func ("/test-move-one-empty-directory-undo/1.0",
+ test_move_one_empty_directory_undo);
+ g_test_add_func ("/test-move-one-empty-directory-undo-redo/1.0",
+ test_move_one_empty_directory_undo_redo);
+ g_test_add_func ("/test-move-files/1.0",
+ test_move_files_small);
+ g_test_add_func ("/test-move-files-undo/1.0",
+ test_move_files_small_undo);
+ g_test_add_func ("/test-move-files-undo-redo/1.0",
+ test_move_files_small_undo_redo);
+ g_test_add_func ("/test-move-files/1.1",
+ test_move_files_medium);
+ g_test_add_func ("/test-move-files-undo/1.1",
+ test_move_files_medium_undo);
+ g_test_add_func ("/test-move-files-undo-redo/1.1",
+ test_move_files_medium_undo_redo);
+ g_test_add_func ("/test-move-files/1.2",
+ test_move_files_large);
+ g_test_add_func ("/test-move-files-undo/1.2",
+ test_move_files_large_undo);
+ g_test_add_func ("/test-move-files-undo-redo/1.2",
+ test_move_files_large_undo_redo);
+ g_test_add_func ("/test-move-directories/1.0",
+ test_move_directories_small);
+ g_test_add_func ("/test-move-directories-undo/1.0",
+ test_move_directories_small_undo);
+ g_test_add_func ("/test-move-directories-undo-redo/1.0",
+ test_move_directories_small_undo_redo);
+ g_test_add_func ("/test-move-directories/1.1",
+ test_move_directories_medium);
+ g_test_add_func ("/test-move-directories-undo/1.1",
+ test_move_directories_medium_undo);
+ g_test_add_func ("/test-move-directories-undo-redo/1.1",
+ test_move_directories_medium_undo_redo);
+ g_test_add_func ("/test-move-directories/1.2",
+ test_move_directories_large);
+ g_test_add_func ("/test-move-directories-undo/1.2",
+ test_move_directories_large_undo);
+ g_test_add_func ("/test-move-directories-undo-redo/1.2",
+ test_move_directories_large_undo_redo);
+ g_test_add_func ("/test-move-hierarchy/1.0",
+ test_move_full_directory);
+ g_test_add_func ("/test-move-hierarchy-undo/1.0",
+ test_move_full_directory_undo);
+ g_test_add_func ("/test-move-hierarchy-undo-redo/1.0",
+ test_move_full_directory_undo_redo);
+ g_test_add_func ("/test-move-hierarchy/1.1",
+ test_move_first_hierarchy);
+ g_test_add_func ("/test-move-hierarchy-undo/1.1",
+ test_move_first_hierarchy_undo);
+ g_test_add_func ("/test-move-hierarchy-undo-redo/1.1",
+ test_move_first_hierarchy_undo_redo);
+ g_test_add_func ("/test-move-hierarchy/1.2",
+ test_move_second_hierarchy);
+ g_test_add_func ("/test-move-hierarchy-undo/1.2",
+ test_move_second_hierarchy_undo);
+ g_test_add_func ("/test-move-hierarchy-undo-redo/1.2",
+ test_move_second_hierarchy_undo_redo);
+ g_test_add_func ("/test-move-hierarchy/1.3",
+ test_move_third_hierarchy);
+ g_test_add_func ("/test-move-hierarchy-undo/1.3",
+ test_move_third_hierarchy_undo);
+ g_test_add_func ("/test-move-hierarchy-undo-redo/1.3",
+ test_move_third_hierarchy_undo_redo);
+ g_test_add_func ("/test-move-hierarchy/1.4",
+ test_move_fourth_hierarchy);
+ g_test_add_func ("/test-move-hierarchy-undo/1.4",
+ test_move_fourth_hierarchy_undo);
+ g_test_add_func ("/test-move-hierarchy-undo-redo/1.4",
+ test_move_fourth_hierarchy_undo_redo);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_autoptr (NautilusFileUndoManager) undo_manager = NULL;
+
+ undo_manager = nautilus_file_undo_manager_new ();
+ g_test_init (&argc, &argv, NULL);
+ g_test_set_nonfatal_assertions ();
+ nautilus_ensure_extension_points ();
+
+ setup_test_suite ();
+
+ return g_test_run ();
+}
diff --git a/test/automated/displayless/test-file-operations-trash-or-delete.c b/test/automated/displayless/test-file-operations-trash-or-delete.c
new file mode 100644
index 0000000..b1f4109
--- /dev/null
+++ b/test/automated/displayless/test-file-operations-trash-or-delete.c
@@ -0,0 +1,582 @@
+#include "test-utilities.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;
+
+ create_one_file ("trash_or_delete");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ nautilus_file_operations_trash_or_delete_sync (files);
+
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+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;
+
+ create_multiple_files ("trash_or_delete", files_to_trash);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < files_to_trash; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ nautilus_file_operations_trash_or_delete_sync (files);
+
+ for (int i = 0; i < files_to_trash; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ }
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+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;
+
+ create_one_file ("trash_or_delete");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+
+ nautilus_file_operations_delete_sync (files);
+
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+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;
+
+ create_multiple_files ("trash_or_delete", files_to_delete);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < files_to_delete; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ nautilus_file_operations_delete_sync (files);
+
+ for (int i = 0; i < files_to_delete; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ }
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+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_autoptr (GFile) file = NULL;
+ g_autolist (GFile) files = NULL;
+
+ create_one_empty_directory ("trash_or_delete");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
+ g_assert_true (file != NULL);
+
+ files = g_list_prepend (files, g_object_ref (file));
+
+ nautilus_file_operations_trash_or_delete_sync (files);
+
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+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;
+
+ create_multiple_directories ("trash_or_delete", directories_to_trash);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < directories_to_trash; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ nautilus_file_operations_trash_or_delete_sync (files);
+
+ for (int i = 0; i < directories_to_trash; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ g_assert_false (g_file_query_exists (file, NULL));
+ }
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+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_autoptr (GFile) file = NULL;
+ g_autolist (GFile) files = NULL;
+
+ create_one_empty_directory ("trash_or_delete");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
+ g_assert_true (first_dir != NULL);
+ file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
+ g_assert_true (file != NULL);
+
+ files = g_list_prepend (files, g_object_ref (file));
+
+ nautilus_file_operations_delete_sync (files);
+
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+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;
+
+ create_multiple_directories ("trash_or_delete", directories_to_delete);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < directories_to_delete; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ nautilus_file_operations_delete_sync (files);
+
+
+ for (int i = 0; i < directories_to_delete; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_file_%i", i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+ g_assert_true (file != NULL);
+ g_assert_false (g_file_query_exists (file, NULL));
+ }
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+static void
+test_delete_more_empty_directories (void)
+{
+ test_delete_more_empty_directories_func (100);
+}
+
+/* The hierarchy looks like this:
+ * /tmp/first_dir/first_dir_child
+ * We're trashing first_dir.
+ */
+static void
+test_trash_full_directory (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) first_dir = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autolist (GFile) files = NULL;
+
+ create_one_file ("trash_or_delete");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
+ g_assert_true (file != NULL);
+
+ files = g_list_prepend (files, g_object_ref (first_dir));
+
+ nautilus_file_operations_trash_or_delete_sync (files);
+
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+/* The hierarchy looks like this:
+ * /tmp/first_dir/first_child
+ * /tmp/first_dir/second_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;
+
+ create_first_hierarchy ("trash_or_delete");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ 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);
+
+ file = g_file_get_child (first_dir, "trash_or_delete_first_child");
+ g_assert_true (file != NULL);
+ file = g_file_get_child (first_dir, "trash_or_delete_second_child");
+ g_assert_true (file != NULL);
+
+ nautilus_file_operations_trash_or_delete_sync (files);
+
+ 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));
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+/* 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;
+
+ create_multiple_full_directories ("trash_or_delete", 50);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 50; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_directory_%i", i);
+
+ directory = g_file_get_child (root, file_name);
+ g_free (file_name);
+ files = g_list_prepend (files, g_object_ref (directory));
+ }
+
+ nautilus_file_operations_trash_or_delete_sync (files);
+
+ for (int i = 0; i < 50; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_directory_%i", i);
+
+ directory = g_file_get_child (root, file_name);
+ g_free (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_free (file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ }
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+/* The hierarchy looks like this:
+ * /tmp/first_dir/first_dir_child
+ * We're deleting first_dir.
+ */
+static void
+test_delete_full_directory (void)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) first_dir = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autolist (GFile) files = NULL;
+
+ create_one_file ("trash_or_delete");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ first_dir = g_file_get_child (root, "trash_or_delete_first_dir");
+ g_assert_true (first_dir != NULL);
+
+ file = g_file_get_child (first_dir, "trash_or_delete_first_dir_child");
+ g_assert_true (file != NULL);
+
+ files = g_list_prepend (files, g_object_ref (first_dir));
+
+ nautilus_file_operations_delete_sync (files);
+
+ g_assert_false (g_file_query_exists (first_dir, NULL));
+ g_assert_false (g_file_query_exists (file, NULL));
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+/* The hierarchy looks like this:
+ * /tmp/first_dir/first_child
+ * /tmp/first_dir/second_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;
+
+ create_first_hierarchy ("trash_or_delete");
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ 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);
+
+ file = g_file_get_child (first_dir, "trash_or_delete_first_child");
+ g_assert_true (file != NULL);
+ file = g_file_get_child (first_dir, "trash_or_delete_second_child");
+ g_assert_true (file != NULL);
+
+ nautilus_file_operations_delete_sync (files);
+
+ 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));
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+/* 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;
+
+ create_multiple_full_directories ("trash_or_delete", 50);
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < 50; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_directory_%i", i);
+
+ directory = g_file_get_child (root, file_name);
+ g_free (file_name);
+ files = g_list_prepend (files, g_object_ref (directory));
+ }
+
+ nautilus_file_operations_delete_sync (files);
+
+ for (int i = 0; i < 50; i++)
+ {
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("trash_or_delete_directory_%i", i);
+
+ directory = g_file_get_child (root, file_name);
+ g_free (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_free (file_name);
+ g_assert_false (g_file_query_exists (file, NULL));
+ }
+
+ empty_directory_by_prefix (root, "trash_or_delete");
+}
+
+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_full_directory);
+ g_test_add_func ("/test-trash-one-full-directory/1.1",
+ test_trash_first_hierarchy);
+ g_test_add_func ("/test-trash-more-full-directories/1.2",
+ test_trash_third_hierarchy);
+ g_test_add_func ("/test-delete-one-full-directory/1.0",
+ test_delete_full_directory);
+ g_test_add_func ("/test-delete-one-full-directory/1.1",
+ test_delete_first_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 ();
+}
diff --git a/test/automated/displayless/test-file-utilities-get-common-filename-prefix.c b/test/automated/displayless/test-file-utilities-get-common-filename-prefix.c
new file mode 100644
index 0000000..4c044a0
--- /dev/null
+++ b/test/automated/displayless/test-file-utilities-get-common-filename-prefix.c
@@ -0,0 +1,459 @@
+#include <glib.h>
+#include <glib/gprintf.h>
+
+#include "src/nautilus-file-utilities.h"
+
+
+static void
+free_list_and_result (GList *list,
+ char *result)
+{
+ g_list_free (list);
+ g_free (result);
+}
+
+static void
+test_has_large_enough_common_prefix (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "test");
+ list = g_list_append (list, "tests");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("test", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_large_enough_common_prefix_with_spaces_in_middle (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "Cpt J Yossarian r1");
+ list = g_list_append (list, "Cpt J Yossarian a1");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("Cpt J Yossarian", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_large_enough_common_prefix_with_punctuation_in_middle (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "Cpt-J_Yossarian r1");
+ list = g_list_append (list, "Cpt-J_Yossarian a1");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("Cpt-J_Yossarian", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_large_enough_common_prefix_with_punctuation_in_middle_and_extension (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "Cpt-J, Yossarian.xml");
+ list = g_list_append (list, "Cpt-J, Yossarian.xsl");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("Cpt-J, Yossarian", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_doesnt_have_large_enough_common_prefix (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "foo");
+ list = g_list_append (list, "foob");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_doesnt_have_large_enough_common_prefix_completely_different_strings (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "this string really");
+ list = g_list_append (list, "isn't the same as the other");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_doesnt_have_large_enough_common_prefix_first_character_differs (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "foo");
+ list = g_list_append (list, "roo");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_doesnt_have_large_enough_common_prefix_first_character_differs_longer_string (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "fools");
+ list = g_list_append (list, "rools");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_large_enough_common_prefix_until_extension_removed (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "tes.txt");
+ list = g_list_append (list, "tes.tar");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_extension_is_removed (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "nau tilus.c");
+ list = g_list_append (list, "nau tilus.cpp");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nau tilus", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_whitespace_is_removed (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "nautilus ");
+ list = g_list_append (list, "nautilus two");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_whitespace_and_extension_are_removed (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "nautilus !£ $\" foo.tar.gz");
+ list = g_list_append (list, "nautilus !£ $\" .lzma");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus !£ $\"", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_punctuation_is_preserved (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "nautilus (2018!£$%^&* ()_+-={}[ ];':@#~<>?,./\".mp4");
+ list = g_list_append (list, "nautilus (2018!£$%^&* ()_+-={}[ ];':@#~<>?,./\".srt");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus (2018!£$%^&* ()_+-={}[ ];':@#~<>?,./\"", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_unicode_on_outside (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "ӶtestӶ234");
+ list = g_list_append (list, "ӶtestӶ1");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("ӶtestӶ", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_unicode_on_inside (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "QQӶtestӶabb234");
+ list = g_list_append (list, "QQӶtestӶabb1");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("QQӶtestӶabb", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_unicode_whole_string (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "ǣȸʸͻͻΎΘΛ");
+ list = g_list_append (list, "ǣȸʸͻͻΎΘ");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("ǣȸʸͻͻΎΘ", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_unicode_extension (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "test.ǣȸʸͻͻΎΘΛ");
+ list = g_list_append (list, "test.ǣȸʸͻͻΎΘ");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("test", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_unicode_with_punctuation (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "ǣȸʸ- ͻͻΎΘ$%%^");
+ list = g_list_append (list, "ǣȸʸ- ͻͻΎΘ$%%&");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("ǣȸʸ- ͻͻΎΘ$%%", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_many_strings (void)
+{
+ GList *list = NULL;
+ char *actual;
+ char *filename;
+ int i;
+
+ for (i = 0; i < 500; ++i)
+ {
+ filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
+ list = g_list_append (list, filename);
+ }
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("we are no longer the knights who say nii", ==, actual);
+
+ g_free (actual);
+ g_list_free_full (list, g_free);
+}
+
+static void
+test_many_strings_last_differs (void)
+{
+ GList *list = NULL;
+ char *actual;
+ char *filename;
+ int i;
+
+ for (i = 0; i < 500; ++i)
+ {
+ filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
+
+ if (i == 499)
+ {
+ filename[2] = 'X';
+ }
+
+ list = g_list_append (list, filename);
+ }
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ g_free (actual);
+ g_list_free_full (list, g_free);
+}
+
+static void
+test_many_strings_first_differs (void)
+{
+ GList *list = NULL;
+ char *actual;
+ char *filename;
+ int i;
+
+ for (i = 0; i < 500; ++i)
+ {
+ filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
+
+ if (i == 0)
+ {
+ filename[2] = 'X';
+ }
+
+ list = g_list_append (list, filename);
+ }
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ g_free (actual);
+ g_list_free_full (list, g_free);
+}
+
+static void
+test_smaller_min_length_and_does_have_common_prefix (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "CA");
+ list = g_list_append (list, "CB");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 1);
+ g_assert_cmpstr ("C", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_smaller_min_length_and_doesnt_have_common_prefix (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "CA");
+ list = g_list_append (list, "BB");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 1);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+
+static void
+setup_test_suite (void)
+{
+ g_test_add_func ("/get-common-filename-prefix/1.0",
+ test_has_large_enough_common_prefix);
+ g_test_add_func ("/get-common-filename-prefix/1.1",
+ test_has_large_enough_common_prefix_with_spaces_in_middle);
+ g_test_add_func ("/get-common-filename-prefix/1.2",
+ test_has_large_enough_common_prefix_with_punctuation_in_middle);
+ g_test_add_func ("/get-common-filename-prefix/1.3",
+ test_has_large_enough_common_prefix_with_punctuation_in_middle_and_extension);
+
+ g_test_add_func ("/get-common-filename-prefix/2.0",
+ test_doesnt_have_large_enough_common_prefix);
+ g_test_add_func ("/get-common-filename-prefix/2.1",
+ test_doesnt_have_large_enough_common_prefix_completely_different_strings);
+ g_test_add_func ("/get-common-filename-prefix/2.2",
+ test_doesnt_have_large_enough_common_prefix_first_character_differs);
+ g_test_add_func ("/get-common-filename-prefix/2.3",
+ test_doesnt_have_large_enough_common_prefix_first_character_differs_longer_string);
+
+ g_test_add_func ("/get-common-filename-prefix/3.0",
+ test_has_large_enough_common_prefix_until_extension_removed);
+
+ g_test_add_func ("/get-common-filename-prefix/4.0",
+ test_extension_is_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.1",
+ test_whitespace_is_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.2",
+ test_whitespace_and_extension_are_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.3",
+ test_punctuation_is_preserved);
+
+ g_test_add_func ("/get-common-filename-prefix/5.0",
+ test_unicode_on_inside);
+ g_test_add_func ("/get-common-filename-prefix/5.1",
+ test_unicode_on_outside);
+ g_test_add_func ("/get-common-filename-prefix/5.2",
+ test_unicode_whole_string);
+ g_test_add_func ("/get-common-filename-prefix/5.3",
+ test_unicode_extension);
+ g_test_add_func ("/get-common-filename-prefix/5.4",
+ test_unicode_with_punctuation);
+
+ g_test_add_func ("/get-common-filename-prefix/6.0",
+ test_many_strings);
+ g_test_add_func ("/get-common-filename-prefix/6.1",
+ test_many_strings_last_differs);
+ g_test_add_func ("/get-common-filename-prefix/6.2",
+ test_many_strings_first_differs);
+
+ g_test_add_func ("/get-common-filename-prefix/7.0",
+ test_smaller_min_length_and_does_have_common_prefix);
+ g_test_add_func ("/get-common-filename-prefix/7.1",
+ test_smaller_min_length_and_doesnt_have_common_prefix);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=747907");
+ g_test_set_nonfatal_assertions ();
+
+ setup_test_suite ();
+
+ return g_test_run ();
+}
diff --git a/test/automated/displayless/test-file-utilities.c b/test/automated/displayless/test-file-utilities.c
new file mode 100644
index 0000000..17a7c92
--- /dev/null
+++ b/test/automated/displayless/test-file-utilities.c
@@ -0,0 +1,240 @@
+#include <glib.h>
+#include <glib/gprintf.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.h"
+#include "src/nautilus-file.c"
+#include <unistd.h>
+#include "eel/eel-string.h"
+
+#define ROOT_DIR "file:///tmp"
+
+/* Tests the function for empty selections */
+static void
+test_both_null (void)
+{
+ g_assert_true (nautilus_file_selection_equal (NULL, NULL));
+}
+
+/* Tests the function for an empty and a non-empty selection */
+static void
+test_either_null (void)
+{
+ g_autoptr (NautilusFile) file = NULL;
+ g_autoptr (NautilusDirectory) directory = NULL;
+ g_autolist (NautilusFile) selection = NULL;
+
+ directory = nautilus_directory_get_by_uri (ROOT_DIR);
+ g_assert_true (NAUTILUS_IS_DIRECTORY (directory));
+
+ file = nautilus_file_new_from_filename (directory, "null_first", FALSE);
+ nautilus_directory_add_file (directory, file);
+
+ selection = g_list_append (selection, g_object_ref (file));
+ g_assert_false (nautilus_file_selection_equal (NULL, selection));
+ g_assert_false (nautilus_file_selection_equal (selection, NULL));
+}
+
+/* tests the function for 2 identical selections, each containing one file */
+static void
+test_one_file_equal (void)
+{
+ g_autoptr (NautilusFile) file = NULL;
+ g_autoptr (NautilusDirectory) directory = NULL;
+ g_autolist (NautilusFile) selection = NULL;
+
+ directory = nautilus_directory_get_by_uri (ROOT_DIR);
+ g_assert_true (NAUTILUS_IS_DIRECTORY (directory));
+
+ file = nautilus_file_new_from_filename (directory, "one_file_equal", FALSE);
+ nautilus_directory_add_file (directory, file);
+
+ selection = g_list_append (selection, g_object_ref (file));
+ g_assert_true (nautilus_file_selection_equal (selection, selection));
+}
+
+/* Tests the function for 2 different selections, each containing one file */
+static void
+test_one_file_different (void)
+{
+ g_autoptr (NautilusFile) one_file_first = NULL;
+ g_autoptr (NautilusFile) one_file_second = NULL;
+ g_autoptr (NautilusDirectory) directory = NULL;
+ g_autolist (NautilusFile) first_selection = NULL;
+ g_autolist (NautilusFile) second_selection = NULL;
+
+ directory = nautilus_directory_get_by_uri (ROOT_DIR);
+ g_assert_true (NAUTILUS_IS_DIRECTORY (directory));
+
+ one_file_first = nautilus_file_new_from_filename (directory, "one_file_first", FALSE);
+ nautilus_directory_add_file (directory, one_file_first);
+
+ one_file_second = nautilus_file_new_from_filename (directory, "one_file_second", FALSE);
+ nautilus_directory_add_file (directory, one_file_second);
+
+ first_selection = g_list_append (first_selection, g_object_ref (one_file_first));
+ second_selection = g_list_append (second_selection, g_object_ref (one_file_second));
+ g_assert_false (nautilus_file_selection_equal (first_selection, second_selection));
+}
+
+/* Tests the function for 2 identical selections, each containing 50 files */
+static void
+test_multiple_files_equal_medium (void)
+{
+ g_autoptr (NautilusDirectory) directory = NULL;
+ g_autolist (NautilusFile) selection = NULL;
+
+ directory = nautilus_directory_get_by_uri (ROOT_DIR);
+ g_assert_true (NAUTILUS_IS_DIRECTORY (directory));
+ for (gint index = 0; index < 50; index++)
+ {
+ g_autoptr (NautilusFile) file = NULL;
+ g_autofree gchar *file_name = NULL;
+
+ file_name = g_strdup_printf ("multiple_files_equal_medium_%i", index);
+ file = nautilus_file_new_from_filename (directory, file_name, FALSE);
+ nautilus_directory_add_file (directory, file);
+ selection = g_list_prepend (selection, g_object_ref (file));
+ }
+
+ g_assert_true (nautilus_file_selection_equal (selection, selection));
+}
+
+/* Tests the function for 2 different selections, each containing 51 files,
+ * the last file being the different one */
+static void
+test_multiple_files_different_medium (void)
+{
+ g_autoptr (NautilusFile) first_file = NULL;
+ g_autoptr (NautilusFile) second_file = NULL;
+ g_autoptr (NautilusDirectory) directory = NULL;
+ g_autolist (NautilusFile) first_selection = NULL;
+ g_autolist (NautilusFile) second_selection = NULL;
+ g_autofree gchar *first_file_name = NULL;
+ g_autofree gchar *second_file_name = NULL;
+
+ directory = nautilus_directory_get_by_uri (ROOT_DIR);
+ g_assert_true (NAUTILUS_IS_DIRECTORY (directory));
+ for (gint index = 0; index < 50; index++)
+ {
+ first_file_name = g_strdup_printf ("multiple_files_different_medium_%i", index);
+ first_file = nautilus_file_new_from_filename (directory, first_file_name, FALSE);
+ nautilus_directory_add_file (directory, first_file);
+ g_assert_true (NAUTILUS_IS_FILE (first_file));
+ first_selection = g_list_prepend (first_selection, g_object_ref (first_file));
+ second_selection = g_list_prepend (second_selection, g_object_ref (first_file));
+ }
+
+ first_file_name = g_strdup_printf ("multiple_files_different_medium_lastElement");
+ second_file_name = g_strdup_printf ("multiple_files_different_medium_differentElement");
+ first_file = nautilus_file_new_from_filename (directory, first_file_name, FALSE);
+ nautilus_directory_add_file (directory, first_file);
+ second_file = nautilus_file_new_from_filename (directory, second_file_name, FALSE);
+ nautilus_directory_add_file (directory, second_file);
+ g_assert_true (NAUTILUS_IS_FILE (first_file));
+ g_assert_true (NAUTILUS_IS_FILE (second_file));
+ first_selection = g_list_append (first_selection, g_object_ref (first_file));
+ second_selection = g_list_append (second_selection, g_object_ref (second_file));
+
+ g_assert_false (nautilus_file_selection_equal (first_selection, second_selection));
+}
+
+/* Tests the function for 2 identical selections, each containing 1000 files */
+static void
+test_multiple_files_equal_large (void)
+{
+ g_autoptr (NautilusDirectory) directory = NULL;
+ g_autolist (NautilusFile) selection = NULL;
+
+ directory = nautilus_directory_get_by_uri (ROOT_DIR);
+ g_assert_true (NAUTILUS_IS_DIRECTORY (directory));
+ for (gint index = 0; index < 1000; index++)
+ {
+ g_autoptr (NautilusFile) file = NULL;
+ g_autofree gchar *file_name = NULL;
+
+ file_name = g_strdup_printf ("multiple_files_equal_large_%i", index);
+ file = nautilus_file_new_from_filename (directory, file_name, FALSE);
+ nautilus_directory_add_file (directory, file);
+ g_assert_true (NAUTILUS_IS_FILE (file));
+ selection = g_list_prepend (selection, g_object_ref (file));
+ }
+
+ g_assert_true (nautilus_file_selection_equal (selection, selection));
+}
+
+/* Tests the function for 2 different selections, each containing 1001 files,
+ * the last file being the different one */
+static void
+test_multiple_files_different_large (void)
+{
+ g_autoptr (NautilusFile) first_file = NULL;
+ g_autoptr (NautilusFile) second_file = NULL;
+ g_autoptr (NautilusDirectory) directory = NULL;
+ g_autolist (NautilusFile) first_selection = NULL;
+ g_autolist (NautilusFile) second_selection = NULL;
+ g_autofree gchar *first_file_name = NULL;
+ g_autofree gchar *second_file_name = NULL;
+
+ directory = nautilus_directory_get_by_uri (ROOT_DIR);
+ g_assert_true (NAUTILUS_IS_DIRECTORY (directory));
+ for (gint index = 0; index < 1000; index++)
+ {
+ first_file_name = g_strdup_printf ("multiple_files_different_large_%i", index);
+ first_file = nautilus_file_new_from_filename (directory, first_file_name, FALSE);
+ nautilus_directory_add_file (directory, first_file);
+ g_assert_true (NAUTILUS_IS_FILE (first_file));
+ first_selection = g_list_prepend (first_selection, g_object_ref (first_file));
+ second_selection = g_list_prepend (second_selection, g_object_ref (first_file));
+ }
+
+ first_file_name = g_strdup_printf ("multiple_files_different_large_lastElement");
+ second_file_name = g_strdup_printf ("multiple_files_different_large_differentElement");
+ first_file = nautilus_file_new_from_filename (directory, first_file_name, FALSE);
+ nautilus_directory_add_file (directory, first_file);
+ second_file = nautilus_file_new_from_filename (directory, second_file_name, FALSE);
+ nautilus_directory_add_file (directory, second_file);
+ g_assert_true (NAUTILUS_IS_FILE (first_file));
+ g_assert_true (NAUTILUS_IS_FILE (second_file));
+
+ first_selection = g_list_append (first_selection, g_object_ref (first_file));
+ second_selection = g_list_append (second_selection, g_object_ref (second_file));
+
+ g_assert_false (nautilus_file_selection_equal (first_selection, second_selection));
+}
+
+static void
+setup_test_suite (void)
+{
+ g_test_add_func ("/file-selection-equal-null/1.0",
+ test_both_null);
+ g_test_add_func ("/file-selection-equal-null/1.1",
+ test_either_null);
+ g_test_add_func ("/file-selection-equal-files/1.0",
+ test_one_file_equal);
+ g_test_add_func ("/file-selection-equal-files/1.1",
+ test_multiple_files_equal_medium);
+ g_test_add_func ("/file-selection-equal-files/1.2",
+ test_multiple_files_equal_large);
+ g_test_add_func ("/file-selection-different-files/1.0",
+ test_one_file_different);
+ g_test_add_func ("/file-selection-different-files/1.1",
+ test_multiple_files_different_medium);
+ g_test_add_func ("/file-selection-different-files/1.2",
+ test_multiple_files_different_large);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_set_nonfatal_assertions ();
+ nautilus_ensure_extension_points ();
+
+ setup_test_suite ();
+
+ return g_test_run ();
+}
diff --git a/test/automated/displayless/test-nautilus-search-engine-model.c b/test/automated/displayless/test-nautilus-search-engine-model.c
new file mode 100644
index 0000000..0a68bd7
--- /dev/null
+++ b/test/automated/displayless/test-nautilus-search-engine-model.c
@@ -0,0 +1,79 @@
+#include "test-utilities.h"
+
+static guint total_hits = 0;
+
+static void
+hits_added_cb (NautilusSearchEngine *engine,
+ GSList *hits)
+{
+ g_print ("Hits added for search engine model!\n");
+ for (gint hit_number = 0; hits != NULL; hits = hits->next, hit_number++)
+ {
+ g_print ("Hit %i: %s\n", hit_number, nautilus_search_hit_get_uri (hits->data));
+
+ total_hits += 1;
+ }
+}
+
+static void
+finished_cb (NautilusSearchEngine *engine,
+ NautilusSearchProviderStatus status,
+ gpointer user_data)
+{
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine));
+
+ g_print ("\nNautilus search engine model finished!\n");
+
+ delete_search_file_hierarchy ("model");
+
+ g_main_loop_quit (user_data);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_autoptr (GMainLoop) loop = NULL;
+ NautilusSearchEngine *engine;
+ NautilusSearchEngineModel *model;
+ g_autoptr (NautilusDirectory) directory = NULL;
+ g_autoptr (NautilusQuery) query = NULL;
+ g_autoptr (GFile) location = NULL;
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ nautilus_ensure_extension_points ();
+ /* Needed for nautilus-query.c.
+ * FIXME: tests are not installed, so the system does not
+ * have the gschema. Installed tests is a long term GNOME goal.
+ */
+ nautilus_global_preferences_init ();
+
+ engine = nautilus_search_engine_new ();
+ g_signal_connect (engine, "hits-added",
+ G_CALLBACK (hits_added_cb), NULL);
+ g_signal_connect (engine, "finished",
+ G_CALLBACK (finished_cb), loop);
+
+ query = nautilus_query_new ();
+ nautilus_query_set_text (query, "engine_model");
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine), query);
+
+ location = g_file_new_for_path (g_get_tmp_dir ());
+ directory = nautilus_directory_get (location);
+ model = nautilus_search_engine_get_model_provider (engine);
+ nautilus_search_engine_model_set_model (model, directory);
+
+ nautilus_query_set_location (query, location);
+
+ create_search_file_hierarchy ("model");
+
+ nautilus_search_engine_start_by_target (NAUTILUS_SEARCH_PROVIDER (engine),
+ NAUTILUS_SEARCH_ENGINE_MODEL_ENGINE);
+
+ g_main_loop_run (loop);
+
+ g_assert_cmpint (total_hits, ==, 3);
+
+ return 0;
+}
diff --git a/test/automated/displayless/test-nautilus-search-engine-simple.c b/test/automated/displayless/test-nautilus-search-engine-simple.c
new file mode 100644
index 0000000..9657bb6
--- /dev/null
+++ b/test/automated/displayless/test-nautilus-search-engine-simple.c
@@ -0,0 +1,74 @@
+#include "test-utilities.h"
+
+static guint total_hits = 0;
+
+static void
+hits_added_cb (NautilusSearchEngine *engine,
+ GSList *hits)
+{
+ g_print ("Hits added for search engine simple!\n");
+ for (gint hit_number = 0; hits != NULL; hits = hits->next, hit_number++)
+ {
+ g_print ("Hit %i: %s\n", hit_number, nautilus_search_hit_get_uri (hits->data));
+ total_hits += 1;
+ }
+}
+
+static void
+finished_cb (NautilusSearchEngine *engine,
+ NautilusSearchProviderStatus status,
+ gpointer user_data)
+{
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine));
+
+ g_print ("\nNautilus search engine simple finished!\n");
+
+ delete_search_file_hierarchy ("simple");
+
+ g_main_loop_quit (user_data);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_autoptr (GMainLoop) loop = NULL;
+ NautilusSearchEngine *engine;
+ g_autoptr (NautilusDirectory) directory = NULL;
+ g_autoptr (NautilusQuery) query = NULL;
+ g_autoptr (GFile) location = NULL;
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ nautilus_ensure_extension_points ();
+ /* Needed for nautilus-query.c.
+ * FIXME: tests are not installed, so the system does not
+ * have the gschema. Installed tests is a long term GNOME goal.
+ */
+ nautilus_global_preferences_init ();
+
+ engine = nautilus_search_engine_new ();
+ g_signal_connect (engine, "hits-added",
+ G_CALLBACK (hits_added_cb), NULL);
+ g_signal_connect (engine, "finished",
+ G_CALLBACK (finished_cb), loop);
+
+ query = nautilus_query_new ();
+ nautilus_query_set_text (query, "engine_simple");
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine), query);
+
+ location = g_file_new_for_path (g_get_tmp_dir ());
+ directory = nautilus_directory_get (location);
+ nautilus_query_set_location (query, location);
+
+ create_search_file_hierarchy ("simple");
+
+ nautilus_search_engine_start_by_target (NAUTILUS_SEARCH_PROVIDER (engine),
+ NAUTILUS_SEARCH_ENGINE_SIMPLE_ENGINE);
+
+ g_main_loop_run (loop);
+
+ g_assert_cmpint (total_hits, ==, 3);
+
+ return 0;
+}
diff --git a/test/automated/displayless/test-nautilus-search-engine-tracker.c b/test/automated/displayless/test-nautilus-search-engine-tracker.c
new file mode 100644
index 0000000..0c96ef7
--- /dev/null
+++ b/test/automated/displayless/test-nautilus-search-engine-tracker.c
@@ -0,0 +1,185 @@
+#include "test-utilities.h"
+
+/* Time in seconds we allow for Tracker Miners to index the file */
+#define TRACKER_MINERS_AWAIT_TIMEOUT 1000
+
+static guint total_hits = 0;
+
+typedef struct
+{
+ GMainLoop *main_loop;
+ gchar *uri;
+ gboolean created;
+} TrackerAwaitFileData;
+
+static TrackerAwaitFileData *
+tracker_await_file_data_new (const char *uri,
+ GMainLoop *main_loop)
+{
+ TrackerAwaitFileData *data;
+
+ data = g_slice_new0 (TrackerAwaitFileData);
+ data->uri = g_strdup (uri);
+ data->main_loop = g_main_loop_ref (main_loop);
+
+ return data;
+}
+
+static void
+tracker_await_file_data_free (TrackerAwaitFileData *data)
+{
+ g_free (data->uri);
+ g_main_loop_unref (data->main_loop);
+ g_slice_free (TrackerAwaitFileData, data);
+}
+
+static gboolean timeout_cb (gpointer user_data)
+{
+ TrackerAwaitFileData *data = user_data;
+ g_error ("Timeout waiting for %s to be indexed by Tracker.", data->uri);
+ return G_SOURCE_REMOVE;
+}
+
+static void
+tracker_events_cb (TrackerNotifier *self,
+ gchar *service,
+ gchar *graph,
+ GPtrArray *events,
+ gpointer user_data)
+{
+ TrackerAwaitFileData *data = user_data;
+ int i;
+
+ for (i = 0; i < events->len; i++)
+ {
+ TrackerNotifierEvent *event = g_ptr_array_index (events, i);
+
+ if (tracker_notifier_event_get_event_type (event) == TRACKER_NOTIFIER_EVENT_CREATE)
+ {
+ const gchar *urn = tracker_notifier_event_get_urn (event);
+ g_debug ("Got CREATED event for %s", urn);
+ if (strcmp (urn, data->uri) == 0)
+ {
+ data->created = TRUE;
+ g_main_loop_quit (data->main_loop);
+ }
+ }
+ }
+}
+
+/* Create data that the Tracker indexer will find, and wait for the database to be updated. */
+static void
+create_test_data (TrackerSparqlConnection *connection,
+ const gchar *indexed_tmpdir)
+{
+ g_autoptr (GFile) test_file = NULL;
+ g_autoptr (GMainLoop) main_loop = NULL;
+ g_autoptr (GError) error = NULL;
+ g_autoptr (TrackerNotifier) notifier = NULL;
+ TrackerAwaitFileData *await_data;
+ gulong signal_id, timeout_id;
+
+ test_file = g_file_new_build_filename (indexed_tmpdir, "target_file.txt", NULL);
+
+ main_loop = g_main_loop_new (NULL, 0);
+ await_data = tracker_await_file_data_new (g_file_get_uri (test_file), main_loop);
+
+ notifier = tracker_sparql_connection_create_notifier (connection);
+
+ signal_id = g_signal_connect (notifier, "events", G_CALLBACK (tracker_events_cb), await_data);
+ timeout_id = g_timeout_add_seconds (TRACKER_MINERS_AWAIT_TIMEOUT, timeout_cb, await_data);
+
+ g_file_set_contents (g_file_peek_path (test_file), "Please show me in the search results", -1, &error);
+ g_assert_no_error (error);
+
+ g_main_loop_run (main_loop);
+
+ g_assert (await_data->created);
+ g_source_remove (timeout_id);
+ g_clear_signal_handler (&signal_id, notifier);
+
+ tracker_await_file_data_free (await_data);
+}
+
+static void
+hits_added_cb (NautilusSearchEngine *engine,
+ GSList *hits)
+{
+ g_print ("Hits added for search engine tracker!\n");
+ for (gint hit_number = 0; hits != NULL; hits = hits->next, hit_number++)
+ {
+ g_print ("Hit %i: %s\n", hit_number, nautilus_search_hit_get_uri (hits->data));
+ total_hits += 1;
+ }
+}
+
+static void
+finished_cb (NautilusSearchEngine *engine,
+ NautilusSearchProviderStatus status,
+ gpointer user_data)
+{
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine));
+
+ g_print ("\nNautilus search engine tracker finished!\n");
+
+ g_main_loop_quit (user_data);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_autoptr (GMainLoop) loop = NULL;
+ g_autoptr (TrackerSparqlConnection) connection = NULL;
+ NautilusSearchEngine *engine;
+ g_autoptr (NautilusDirectory) directory = NULL;
+ g_autoptr (NautilusQuery) query = NULL;
+ g_autoptr (GFile) location = NULL;
+ g_autoptr (GError) error = NULL;
+ const gchar *indexed_tmpdir;
+
+ indexed_tmpdir = g_getenv ("TRACKER_INDEXED_TMPDIR");
+ if (!indexed_tmpdir)
+ {
+ g_error ("This test must be inside the `tracker-sandbox` script "
+ "to ensure a private Tracker indexer daemon is used.");
+ }
+
+ connection = tracker_sparql_connection_bus_new ("org.freedesktop.Tracker3.Miner.Files", NULL, NULL, &error);
+
+ g_assert_no_error (error);
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ nautilus_ensure_extension_points ();
+ /* Needed for nautilus-query.c.
+ * FIXME: tests are not installed, so the system does not
+ * have the gschema. Installed tests is a long term GNOME goal.
+ */
+ nautilus_global_preferences_init ();
+
+ create_test_data (connection, indexed_tmpdir);
+
+ engine = nautilus_search_engine_new ();
+ g_signal_connect (engine, "hits-added",
+ G_CALLBACK (hits_added_cb), NULL);
+ g_signal_connect (engine, "finished",
+ G_CALLBACK (finished_cb), loop);
+
+ query = nautilus_query_new ();
+ nautilus_query_set_text (query, "target");
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine), query);
+
+ location = g_file_new_for_path (indexed_tmpdir);
+ directory = nautilus_directory_get (location);
+ nautilus_query_set_location (query, location);
+
+ nautilus_search_engine_start_by_target (NAUTILUS_SEARCH_PROVIDER (engine),
+ NAUTILUS_SEARCH_ENGINE_TRACKER_ENGINE);
+
+ g_main_loop_run (loop);
+
+ g_assert_cmpint (total_hits, ==, 1);
+
+ return 0;
+}
diff --git a/test/automated/displayless/test-nautilus-search-engine.c b/test/automated/displayless/test-nautilus-search-engine.c
new file mode 100644
index 0000000..cc843de
--- /dev/null
+++ b/test/automated/displayless/test-nautilus-search-engine.c
@@ -0,0 +1,74 @@
+#include "test-utilities.h"
+
+static guint total_hits = 0;
+
+static void
+hits_added_cb (NautilusSearchEngine *engine,
+ GSList *hits)
+{
+ g_print ("Hits added for search engine!\n");
+ for (gint hit_number = 0; hits != NULL; hits = hits->next, hit_number++)
+ {
+ g_print ("Hit %i: %s\n", hit_number, nautilus_search_hit_get_uri (hits->data));
+ total_hits += 1;
+ }
+}
+
+static void
+finished_cb (NautilusSearchEngine *engine,
+ NautilusSearchProviderStatus status,
+ gpointer user_data)
+{
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine));
+
+ g_print ("\nNautilus search engine finished!\n");
+
+ delete_search_file_hierarchy ("all_engines");
+
+ g_main_loop_quit (user_data);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_autoptr (GMainLoop) loop = NULL;
+ NautilusSearchEngine *engine;
+ g_autoptr (NautilusDirectory) directory = NULL;
+ g_autoptr (NautilusQuery) query = NULL;
+ g_autoptr (GFile) location = NULL;
+ g_autoptr (GFile) file = NULL;
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ nautilus_ensure_extension_points ();
+ /* Needed for nautilus-query.c.
+ * FIXME: tests are not installed, so the system does not
+ * have the gschema. Installed tests is a long term GNOME goal.
+ */
+ nautilus_global_preferences_init ();
+
+ engine = nautilus_search_engine_new ();
+ g_signal_connect (engine, "hits-added",
+ G_CALLBACK (hits_added_cb), NULL);
+ g_signal_connect (engine, "finished",
+ G_CALLBACK (finished_cb), loop);
+
+ query = nautilus_query_new ();
+ nautilus_query_set_text (query, "engine_all_engines");
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine), query);
+
+ location = g_file_new_for_path (g_get_tmp_dir ());
+ directory = nautilus_directory_get (location);
+ nautilus_query_set_location (query, location);
+
+ create_search_file_hierarchy ("all_engines");
+
+ nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (engine));
+
+ g_main_loop_run (loop);
+
+ g_assert_cmpint (total_hits, ==, 3);
+
+ return 0;
+}
diff --git a/test/automated/displayless/test-utilities.c b/test/automated/displayless/test-utilities.c
new file mode 100644
index 0000000..68014ea
--- /dev/null
+++ b/test/automated/displayless/test-utilities.c
@@ -0,0 +1,558 @@
+#include "test-utilities.h"
+
+void
+empty_directory_by_prefix (GFile *parent,
+ gchar *prefix)
+{
+ g_autoptr (GFileEnumerator) enumerator = NULL;
+ g_autoptr (GFile) child = NULL;
+
+ enumerator = g_file_enumerate_children (parent,
+ G_FILE_ATTRIBUTE_STANDARD_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+
+ g_file_enumerator_iterate (enumerator, NULL, &child, NULL, NULL);
+ while (child != NULL)
+ {
+ gboolean res;
+
+ if (g_str_has_prefix (g_file_get_basename (child), prefix))
+ {
+ res = g_file_delete (child, NULL, NULL);
+ /* The directory is not empty */
+ if (!res)
+ {
+ empty_directory_by_prefix (child, prefix);
+ g_file_delete (child, NULL, NULL);
+ }
+ }
+
+ g_file_enumerator_iterate (enumerator, NULL, &child, NULL, NULL);
+ }
+}
+
+void
+create_search_file_hierarchy (gchar *search_engine)
+{
+ g_autoptr (GFile) location = NULL;
+ g_autoptr (GFile) file = NULL;
+ GFileOutputStream *out;
+ gchar *file_name;
+
+ location = g_file_new_for_path (g_get_tmp_dir ());
+
+ file_name = g_strdup_printf ("engine_%s", search_engine);
+ file = g_file_get_child (location, file_name);
+ g_free (file_name);
+ out = g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL);
+ g_object_unref (out);
+
+ file_name = g_strdup_printf ("engine_%s_directory", search_engine);
+ file = g_file_get_child (location, file_name);
+ g_free (file_name);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_child", search_engine);
+ file = g_file_get_child (file, file_name);
+ g_free (file_name);
+ out = g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL);
+ g_object_unref (out);
+
+ file_name = g_strdup_printf ("engine_%s_second_directory", search_engine);
+ file = g_file_get_child (location, file_name);
+ g_free (file_name);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("engine_%s_child", search_engine);
+ file = g_file_get_child (file, file_name);
+ g_free (file_name);
+ out = g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL);
+ g_object_unref (out);
+
+ file_name = g_strdup_printf ("%s_directory", search_engine);
+ file = g_file_get_child (location, file_name);
+ g_free (file_name);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("engine_%s_child", search_engine);
+ file = g_file_get_child (file, file_name);
+ g_free (file_name);
+ out = g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL);
+ g_object_unref (out);
+}
+
+void
+delete_search_file_hierarchy (gchar *search_engine)
+{
+ g_autoptr (GFile) location = NULL;
+ g_autoptr (GFile) file = NULL;
+ gchar *file_name;
+
+ location = g_file_new_for_path (g_get_tmp_dir ());
+
+ file_name = g_strdup_printf ("engine_%s", search_engine);
+ file = g_file_get_child (location, file_name);
+ g_free (file_name);
+ g_file_delete (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("engine_%s_directory", search_engine);
+ file = g_file_get_child (location, file_name);
+ g_free (file_name);
+ file_name = g_strdup_printf ("%s_child", search_engine);
+ file = g_file_get_child (file, file_name);
+ g_free (file_name);
+ g_file_delete (file, NULL, NULL);
+ file_name = g_strdup_printf ("engine_%s_directory", search_engine);
+ file = g_file_get_child (location, file_name);
+ g_free (file_name);
+ g_file_delete (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("engine_%s_second_directory", search_engine);
+ file = g_file_get_child (location, file_name);
+ g_free (file_name);
+ file_name = g_strdup_printf ("engine_%s_child", search_engine);
+ file = g_file_get_child (file, file_name);
+ g_free (file_name);
+ g_file_delete (file, NULL, NULL);
+ file_name = g_strdup_printf ("engine_%s_second_directory", search_engine);
+ file = g_file_get_child (location, file_name);
+ g_free (file_name);
+ g_file_delete (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_directory", search_engine);
+ file = g_file_get_child (location, file_name);
+ g_free (file_name);
+ file_name = g_strdup_printf ("engine_%s_child", search_engine);
+ file = g_file_get_child (file, file_name);
+ g_free (file_name);
+ g_file_delete (file, NULL, NULL);
+ file_name = g_strdup_printf ("%s_directory", search_engine);
+ file = g_file_get_child (location, file_name);
+ g_free (file_name);
+ g_file_delete (file, NULL, NULL);
+}
+
+/* This callback function quits the mainloop inside which the
+ * asynchronous undo/redo operation happens.
+ */
+
+void
+quit_loop_callback (NautilusFileUndoManager *undo_manager,
+ GMainLoop *loop)
+{
+ g_main_loop_quit (loop);
+}
+
+/* This undoes the last operation blocking the current main thread. */
+void
+test_operation_undo (void)
+{
+ g_autoptr (GMainLoop) loop = NULL;
+ g_autoptr (GMainContext) context = NULL;
+ gulong handler_id;
+
+ context = g_main_context_new ();
+ g_main_context_push_thread_default (context);
+ loop = g_main_loop_new (context, FALSE);
+
+ handler_id = g_signal_connect (nautilus_file_undo_manager_get (),
+ "undo-changed",
+ G_CALLBACK (quit_loop_callback),
+ loop);
+
+ nautilus_file_undo_manager_undo (NULL, NULL);
+
+ g_main_loop_run (loop);
+
+ g_main_context_pop_thread_default (context);
+
+ g_signal_handler_disconnect (nautilus_file_undo_manager_get (),
+ handler_id);
+}
+
+/* This undoes and redoes the last move operation blocking the current main thread. */
+void
+test_operation_undo_redo (void)
+{
+ g_autoptr (GMainLoop) loop = NULL;
+ g_autoptr (GMainContext) context = NULL;
+ gulong handler_id;
+
+ test_operation_undo ();
+
+ context = g_main_context_new ();
+ g_main_context_push_thread_default (context);
+ loop = g_main_loop_new (context, FALSE);
+
+ handler_id = g_signal_connect (nautilus_file_undo_manager_get (),
+ "undo-changed",
+ G_CALLBACK (quit_loop_callback),
+ loop);
+
+ nautilus_file_undo_manager_redo (NULL, NULL);
+
+ g_main_loop_run (loop);
+
+ g_main_context_pop_thread_default (context);
+
+ g_signal_handler_disconnect (nautilus_file_undo_manager_get (),
+ handler_id);
+}
+
+/* Creates the following hierarchy:
+ * /tmp/`prefix`_first_dir/`prefix`_first_dir_child
+ * /tmp/`prefix`_second_dir/
+ */
+void
+create_one_file (gchar *prefix)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) first_dir = NULL;
+ g_autoptr (GFile) second_dir = NULL;
+ g_autoptr (GFile) file = NULL;
+ GFileOutputStream *out;
+ gchar *file_name;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ file_name = g_strdup_printf ("%s_first_dir", prefix);
+ first_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (first_dir != NULL);
+ g_file_make_directory (first_dir, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_first_dir_child", prefix);
+ file = g_file_get_child (first_dir, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ out = g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL);
+ g_object_unref (out);
+
+ file_name = g_strdup_printf ("%s_second_dir", prefix);
+ second_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (second_dir != NULL);
+ g_file_make_directory (second_dir, NULL, NULL);
+}
+
+/* Creates the same hierarchy as above, but all files being directories. */
+void
+create_one_empty_directory (gchar *prefix)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) first_dir = NULL;
+ g_autoptr (GFile) second_dir = NULL;
+ g_autoptr (GFile) file = NULL;
+ gchar *file_name;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ file_name = g_strdup_printf ("%s_first_dir", prefix);
+ first_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (first_dir != NULL);
+ g_file_make_directory (first_dir, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_first_dir_child", prefix);
+ file = g_file_get_child (first_dir, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_second_dir", prefix);
+ second_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (second_dir != NULL);
+ g_file_make_directory (second_dir, NULL, NULL);
+}
+
+void
+create_multiple_files (gchar *prefix,
+ gint number_of_files)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ gchar *file_name;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < number_of_files; i++)
+ {
+ GFileOutputStream *out;
+
+ file_name = g_strdup_printf ("%s_file_%i", prefix, i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ out = g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL);
+ g_object_unref (out);
+ }
+
+ file_name = g_strdup_printf ("%s_dir", prefix);
+ dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (dir != NULL);
+ g_file_make_directory (dir, NULL, NULL);
+}
+
+void
+create_multiple_directories (gchar *prefix,
+ gint number_of_directories)
+{
+ g_autoptr (GFile) root = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) dir = NULL;
+ gchar *file_name;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < number_of_directories; i++)
+ {
+ file_name = g_strdup_printf ("%s_file_%i", prefix, i);
+ file = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+ }
+
+ file_name = g_strdup_printf ("%s_dir", prefix);
+ dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (dir != NULL);
+ g_file_make_directory (dir, NULL, NULL);
+}
+
+void
+create_first_hierarchy (gchar *prefix)
+{
+ 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;
+ gchar *file_name;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ file_name = g_strdup_printf ("%s_first_dir", prefix);
+ first_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (first_dir != NULL);
+ g_file_make_directory (first_dir, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_first_child", prefix);
+ file = g_file_get_child (first_dir, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+ file_name = g_strdup_printf ("%s_second_child", prefix);
+ file = g_file_get_child (first_dir, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_second_dir", prefix);
+ second_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (second_dir != NULL);
+ g_file_make_directory (second_dir, NULL, NULL);
+}
+
+void
+create_second_hierarchy (gchar *prefix)
+{
+ 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;
+ gchar *file_name;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ file_name = g_strdup_printf ("%s_first_dir", prefix);
+ first_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (first_dir != NULL);
+ g_file_make_directory (first_dir, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_first_child", prefix);
+ file = g_file_get_child (first_dir, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+ file_name = g_strdup_printf ("%s_second_child", prefix);
+ file = g_file_get_child (file, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_second_dir", prefix);
+ second_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (second_dir != NULL);
+ g_file_make_directory (second_dir, NULL, NULL);
+}
+
+void
+create_third_hierarchy (gchar *prefix)
+{
+ 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;
+ gchar *file_name;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ file_name = g_strdup_printf ("%s_first_dir", prefix);
+ first_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (first_dir != NULL);
+ g_file_make_directory (first_dir, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_first_dir_dir1", prefix);
+ file = g_file_get_child (first_dir, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_dir1_child", prefix);
+ file = g_file_get_child (file, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_first_dir_dir2", prefix);
+ file = g_file_get_child (first_dir, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_dir2_child", prefix);
+ file = g_file_get_child (file, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_second_dir", prefix);
+ second_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (second_dir != NULL);
+ g_file_make_directory (second_dir, NULL, NULL);
+}
+
+void
+create_fourth_hierarchy (gchar *prefix)
+{
+ 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;
+ gchar *file_name;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ file_name = g_strdup_printf ("%s_first_dir", prefix);
+ first_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (first_dir != NULL);
+ g_file_make_directory (first_dir, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_first_dir_child", prefix);
+ file = g_file_get_child (first_dir, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_second_dir", prefix);
+ second_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (second_dir != NULL);
+ g_file_make_directory (second_dir, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_second_dir_child", prefix);
+ file = g_file_get_child (second_dir, file_name);
+ g_free (file_name);
+
+ g_assert_true (file != NULL);
+ g_file_make_directory (file, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_third_dir", prefix);
+ third_dir = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_assert_true (third_dir != NULL);
+ g_file_make_directory (third_dir, NULL, NULL);
+}
+
+void
+create_multiple_full_directories (gchar *prefix,
+ gint number_of_directories)
+{
+ g_autoptr (GFile) root = NULL;
+
+ root = g_file_new_for_path (g_get_tmp_dir ());
+ g_assert_true (root != NULL);
+
+ for (int i = 0; i < number_of_directories; i++)
+ {
+ g_autoptr (GFile) directory = NULL;
+ g_autoptr (GFile) file = NULL;
+ gchar *file_name;
+
+ file_name = g_strdup_printf ("%s_directory_%i", prefix, i);
+
+ directory = g_file_get_child (root, file_name);
+ g_free (file_name);
+
+ g_file_make_directory (directory, NULL, NULL);
+
+ file_name = g_strdup_printf ("%s_file_%i", prefix, i);
+ file = g_file_get_child (directory, file_name);
+ g_free (file_name);
+
+ g_file_make_directory (file, NULL, NULL);
+ }
+}
diff --git a/test/automated/displayless/test-utilities.h b/test/automated/displayless/test-utilities.h
new file mode 100644
index 0000000..878c878
--- /dev/null
+++ b/test/automated/displayless/test-utilities.h
@@ -0,0 +1,34 @@
+#include <gio/gio.h>
+#include <src/nautilus-file-utilities.h>
+#include <src/nautilus-global-preferences.h>
+#include <src/nautilus-search-engine.h>
+#include <tracker-sparql.h>
+#include <locale.h>
+#include <src/nautilus-file-undo-manager.h>
+#include <src/nautilus-file-operations.h>
+#include <gio/gio.h>
+
+#pragma once
+
+void empty_directory_by_prefix (GFile *parent,
+ gchar *prefix);
+
+void create_search_file_hierarchy (gchar *search_engine);
+void delete_search_file_hierarchy (gchar *search_engine);
+
+void quit_loop_callback (NautilusFileUndoManager *undo_manager,
+ GMainLoop *loop);
+void test_operation_undo_redo (void);
+void test_operation_undo (void);
+
+void create_one_file (gchar *prefix);
+void create_one_empty_directory (gchar *prefix);
+
+void create_multiple_files (gchar *prefix, gint number_of_files);
+void create_multiple_directories (gchar *prefix, gint number_of_directories);
+void create_multiple_full_directories (gchar *prefix, gint number_of_directories);
+
+void create_first_hierarchy (gchar *prefix);
+void create_second_hierarchy (gchar *prefix);
+void create_third_hierarchy (gchar *prefix);
+void create_fourth_hierarchy (gchar *prefix); \ No newline at end of file