1#include <gio/gio.h>
2
3static GVolumeMonitor *monitor;
4
5static void
6do_mount_tests (GDrive *drive, GVolume *volume, GMount *mount)
7{
8 GDrive *d;
9 GVolume *v;
10 gchar *name;
11 gchar *uuid;
12
13 name = g_mount_get_name (mount);
14 g_assert (name != NULL);
15 g_free (mem: name);
16
17 v = g_mount_get_volume (mount);
18 g_assert (v == volume);
19 if (v != NULL)
20 g_object_unref (object: v);
21
22 d = g_mount_get_drive (mount);
23 g_assert (d == drive);
24 if (d != NULL)
25 g_object_unref (object: d);
26
27 uuid = g_mount_get_uuid (mount);
28 if (uuid)
29 {
30 GMount *m;
31 m = g_volume_monitor_get_mount_for_uuid (volume_monitor: monitor, uuid);
32 g_assert (m == mount);
33 g_object_unref (object: m);
34 g_free (mem: uuid);
35 }
36}
37
38static void
39do_volume_tests (GDrive *drive, GVolume *volume)
40{
41 GDrive *d;
42 gchar *name;
43 GMount *mount;
44 gchar *uuid;
45
46 name = g_volume_get_name (volume);
47 g_assert (name != NULL);
48 g_free (mem: name);
49
50 d = g_volume_get_drive (volume);
51 g_assert (d == drive);
52 if (d != NULL)
53 g_object_unref (object: d);
54
55 mount = g_volume_get_mount (volume);
56 if (mount != NULL)
57 {
58 do_mount_tests (drive, volume, mount);
59 g_object_unref (object: mount);
60 }
61
62 uuid = g_volume_get_uuid (volume);
63 if (uuid)
64 {
65 GVolume *v;
66 v = g_volume_monitor_get_volume_for_uuid (volume_monitor: monitor, uuid);
67 g_assert (v == volume);
68 g_object_unref (object: v);
69 g_free (mem: uuid);
70 }
71}
72
73static void
74do_drive_tests (GDrive *drive)
75{
76 GList *volumes, *l;
77 gchar *name;
78 gboolean has_volumes;
79
80 g_assert (G_IS_DRIVE (drive));
81 name = g_drive_get_name (drive);
82 g_assert (name != NULL);
83 g_free (mem: name);
84
85 has_volumes = g_drive_has_volumes (drive);
86 volumes = g_drive_get_volumes (drive);
87 g_assert (has_volumes == (volumes != NULL));
88 for (l = volumes; l; l = l->next)
89 {
90 GVolume *volume = l->data;
91 do_volume_tests (drive, volume);
92 }
93
94 g_list_free_full (list: volumes, free_func: g_object_unref);
95}
96
97static void
98test_connected_drives (void)
99{
100 GList *drives;
101 GList *l;
102
103 drives = g_volume_monitor_get_connected_drives (volume_monitor: monitor);
104
105 for (l = drives; l; l = l->next)
106 {
107 GDrive *drive = l->data;
108 do_drive_tests (drive);
109 }
110
111 g_list_free_full (list: drives, free_func: g_object_unref);
112}
113
114static void
115test_volumes (void)
116{
117 GList *volumes, *l;
118
119 volumes = g_volume_monitor_get_volumes (volume_monitor: monitor);
120
121 for (l = volumes; l; l = l->next)
122 {
123 GVolume *volume = l->data;
124 GDrive *drive;
125
126 drive = g_volume_get_drive (volume);
127 do_volume_tests (drive, volume);
128 if (drive != NULL)
129 g_object_unref (object: drive);
130 }
131
132 g_list_free_full (list: volumes, free_func: g_object_unref);
133}
134
135static void
136test_mounts (void)
137{
138 GList *mounts, *l;
139
140 mounts = g_volume_monitor_get_mounts (volume_monitor: monitor);
141
142 for (l = mounts; l; l = l->next)
143 {
144 GMount *mount = l->data;
145 GVolume *volume;
146 GDrive *drive;
147
148 drive = g_mount_get_drive (mount);
149 volume = g_mount_get_volume (mount);
150 do_mount_tests (drive, volume, mount);
151
152 if (drive != NULL)
153 g_object_unref (object: drive);
154 if (volume != NULL)
155 g_object_unref (object: volume);
156 }
157
158 g_list_free_full (list: mounts, free_func: g_object_unref);
159}
160int
161main (int argc, char *argv[])
162{
163 gboolean ret;
164
165 g_setenv (variable: "GIO_USE_VFS", value: "local", FALSE);
166
167 g_test_init (argc: &argc, argv: &argv, NULL);
168
169 monitor = g_volume_monitor_get ();
170
171 g_test_add_func (testpath: "/volumemonitor/connected_drives", test_func: test_connected_drives);
172 g_test_add_func (testpath: "/volumemonitor/volumes", test_func: test_volumes);
173 g_test_add_func (testpath: "/volumemonitor/mounts", test_func: test_mounts);
174
175 ret = g_test_run ();
176
177 g_object_unref (object: monitor);
178
179 return ret;
180}
181

source code of gtk/subprojects/glib/gio/tests/volumemonitor.c