Update German translation
[glib.git] / gio / tests / vfs.c
blobb8a850decb0010ea00a173e74658744d1209efd1
2 /* Unit tests for GVfs
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.
24 #include <gio/gio.h>
26 static GFile *
27 test_vfs_parse_name (GVfs *vfs,
28 const char *parse_name,
29 gpointer user_data)
31 GFile *file = NULL;
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));
39 return file;
42 static GFile *
43 test_vfs_lookup (GVfs *vfs,
44 const char *uri,
45 gpointer user_data)
47 GFile *file;
48 file = g_file_new_for_uri ("file:///");
49 g_object_set_data (G_OBJECT (file), "testfile", GINT_TO_POINTER (1));
51 return file;
54 static void
55 test_register_scheme (void)
57 GVfs *vfs;
58 GFile *file;
59 const gchar * const *schemes;
60 gboolean res;
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");
70 g_assert_false (res);
72 res = g_vfs_register_uri_scheme (vfs, "test",
73 test_vfs_lookup, NULL, NULL,
74 test_vfs_parse_name, NULL, NULL);
75 g_assert_true (res);
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);
91 g_assert_false (res);
93 res = g_vfs_unregister_uri_scheme (vfs, "test");
94 g_assert_true (res);
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);
101 static void
102 test_local (void)
104 GVfs *vfs;
105 GFile *file;
106 gchar **schemes;
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 ();