[glib/wip/oholy/fix-trash-symlink: 3/5] glocalfile: Add test case for symlink expansion
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/oholy/fix-trash-symlink: 3/5] glocalfile: Add test case for symlink expansion
- Date: Mon, 1 Oct 2018 13:30:17 +0000 (UTC)
commit d78d887fe6dc4c45701c9ed5872b47cf8f4a281b
Author: Ondrej Holy <oholy redhat com>
Date: Mon Oct 1 13:45:17 2018 +0200
glocalfile: Add test case for symlink expansion
Test symlink expansion in find_mountpoint_for() function over
_g_local_file_find_topdir_for(). find_mount_for() is crucial for many
of glocalfile.c functionality (e.g. to determine correct trash location)
and symlink expansion has to work properly.
https://gitlab.gnome.org/GNOME/glib/issues/1522
gio/tests/trash.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
---
diff --git a/gio/tests/trash.c b/gio/tests/trash.c
index b586f16f9..5022b4f09 100644
--- a/gio/tests/trash.c
+++ b/gio/tests/trash.c
@@ -96,6 +96,63 @@ test_trash_not_supported (void)
g_object_unref (file);
}
+/* Test that symlinks are properly expaned when looking for topdir (e.g. for trash folder). */
+static void
+test_trash_symlinks (void)
+{
+ GFile *symlink;
+ GUnixMountEntry *target_mount, *tmp_mount, *symlink_mount, *target_over_symlink_mount;
+ gchar *target, *tmp, *target_over_symlink;
+ GError *error = NULL;
+
+ g_test_bug ("1522");
+
+ /* The test assumes that ~/.local always exists. */
+ target = g_build_filename (g_get_home_dir (), ".local", NULL);
+ target_mount = g_unix_mount_for (target, NULL);
+ g_assert_nonnull (target_mount);
+
+ tmp = g_dir_make_tmp ("test-trashXXXXXX", &error);
+ tmp_mount = g_unix_mount_for (tmp, NULL);
+ g_assert_nonnull (tmp_mount);
+
+ if (g_unix_mount_compare (target_mount, tmp_mount) == 0)
+ {
+ g_test_skip ("The tmp has to be on another mount than the home to run this test");
+
+ g_unix_mount_free (tmp_mount);
+ g_free (tmp);
+ g_unix_mount_free (target_mount);
+ g_free (target);
+
+ return;
+ }
+
+ symlink = g_file_new_build_filename (tmp, "symlink", NULL);
+
+ g_file_make_symbolic_link (symlink, g_get_home_dir (), NULL, &error);
+ g_assert_no_error (error);
+
+ target_over_symlink = g_build_filename (g_file_peek_path (symlink),
+ ".local",
+ NULL);
+
+ target_over_symlink_mount = g_unix_mount_for (target_over_symlink, NULL);
+ g_assert (g_unix_mount_compare (target_over_symlink_mount, target_mount) == 0);
+
+ symlink_mount = g_unix_mount_for (g_file_peek_path (symlink), NULL);
+ g_assert (g_unix_mount_compare (symlink_mount, tmp_mount) == 0);
+
+ g_unix_mount_free (target_over_symlink_mount);
+ g_unix_mount_free (symlink_mount);
+ g_free (target_over_symlink);
+ g_object_unref (symlink);
+ g_unix_mount_free (tmp_mount);
+ g_free (tmp);
+ g_unix_mount_free (target_mount);
+ g_free (target);
+}
+
int
main (int argc, char *argv[])
{
@@ -104,6 +161,7 @@ main (int argc, char *argv[])
g_test_bug_base ("https://gitlab.gnome.org/GNOME/glib/issues/");
g_test_add_func ("/trash/not-supported", test_trash_not_supported);
+ g_test_add_func ("/trash/symlinks", test_trash_symlinks);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]