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
5 Copyright (C) 2000 Eazel
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.
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.
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.
22 Author: Maciej Stachowiak <mjs@eazel.com>
27 #include <libgnomevfs/gnome-vfs-init.h>
28 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
29 #include <libgnomevfs/gnome-vfs-mime-info.h>
35 main (int argc, char **argv)
41 /* test reading of gnome-vfs.keys file */
42 value = gnome_vfs_mime_get_value ("x-directory/normal", "description");
43 if (value == NULL || strcmp (value, "folder") != 0) {
44 printf ("Error: get_value failed on \"description\".\n");
47 value = gnome_vfs_mime_get_value ("x-directory/normal", "default_action_type");
48 if (value == NULL || strcmp (value, "component") != 0) {
49 printf ("Error: get_value failed on \"default_action_type\".\n");
52 /* default_component_iid doesn't appear anymore in gnome-vfs.keys */
54 value = gnome_vfs_mime_get_value ("x-directory/normal", "default_component_iid");
55 if (value == NULL || strcmp (value, "OAFIID:nautilus_file_manager_icon_view:42681b21-d5ca-4837-87d2-394d88ecc058") != 0) {
56 printf ("Error: get_value failed on \"default_component_iid\".\n");
60 value = gnome_vfs_mime_get_value ("x-directory/normal", "short_list_component_iids_for_novice_user_level");
61 if (value == NULL || strcmp (value,
62 "OAFIID:nautilus_file_manager_icon_view:42681b21-d5ca-4837-87d2-394d88ecc058,"
63 "OAFIID:nautilus_file_manager_list_view:521e489d-0662-4ad7-ac3a-832deabe111c,"
64 "OAFIID:nautilus_music_view:9456b5d2-60a8-407f-a56e-d561e1821391:OAFIID") != 0) {
65 printf ("Error: get_value failed on \"short_list_component_iids_for_novice_user_level\".\n");
68 value = gnome_vfs_mime_get_value ("x-directory/normal", "short_list_component_iids_for_intermediate_user_level");
69 if (value == NULL || strcmp (value, "OAFIID:nautilus_file_manager_icon_view:42681b21-d5ca-4837-87d2-394d88ecc058,"
70 "OAFIID:nautilus_file_manager_list_view:521e489d-0662-4ad7-ac3a-832deabe111c,"
71 "OAFIID:nautilus_music_view:9456b5d2-60a8-407f-a56e-d561e1821391") != 0) {
72 printf ("Error: get_value failed on \"short_list_component_iids_for_intermediate_user_level\".\n");
75 value = gnome_vfs_mime_get_value ("x-directory/normal", "short_list_component_iids_for_advanced_user_level");
76 if (value == NULL || strcmp (value, "OAFIID:nautilus_file_manager_icon_view:42681b21-d5ca-4837-87d2-394d88ecc058,"
77 "OAFIID:nautilus_file_manager_list_view:521e489d-0662-4ad7-ac3a-832deabe111c,"
78 "OAFIID:nautilus_music_view:9456b5d2-60a8-407f-a56e-d561e1821391") != 0) {
79 printf ("Error: get_value failed on \"short_list_component_iids_for_advanced_user_level\".\n");
82 value = gnome_vfs_mime_get_description ("application/mime-type-test");
83 if (value == NULL || strcmp (value, "mon test a moi") != 0) {
84 printf ("Error: description failed on \"application/mime-type-test\".\n");
89 /* test reading of gnome-vfs.mime file */
92 char *extensions[] = {"ps", "eps"};
95 list = gnome_vfs_mime_get_extensions_list ("application/postscript");
97 printf ("Error: get_extensions_list failed on \"application/postscript\" list NULL.\n");
100 for (temp = list, extension = extensions; temp != NULL; temp = temp->next, extension++) {
101 if (strcmp (*extension, (char *)temp->data) != 0) {
102 printf ("Error: get_extensions_list failed on \"application/postscript\".\n");
103 printf ("Wrong value received was %s instead of %s\n", (char *) temp->data, *extension);
107 gnome_vfs_mime_extensions_list_free (list);
109 ext = gnome_vfs_mime_get_extensions_string ("application/postscript");
110 if (ext == NULL || strcmp (ext, "eps ps") != 0) {
111 printf ("Error: get_extensions_string failed on \"application/postscript\".\n");
114 ext = gnome_vfs_mime_get_extensions_pretty_string ("application/postscript");
115 if (ext == NULL || strcmp (ext, ".ps, .eps") != 0) {
116 printf ("Error: get_extensions_pretty_string failed on \"application/postscript\".\n");
121 /* test writing the users' user.keys file. It should overide the system default */
124 gnome_vfs_mime_set_value ("application/postscript",
127 value = gnome_vfs_mime_get_value ("application/postscript",
129 if (value == NULL || strcmp (value, "bar") != 0) {
130 printf ("%s\n", value);
131 printf ("Error: set_value failed on \"application/postscript\" / \"foo\".\n");
135 /* test freeze/thaw for this stuff */
136 gnome_vfs_mime_freeze ();
137 gnome_vfs_mime_set_value ("application/postscript",
140 value = gnome_vfs_mime_get_value ("application/postscript",
142 if (value == NULL || strcmp (value, "foo") != 0) {
143 printf ("%s\n", value);
144 printf ("Error: set_value failed on \"application/postscript\" / \"bar\".\n");
147 gnome_vfs_mime_thaw ();
148 value = gnome_vfs_mime_get_value ("application/postscript",
150 if (value == NULL || strcmp (value, "foo") != 0) {
151 printf ("%s\n", value);
152 printf ("Error: set_value failed on \"application/postscript\" / \"bar\".\n");
156 /* try to overide system settings.*/
157 gnome_vfs_mime_set_value ("application/postscript",
160 value = gnome_vfs_mime_get_value ("application/postscript",
162 if (value == NULL || strcmp (value, "bar") != 0) {
163 printf ("%s\n", value);
164 printf ("Error: set_value failed on \"application/postscript\" / \"description\".\n");
171 /* test to try to modify the user.mime file */
175 save = gnome_vfs_mime_get_extensions_string ("application/postscript");
176 gnome_vfs_mime_set_registered_type_key ("application/postscript", "ext", "foo");
178 value = gnome_vfs_mime_get_extensions_string ("application/postscript");
180 if (strstr (value, "foo") == NULL) {
181 printf ("Error: cannot set mime type new extension.\n");
184 if (strstr (value, "ps") != NULL) {
185 printf ("Error: didn't delete default mime type extension.\n");
188 gnome_vfs_mime_set_registered_type_key ("application/postscript", "ext", save);
192 GList *mime_types_list;
193 char *deleted_mime_type;
195 gboolean found_mime_type;
197 mime_types_list = gnome_vfs_get_registered_mime_types ();
199 if (mime_types_list->data != NULL) {
200 /* try to delete a mime type */
201 deleted_mime_type = mime_types_list->data;
202 gnome_vfs_mime_registered_mime_type_delete (deleted_mime_type);
203 gnome_vfs_mime_registered_mime_type_list_free (mime_types_list);
204 mime_types_list = gnome_vfs_get_registered_mime_types ();
205 for (temp = mime_types_list; temp != NULL; temp = temp->next) {
206 if (strcmp (deleted_mime_type, (char *)temp->data) == 0) {
207 printf ("Error: could not delete mime type.\n");
211 gnome_vfs_mime_registered_mime_type_list_free (mime_types_list);
213 /* reset to system defaults */
214 gnome_vfs_mime_reset ();
216 /* try to find the original mime type again */
217 mime_types_list = gnome_vfs_get_registered_mime_types ();
218 found_mime_type = FALSE;
219 for (temp = mime_types_list; temp != NULL; temp = temp->next) {
220 if (strcmp (deleted_mime_type, (char *)temp->data) == 0) {
221 found_mime_type = TRUE;
225 if (!found_mime_type) {
226 printf ("Error: lost a mime type.\n");
234 /* do hard stuff on the API */
236 printf ("all mime-info-related tests succeeded\n");