diff options
author | Ondrej Holy <oholy@redhat.com> | 2018-06-05 09:09:12 +0200 |
---|---|---|
committer | Ondrej Holy <oholy@redhat.com> | 2018-06-05 10:52:57 +0200 |
commit | b7ccb9f55ffd8def9e788f80597e23415b6efe88 (patch) | |
tree | 20f7a481edf8e215493bacc42b8f88826f6acbe9 | |
parent | f0b655fb8cc7a68190bd1a64ce8fe6b00abc0341 (diff) | |
download | glib-wip/oholy/trashing-locations.tar.gz |
glocalfile: Add test case for g_file_trashwip/oholy/trashing-locations
g_local_file_trash has been changed to return G_IO_ERROR_NOT_SUPPORTED
for locations on system-internal mounts. Let's verify that.
https://gitlab.gnome.org/GNOME/glib/issues/251
-rw-r--r-- | gio/tests/Makefile.am | 1 | ||||
-rw-r--r-- | gio/tests/trash.c | 68 |
2 files changed, 69 insertions, 0 deletions
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am index 410f11d95..599823893 100644 --- a/gio/tests/Makefile.am +++ b/gio/tests/Makefile.am @@ -273,6 +273,7 @@ test_programs += \ unix-mounts \ unix-streams \ g-file-info-filesystem-readonly \ + trash \ $(NULL) test_extra_programs += \ diff --git a/gio/tests/trash.c b/gio/tests/trash.c new file mode 100644 index 000000000..771794b49 --- /dev/null +++ b/gio/tests/trash.c @@ -0,0 +1,68 @@ +#include <glib.h> + +#ifndef G_OS_UNIX +#error This is a Unix-specific test +#endif + +#include <gio/gio.h> +#include <gio/gunixmounts.h> + +static void +test_trash_not_supported (void) +{ + GFile *file; + GFileIOStream *stream; + GUnixMountEntry *mount; + GFileInfo *info; + GError *error = NULL; + + /* The test assumes that tmp file is located on system internal mount. */ + file = g_file_new_tmp ("test-trashXXXXXX", &stream, &error); + g_assert_no_error (error); + + g_assert_true (g_file_query_exists (file, NULL)); + + mount = g_unix_mount_for (g_file_peek_path (file), NULL); + g_assert_nonnull (mount); + + g_assert (g_unix_mount_is_system_internal (mount)); + g_unix_mount_free (mount); + + /* g_file_trash() shouldn't be supported on system internal mounts, + * because those are not monitored by gvfsd-trash. + */ + g_file_trash (file, NULL, &error); + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED); + g_test_message ("Error: %s", error->message); + g_clear_error (&error); + + info = g_file_query_info (file, + G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH, + G_FILE_QUERY_INFO_NONE, + NULL, + &error); + g_assert_no_error (error); + + g_assert_false (g_file_info_get_attribute_boolean (info, + G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH)); + + g_io_stream_close (G_IO_STREAM (stream), NULL, &error); + g_assert_no_error (error); + + g_object_unref (stream); + g_object_unref (file); +} + +int +main (int argc, char *argv[]) +{ + g_test_init (&argc, &argv, NULL); + + g_test_bug_base ("htps://gitlab.gnome.org/GNOME/glib/issues/"); + g_test_bug ("251"); + + g_test_add_func ("/trash/not-supported", test_trash_not_supported); + + return g_test_run (); +} + |