1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | /* test-mime.c - Test for the mime handler detection features of the GNOME |
---|
3 | Virtual File System Library |
---|
4 | |
---|
5 | Copyright (C) 2000 Eazel |
---|
6 | |
---|
7 | The Gnome Library is free software; you can redistribute it and/or |
---|
8 | modify it under the terms of the GNU Library General Public License as |
---|
9 | published by the Free Software Foundation; either version 2 of the |
---|
10 | License, or (at your option) any later version. |
---|
11 | |
---|
12 | The Gnome Library 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. See the GNU |
---|
15 | Library General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU Library General Public |
---|
18 | License along with the Gnome Library; see the file COPYING.LIB. If not, |
---|
19 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
20 | Boston, MA 02111-1307, USA. |
---|
21 | |
---|
22 | Author: Maciej Stachowiak <mjs@eazel.com> |
---|
23 | */ |
---|
24 | #ifdef HAVE_CONFIG_H |
---|
25 | #include <config.h> |
---|
26 | #endif |
---|
27 | |
---|
28 | #include "gnome-vfs.h" |
---|
29 | #include "gnome-vfs-mime-handlers.h" |
---|
30 | #include "gnome-vfs-mime-info.h" |
---|
31 | |
---|
32 | |
---|
33 | #include <stdio.h> |
---|
34 | #include <stdlib.h> |
---|
35 | |
---|
36 | |
---|
37 | int |
---|
38 | main (int argc, char **argv) |
---|
39 | { |
---|
40 | const char *value; |
---|
41 | |
---|
42 | gnome_vfs_init (); |
---|
43 | |
---|
44 | /* test reading of gnome-vfs.keys file */ |
---|
45 | value = gnome_vfs_mime_get_value ("x-directory/normal", "description"); |
---|
46 | if (value == NULL || strcmp (value, "folder") != 0) { |
---|
47 | printf ("Error: get_value failed on \"description\".\n"); |
---|
48 | exit (1); |
---|
49 | } |
---|
50 | value = gnome_vfs_mime_get_value ("x-directory/normal", "default_action_type"); |
---|
51 | if (value == NULL || strcmp (value, "component") != 0) { |
---|
52 | printf ("Error: get_value failed on \"default_action_type\".\n"); |
---|
53 | exit (1); |
---|
54 | } |
---|
55 | value = gnome_vfs_mime_get_value ("x-directory/normal", "default_component_iid"); |
---|
56 | if (value == NULL || strcmp (value, "OAFIID:nautilus_file_manager_icon_view:42681b21-d5ca-4837-87d2-394d88ecc058") != 0) { |
---|
57 | printf ("Error: get_value failed on \"default_component_iid\".\n"); |
---|
58 | exit (1); |
---|
59 | } |
---|
60 | value = gnome_vfs_mime_get_value ("x-directory/normal", "short_list_component_iids_for_novice_user_level"); |
---|
61 | if (value == NULL || strcmp (value, "OAFIID:nautilus_file_manager_icon_view:42681b21-d5ca-4837-87d2-394d88ecc058," |
---|
62 | "OAFIID:nautilus_file_manager_list_view:521e489d-0662-4ad7-ac3a-832deabe111c," |
---|
63 | "OAFIID:nautilus_music_view:9456b5d2-60a8-407f-a56e-d561e1821391") != 0) { |
---|
64 | printf ("Error: get_value failed on \"short_list_component_iids_for_novice_user_level\".\n"); |
---|
65 | exit (1); |
---|
66 | } |
---|
67 | value = gnome_vfs_mime_get_value ("x-directory/normal", "short_list_component_iids_for_intermediate_user_level"); |
---|
68 | if (value == NULL || strcmp (value, "OAFIID:nautilus_file_manager_icon_view:42681b21-d5ca-4837-87d2-394d88ecc058," |
---|
69 | "OAFIID:nautilus_file_manager_list_view:521e489d-0662-4ad7-ac3a-832deabe111c," |
---|
70 | "OAFIID:nautilus_music_view:9456b5d2-60a8-407f-a56e-d561e1821391") != 0) { |
---|
71 | printf ("Error: get_value failed on \"short_list_component_iids_for_intermediate_user_level\".\n"); |
---|
72 | exit (1); |
---|
73 | } |
---|
74 | value = gnome_vfs_mime_get_value ("x-directory/normal", "short_list_component_iids_for_advanced_user_level"); |
---|
75 | if (value == NULL || strcmp (value, "OAFIID:nautilus_file_manager_icon_view:42681b21-d5ca-4837-87d2-394d88ecc058," |
---|
76 | "OAFIID:nautilus_file_manager_list_view:521e489d-0662-4ad7-ac3a-832deabe111c," |
---|
77 | "OAFIID:nautilus_music_view:9456b5d2-60a8-407f-a56e-d561e1821391") != 0) { |
---|
78 | printf ("Error: get_value failed on \"short_list_component_iids_for_advanced_user_level\".\n"); |
---|
79 | exit (1); |
---|
80 | } |
---|
81 | value = gnome_vfs_mime_get_description ("application/mime-type-test"); |
---|
82 | if (value == NULL || strcmp (value, "mon test a moi") != 0) { |
---|
83 | printf ("Error: description failed on \"application/mime-type-test\".\n"); |
---|
84 | exit (1); |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | /* test reading of gnome-vfs.mime file */ |
---|
89 | { |
---|
90 | GList *list, *temp; |
---|
91 | char *extensions[] = {"ps", "eps"}; |
---|
92 | char **extension; |
---|
93 | char *ext; |
---|
94 | list = gnome_vfs_mime_get_extensions_list ("application/postscript"); |
---|
95 | if (list == NULL) { |
---|
96 | printf ("Error: get_extensions_list failed on \"application/postscript\" list NULL.\n"); |
---|
97 | exit (1); |
---|
98 | } |
---|
99 | for (temp = list, extension = extensions; temp != NULL; temp = temp->next, extension++) { |
---|
100 | if (strcmp (*extension, (char *)temp->data) != 0) { |
---|
101 | printf ("Error: get_extensions_list failed on \"application/postscript\".\n"); |
---|
102 | printf ("Wrong value received was %s instead of %s\n", (char *) temp->data, *extension); |
---|
103 | exit (1); |
---|
104 | } |
---|
105 | } |
---|
106 | gnome_vfs_mime_extensions_list_free (list); |
---|
107 | |
---|
108 | ext = gnome_vfs_mime_get_extensions_string ("application/postscript"); |
---|
109 | if (ext == NULL || strcmp (ext, "eps ps") != 0) { |
---|
110 | printf ("Error: get_extensions_string failed on \"application/postscript\".\n"); |
---|
111 | exit (1); |
---|
112 | } |
---|
113 | ext = gnome_vfs_mime_get_extensions_pretty_string ("application/postscript"); |
---|
114 | if (ext == NULL || strcmp (ext, ".ps, .eps") != 0) { |
---|
115 | printf ("Error: get_extensions_pretty_string failed on \"application/postscript\".\n"); |
---|
116 | exit (1); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | /* test writing the users' user.keys file. It should overide the system default */ |
---|
121 | { |
---|
122 | const char *value; |
---|
123 | gnome_vfs_mime_set_value ("application/postscript", |
---|
124 | "foo", |
---|
125 | "bar"); |
---|
126 | value = gnome_vfs_mime_get_value ("application/postscript", |
---|
127 | "foo"); |
---|
128 | if (value == NULL || strcmp (value, "bar") != 0) { |
---|
129 | printf ("%s\n", value); |
---|
130 | printf ("Error: set_value failed on \"application/postscript\" / \"foo\".\n"); |
---|
131 | exit (1); |
---|
132 | } |
---|
133 | |
---|
134 | /* test freeze/thaw for this stuff */ |
---|
135 | gnome_vfs_mime_freeze (); |
---|
136 | gnome_vfs_mime_set_value ("application/postscript", |
---|
137 | "bar", |
---|
138 | "foo"); |
---|
139 | value = gnome_vfs_mime_get_value ("application/postscript", |
---|
140 | "bar"); |
---|
141 | if (value == NULL || strcmp (value, "foo") != 0) { |
---|
142 | printf ("%s\n", value); |
---|
143 | printf ("Error: set_value failed on \"application/postscript\" / \"bar\".\n"); |
---|
144 | exit (1); |
---|
145 | } |
---|
146 | gnome_vfs_mime_thaw (); |
---|
147 | value = gnome_vfs_mime_get_value ("application/postscript", |
---|
148 | "bar"); |
---|
149 | if (value == NULL || strcmp (value, "foo") != 0) { |
---|
150 | printf ("%s\n", value); |
---|
151 | printf ("Error: set_value failed on \"application/postscript\" / \"bar\".\n"); |
---|
152 | exit (1); |
---|
153 | } |
---|
154 | |
---|
155 | /* try to overide system settings.*/ |
---|
156 | gnome_vfs_mime_set_value ("application/postscript", |
---|
157 | "description", |
---|
158 | "bar"); |
---|
159 | value = gnome_vfs_mime_get_value ("application/postscript", |
---|
160 | "description"); |
---|
161 | if (value == NULL || strcmp (value, "bar") != 0) { |
---|
162 | printf ("%s\n", value); |
---|
163 | printf ("Error: set_value failed on \"application/postscript\" / \"description\".\n"); |
---|
164 | exit (1); |
---|
165 | } |
---|
166 | |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | /* test to try to modify the user.mime file */ |
---|
171 | { |
---|
172 | char *value; |
---|
173 | gnome_vfs_mime_set_registered_type_key ("application/postscript", "ext", "foo"); |
---|
174 | |
---|
175 | value = gnome_vfs_mime_get_extensions_string ("application/postscript"); |
---|
176 | |
---|
177 | if (strstr (value, "foo") == NULL) { |
---|
178 | printf ("Error: cannot set mime type new extension.\n"); |
---|
179 | exit (1); |
---|
180 | } |
---|
181 | if (strstr (value, "ps") == NULL) { |
---|
182 | printf ("Error: deleted default mime type extension.\n"); |
---|
183 | exit (1); |
---|
184 | } |
---|
185 | gnome_vfs_mime_set_registered_type_key ("application/postscript", "ext", ""); |
---|
186 | } |
---|
187 | |
---|
188 | { |
---|
189 | GList *mime_types_list; |
---|
190 | char *deleted_mime_type; |
---|
191 | GList *temp; |
---|
192 | gboolean found_mime_type; |
---|
193 | |
---|
194 | mime_types_list = gnome_vfs_get_registered_mime_types (); |
---|
195 | |
---|
196 | if (mime_types_list->data != NULL) { |
---|
197 | /* try to delete a mime type */ |
---|
198 | deleted_mime_type = mime_types_list->data; |
---|
199 | gnome_vfs_mime_registered_mime_type_delete (deleted_mime_type); |
---|
200 | gnome_vfs_mime_registered_mime_type_list_free (mime_types_list); |
---|
201 | mime_types_list = gnome_vfs_get_registered_mime_types (); |
---|
202 | for (temp = mime_types_list; temp != NULL; temp = temp->next) { |
---|
203 | if (strcmp (deleted_mime_type, (char *)temp->data) == 0) { |
---|
204 | printf ("Error: could not delete mime type.\n"); |
---|
205 | exit (1); |
---|
206 | } |
---|
207 | } |
---|
208 | gnome_vfs_mime_registered_mime_type_list_free (mime_types_list); |
---|
209 | |
---|
210 | /* reset to system defaults */ |
---|
211 | gnome_vfs_mime_reset (); |
---|
212 | |
---|
213 | /* try to find the original mime type again */ |
---|
214 | mime_types_list = gnome_vfs_get_registered_mime_types (); |
---|
215 | found_mime_type = FALSE; |
---|
216 | for (temp = mime_types_list; temp != NULL; temp = temp->next) { |
---|
217 | if (strcmp (deleted_mime_type, (char *)temp->data) == 0) { |
---|
218 | found_mime_type = TRUE; |
---|
219 | break; |
---|
220 | } |
---|
221 | } |
---|
222 | if (!found_mime_type) { |
---|
223 | printf ("Error: lost a mime type.\n"); |
---|
224 | exit (1); |
---|
225 | } |
---|
226 | |
---|
227 | } |
---|
228 | |
---|
229 | } |
---|
230 | |
---|
231 | |
---|
232 | /* do hard stuff on the API */ |
---|
233 | |
---|
234 | printf ("all mime-info-related tests succeeded\n"); |
---|
235 | |
---|
236 | return 0; |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | |
---|