3 * Copyright (C) 2011 Red Hat, Inc
4 * Author: Matthias Clasen
6 * This work is provided "as is"; redistribution and modification
7 * in whole or in part, in any medium, physical or electronic is
8 * permitted without restriction.
10 * This work is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * In no event shall the authors or contributors be liable for any
15 * direct, indirect, incidental, special, exemplary, or consequential
16 * damages (including, but not limited to, procurement of substitute
17 * goods or services; loss of use, data, or profits; or business
18 * interruption) however caused and on any theory of liability, whether
19 * in contract, strict liability, or tort (including negligence or
20 * otherwise) arising in any way out of the use of this software, even
21 * if advised of the possibility of such damage.
27 test_vfs_parse_name (GVfs
*vfs
,
28 const char *parse_name
,
33 if (g_strcmp0 ((parse_name
), "testfile") == 0)
35 file
= g_file_new_for_uri ("file:///");
36 g_object_set_data (G_OBJECT (file
), "testfile", GINT_TO_POINTER (1));
43 test_vfs_lookup (GVfs
*vfs
,
48 file
= g_file_new_for_uri ("file:///");
49 g_object_set_data (G_OBJECT (file
), "testfile", GINT_TO_POINTER (1));
55 test_register_scheme (void)
59 const gchar
* const *schemes
;
62 vfs
= g_vfs_get_default ();
63 g_assert_nonnull (vfs
);
64 g_assert_true (g_vfs_is_active (vfs
));
66 schemes
= g_vfs_get_supported_uri_schemes (vfs
);
67 g_assert_false (g_strv_contains (schemes
, "test"));
69 res
= g_vfs_unregister_uri_scheme (vfs
, "test");
72 res
= g_vfs_register_uri_scheme (vfs
, "test",
73 test_vfs_lookup
, NULL
, NULL
,
74 test_vfs_parse_name
, NULL
, NULL
);
77 schemes
= g_vfs_get_supported_uri_schemes (vfs
);
78 g_assert_true (g_strv_contains (schemes
, "test"));
80 file
= g_file_new_for_uri ("test:///foo");
81 g_assert_cmpint (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (file
), "testfile")), ==, 1);
82 g_object_unref (file
);
84 file
= g_file_parse_name ("testfile");
85 g_assert_cmpint (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (file
), "testfile")), ==, 1);
86 g_object_unref (file
);
88 res
= g_vfs_register_uri_scheme (vfs
, "test",
89 test_vfs_lookup
, NULL
, NULL
,
90 test_vfs_parse_name
, NULL
, NULL
);
93 res
= g_vfs_unregister_uri_scheme (vfs
, "test");
96 file
= g_file_new_for_uri ("test:///foo");
97 g_assert_null (g_object_get_data (G_OBJECT (file
), "testfile"));
98 g_object_unref (file
);
108 vfs
= g_vfs_get_local ();
109 g_assert (g_vfs_is_active (vfs
));
111 file
= g_vfs_get_file_for_uri (vfs
, "not a good uri");
112 g_assert (G_IS_FILE (file
));
113 g_object_unref (file
);
115 schemes
= (gchar
**)g_vfs_get_supported_uri_schemes (vfs
);
117 g_assert (g_strv_length (schemes
) > 0);
118 g_assert_cmpstr (schemes
[0], ==, "file");
122 main (int argc
, char *argv
[])
124 g_test_init (&argc
, &argv
, NULL
);
126 g_test_add_func ("/gvfs/local", test_local
);
127 g_test_add_func ("/gvfs/register-scheme", test_register_scheme
);
129 return g_test_run ();