tests: Skip some more date tests if translations are not installed
[glib.git] / gio / tests / trash.c
blobec9a9eca6fa0ae94807273a4b8cfc9afb1153746
1 /*
2 * Copyright (C) 2018 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1 of the
7 * licence, or (at your option) any later version.
9 * This is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, see <http://www.gnu.org/licenses/>.
18 #include <glib.h>
20 #ifndef G_OS_UNIX
21 #error This is a Unix-specific test
22 #endif
24 #include <glib/gstdio.h>
25 #include <gio/gio.h>
26 #include <gio/gunixmounts.h>
28 /* Test that g_file_trash() returns G_IO_ERROR_NOT_SUPPORTED for files on system mounts. */
29 static void
30 test_trash_not_supported (void)
32 GFile *file;
33 GFileIOStream *stream;
34 GUnixMountEntry *mount;
35 GFileInfo *info;
36 GError *error = NULL;
37 gboolean ret;
38 GStatBuf file_stat, home_stat;
40 /* The test assumes that tmp file is located on system internal mount. */
41 file = g_file_new_tmp ("test-trashXXXXXX", &stream, &error);
42 g_assert_no_error (error);
43 g_assert_cmpint (g_lstat (g_file_peek_path (file), &file_stat), ==, 0);
44 g_test_message ("File: %s (dev: %lu)", g_file_peek_path (file), file_stat.st_dev);
46 g_assert_cmpint (g_stat (g_get_home_dir (), &home_stat), ==, 0);
47 g_test_message ("Home: %s (dev: %lu)", g_get_home_dir (), home_stat.st_dev);
49 if (file_stat.st_dev == home_stat.st_dev)
51 g_test_skip ("The file has to be on another filesystem than the home trash to run this test");
53 g_object_unref (stream);
54 g_object_unref (file);
56 return;
59 mount = g_unix_mount_for (g_file_peek_path (file), NULL);
60 g_assert_true (mount == NULL || g_unix_mount_is_system_internal (mount));
61 g_test_message ("Mount: %s", (mount != NULL) ? g_unix_mount_get_mount_path (mount) : "(null)");
62 g_clear_pointer (&mount, g_unix_mount_free);
64 /* g_file_trash() shouldn't be supported on system internal mounts,
65 * because those are not monitored by gvfsd-trash.
67 ret = g_file_trash (file, NULL, &error);
68 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
69 g_test_message ("Error: %s", error->message);
70 g_assert_false (ret);
71 g_clear_error (&error);
73 info = g_file_query_info (file,
74 G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH,
75 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
76 NULL,
77 &error);
78 g_assert_no_error (error);
80 g_assert_false (g_file_info_get_attribute_boolean (info,
81 G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH));
83 g_io_stream_close (G_IO_STREAM (stream), NULL, &error);
84 g_assert_no_error (error);
86 g_object_unref (info);
87 g_object_unref (stream);
88 g_object_unref (file);
91 int
92 main (int argc, char *argv[])
94 g_test_init (&argc, &argv, NULL);
96 g_test_bug_base ("htps://gitlab.gnome.org/GNOME/glib/issues/");
97 g_test_bug ("251");
99 g_test_add_func ("/trash/not-supported", test_trash_not_supported);
101 return g_test_run ();