3 * Copyright (C) 2011 Red Hat, Inc
4 * Author: Matthias Clasen
6 * SPDX-License-Identifier: LicenseRef-old-glib-tests
8 * This work is provided "as is"; redistribution and modification
9 * in whole or in part, in any medium, physical or electronic is
10 * permitted without restriction.
12 * This work is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * In no event shall the authors or contributors be liable for any
17 * direct, indirect, incidental, special, exemplary, or consequential
18 * damages (including, but not limited to, procurement of substitute
19 * goods or services; loss of use, data, or profits; or business
20 * interruption) however caused and on any theory of liability, whether
21 * in contract, strict liability, or tort (including negligence or
22 * otherwise) arising in any way out of the use of this software, even
23 * if advised of the possibility of such damage.
29 test_vfs_parse_name (GVfs *vfs,
30 const char *parse_name,
35 if (g_strcmp0 ((parse_name), "testfile") == 0)
37 file = g_file_new_for_uri ("file:///");
38 g_object_set_data (G_OBJECT (file), "testfile", GINT_TO_POINTER (1));
45 test_vfs_lookup (GVfs *vfs,
50 file = g_file_new_for_uri ("file:///");
51 g_object_set_data (G_OBJECT (file), "testfile", GINT_TO_POINTER (1));
57 test_register_scheme (void)
61 const gchar * const *schemes;
64 vfs = g_vfs_get_default ();
65 g_assert_nonnull (vfs);
66 g_assert_true (g_vfs_is_active (vfs));
68 schemes = g_vfs_get_supported_uri_schemes (vfs);
69 g_assert_false (g_strv_contains (schemes, "test"));
71 res = g_vfs_unregister_uri_scheme (vfs, "test");
74 res = g_vfs_register_uri_scheme (vfs, "test",
75 test_vfs_lookup, NULL, NULL,
76 test_vfs_parse_name, NULL, NULL);
79 schemes = g_vfs_get_supported_uri_schemes (vfs);
80 g_assert_true (g_strv_contains (schemes, "test"));
82 file = g_file_new_for_uri ("test:///foo");
83 g_assert_cmpint (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (file), "testfile")), ==, 1);
84 g_object_unref (file);
86 file = g_file_parse_name ("testfile");
87 g_assert_cmpint (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (file), "testfile")), ==, 1);
88 g_object_unref (file);
90 res = g_vfs_register_uri_scheme (vfs, "test",
91 test_vfs_lookup, NULL, NULL,
92 test_vfs_parse_name, NULL, NULL);
95 res = g_vfs_unregister_uri_scheme (vfs, "test");
98 file = g_file_new_for_uri ("test:///foo");
99 g_assert_null (g_object_get_data (G_OBJECT (file), "testfile"));
100 g_object_unref (file);
110 vfs = g_vfs_get_local ();
111 g_assert_true (g_vfs_is_active (vfs));
113 file = g_vfs_get_file_for_uri (vfs, "not a good uri");
114 g_assert_true (G_IS_FILE (file));
115 g_object_unref (file);
117 schemes = (gchar **)g_vfs_get_supported_uri_schemes (vfs);
119 g_assert_cmpuint (g_strv_length (schemes), >, 0);
120 g_assert_cmpstr (schemes[0], ==, "file");
124 test_resource_malformed_escaping (void)
129 g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/3090");
130 g_test_summary ("Test that g_vfs_get_file_for_uri() returns an invalid file for an invalid URI");
132 vfs = g_vfs_get_local ();
133 g_assert_true (g_vfs_is_active (vfs));
135 file = g_vfs_get_file_for_uri (vfs, "resource:///%not-valid-escaping/gtk.css");
136 g_assert_true (G_IS_FILE (file));
138 /* This only returns %NULL if the file was constructed with an invalid URI: */
139 g_assert_null (g_file_get_uri_scheme (file));
141 g_object_unref (file);
145 main (int argc, char *argv[])
147 g_test_init (&argc, &argv, NULL);
149 g_test_add_func ("/gvfs/local", test_local);
150 g_test_add_func ("/gvfs/register-scheme", test_register_scheme);
151 g_test_add_func ("/gvfs/resource/malformed-escaping", test_resource_malformed_escaping);
153 return g_test_run ();