4 #define g_assert_content_type_equals(s1, s2) \
6 const char *__s1 = (s1), *__s2 = (s2); \
7 if (g_content_type_equals (__s1, __s2)) ; \
9 g_assertion_message_cmpstr (G_LOG_DOMAIN, \
13 __s1, " == ", __s2); \
21 gchar
*existing_directory
;
27 "Exec=./appinfo-test --option\n";
30 existing_directory
= (gchar
*) g_getenv ("SYSTEMROOT");
32 if (existing_directory
)
33 existing_directory
= g_strdup_printf ("%s/", existing_directory
);
35 existing_directory
= g_strdup ("/etc/");
38 res
= g_content_type_guess (existing_directory
, NULL
, 0, &uncertain
);
39 g_free (existing_directory
);
40 expected
= g_content_type_from_mime_type ("inode/directory");
41 g_assert_content_type_equals (expected
, res
);
46 res
= g_content_type_guess ("foo.txt", NULL
, 0, &uncertain
);
47 expected
= g_content_type_from_mime_type ("text/plain");
48 g_assert_content_type_equals (expected
, res
);
52 res
= g_content_type_guess ("foo.txt", data
, sizeof (data
) - 1, &uncertain
);
53 expected
= g_content_type_from_mime_type ("text/plain");
54 g_assert_content_type_equals (expected
, res
);
55 g_assert (!uncertain
);
59 res
= g_content_type_guess ("foo", data
, sizeof (data
) - 1, &uncertain
);
60 expected
= g_content_type_from_mime_type ("text/plain");
61 g_assert_content_type_equals (expected
, res
);
62 g_assert (!uncertain
);
66 /* Sadly OSX just doesn't have as large and robust of a mime type database as Linux */
68 res
= g_content_type_guess ("foo.desktop", data
, sizeof (data
) - 1, &uncertain
);
69 expected
= g_content_type_from_mime_type ("application/x-desktop");
70 g_assert_content_type_equals (expected
, res
);
71 g_assert (!uncertain
);
75 res
= g_content_type_guess (NULL
, data
, sizeof (data
) - 1, &uncertain
);
76 expected
= g_content_type_from_mime_type ("application/x-desktop");
77 g_assert_content_type_equals (expected
, res
);
78 g_assert (!uncertain
);
82 /* this is potentially ambiguous: it does not match the PO template format,
83 * but looks like text so it can't be Powerpoint */
84 res
= g_content_type_guess ("test.pot", (guchar
*)"ABC abc", 7, &uncertain
);
85 expected
= g_content_type_from_mime_type ("text/x-gettext-translation-template");
86 g_assert_content_type_equals (expected
, res
);
87 g_assert (!uncertain
);
91 res
= g_content_type_guess ("test.pot", (guchar
*)"msgid \"", 7, &uncertain
);
92 expected
= g_content_type_from_mime_type ("text/x-gettext-translation-template");
93 g_assert_content_type_equals (expected
, res
);
94 g_assert (!uncertain
);
98 res
= g_content_type_guess ("test.pot", (guchar
*)"\xCF\xD0\xE0\x11", 4, &uncertain
);
99 expected
= g_content_type_from_mime_type ("application/vnd.ms-powerpoint");
100 g_assert_content_type_equals (expected
, res
);
101 /* we cannot reliably detect binary powerpoint files as long as there is no
102 * defined MIME magic, so do not check uncertain here
107 res
= g_content_type_guess ("test.otf", (guchar
*)"OTTO", 4, &uncertain
);
108 expected
= g_content_type_from_mime_type ("application/x-font-otf");
109 g_assert_content_type_equals (expected
, res
);
110 g_assert (!uncertain
);
114 res
= g_content_type_guess (NULL
, (guchar
*)"%!PS-Adobe-2.0 EPSF-1.2", 23, &uncertain
);
115 expected
= g_content_type_from_mime_type ("image/x-eps");
116 g_assert_content_type_equals (expected
, res
);
117 g_assert (!uncertain
);
129 unknown
= g_content_type_from_mime_type ("application/octet-stream");
130 g_assert (g_content_type_is_unknown (unknown
));
131 str
= g_content_type_get_mime_type (unknown
);
132 g_assert_cmpstr (str
, ==, "application/octet-stream");
143 plain
= g_content_type_from_mime_type ("text/plain");
144 xml
= g_content_type_from_mime_type ("application/xml");
146 g_assert (g_content_type_is_a (xml
, plain
));
147 g_assert (g_content_type_is_mime_type (xml
, "text/plain"));
154 find_mime (gconstpointer a
, gconstpointer b
)
156 if (g_content_type_equals (a
, b
))
169 g_test_skip ("The OSX backend does not implement g_content_types_get_registered()");
173 plain
= g_content_type_from_mime_type ("text/plain");
174 xml
= g_content_type_from_mime_type ("application/xml");
176 types
= g_content_types_get_registered ();
178 g_assert (g_list_length (types
) > 1);
180 /* just check that some types are in the list */
181 g_assert (g_list_find_custom (types
, plain
, find_mime
) != NULL
);
182 g_assert (g_list_find_custom (types
, xml
, find_mime
) != NULL
);
184 g_list_free_full (types
, g_free
);
191 test_executable (void)
195 type
= g_content_type_from_mime_type ("application/x-executable");
196 g_assert (g_content_type_can_be_executable (type
));
199 type
= g_content_type_from_mime_type ("text/plain");
200 g_assert (g_content_type_can_be_executable (type
));
203 type
= g_content_type_from_mime_type ("image/png");
204 g_assert (!g_content_type_can_be_executable (type
));
209 test_description (void)
214 type
= g_content_type_from_mime_type ("text/plain");
215 desc
= g_content_type_get_description (type
);
216 g_assert (desc
!= NULL
);
228 type
= g_content_type_from_mime_type ("text/plain");
229 icon
= g_content_type_get_icon (type
);
230 g_assert (G_IS_ICON (icon
));
231 if (G_IS_THEMED_ICON (icon
))
233 const gchar
*const *names
;
235 names
= g_themed_icon_get_names (G_THEMED_ICON (icon
));
236 g_assert (g_strv_contains (names
, "text-plain"));
237 g_assert (g_strv_contains (names
, "text-x-generic"));
239 g_object_unref (icon
);
242 type
= g_content_type_from_mime_type ("application/rtf");
243 icon
= g_content_type_get_icon (type
);
244 g_assert (G_IS_ICON (icon
));
245 if (G_IS_THEMED_ICON (icon
))
247 const gchar
*const *names
;
249 names
= g_themed_icon_get_names (G_THEMED_ICON (icon
));
250 g_assert (g_strv_contains (names
, "application-rtf"));
251 g_assert (g_strv_contains (names
, "x-office-document"));
253 g_object_unref (icon
);
258 test_symbolic_icon (void)
264 type
= g_content_type_from_mime_type ("text/plain");
265 icon
= g_content_type_get_symbolic_icon (type
);
266 g_assert (G_IS_ICON (icon
));
267 if (G_IS_THEMED_ICON (icon
))
269 const gchar
*const *names
;
271 names
= g_themed_icon_get_names (G_THEMED_ICON (icon
));
272 g_assert (g_strv_contains (names
, "text-plain-symbolic"));
273 g_assert (g_strv_contains (names
, "text-x-generic-symbolic"));
274 g_assert (g_strv_contains (names
, "text-plain"));
275 g_assert (g_strv_contains (names
, "text-x-generic"));
277 g_object_unref (icon
);
280 type
= g_content_type_from_mime_type ("application/rtf");
281 icon
= g_content_type_get_symbolic_icon (type
);
282 g_assert (G_IS_ICON (icon
));
283 if (G_IS_THEMED_ICON (icon
))
285 const gchar
*const *names
;
287 names
= g_themed_icon_get_names (G_THEMED_ICON (icon
));
288 g_assert (g_strv_contains (names
, "application-rtf-symbolic"));
289 g_assert (g_strv_contains (names
, "x-office-document-symbolic"));
290 g_assert (g_strv_contains (names
, "application-rtf"));
291 g_assert (g_strv_contains (names
, "x-office-document"));
293 g_object_unref (icon
);
301 const gchar
*tests
[] = {
302 "x-content/image-dcf",
303 "x-content/unix-software",
304 "x-content/win32-software"
312 g_test_skip ("The OSX backend does not implement g_content_type_guess_for_tree()");
316 for (i
= 0; i
< G_N_ELEMENTS (tests
); i
++)
318 path
= g_test_get_filename (G_TEST_DIST
, tests
[i
], NULL
);
319 file
= g_file_new_for_path (path
);
320 types
= g_content_type_guess_for_tree (file
);
321 g_assert_content_type_equals (types
[0], tests
[i
]);
323 g_object_unref (file
);
328 test_type_is_a_special_case (void)
332 g_test_bug ("782311");
334 /* Everything but the inode type is application/octet-stream */
335 res
= g_content_type_is_a ("inode/directory", "application/octet-stream");
336 g_assert_false (res
);
337 res
= g_content_type_is_a ("anything", "application/octet-stream");
342 main (int argc
, char *argv
[])
344 g_test_init (&argc
, &argv
, NULL
);
346 g_test_bug_base ("http://bugzilla.gnome.org/");
348 g_test_add_func ("/contenttype/guess", test_guess
);
349 g_test_add_func ("/contenttype/unknown", test_unknown
);
350 g_test_add_func ("/contenttype/subtype", test_subtype
);
351 g_test_add_func ("/contenttype/list", test_list
);
352 g_test_add_func ("/contenttype/executable", test_executable
);
353 g_test_add_func ("/contenttype/description", test_description
);
354 g_test_add_func ("/contenttype/icon", test_icon
);
355 g_test_add_func ("/contenttype/symbolic-icon", test_symbolic_icon
);
356 g_test_add_func ("/contenttype/tree", test_tree
);
357 g_test_add_func ("/contenttype/test_type_is_a_special_case",
358 test_type_is_a_special_case
);
360 return g_test_run ();