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.desktop", data
, sizeof (data
) - 1, &uncertain
);
53 expected
= g_content_type_from_mime_type ("application/x-desktop");
54 g_assert_content_type_equals (expected
, res
);
55 g_assert (!uncertain
);
59 res
= g_content_type_guess ("foo.txt", 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 res
= g_content_type_guess ("foo", data
, sizeof (data
) - 1, &uncertain
);
67 expected
= g_content_type_from_mime_type ("text/plain");
68 g_assert_content_type_equals (expected
, res
);
69 g_assert (!uncertain
);
73 res
= g_content_type_guess (NULL
, data
, sizeof (data
) - 1, &uncertain
);
74 expected
= g_content_type_from_mime_type ("application/x-desktop");
75 g_assert_content_type_equals (expected
, res
);
76 g_assert (!uncertain
);
80 /* this is potentially ambiguous: it does not match the PO template format,
81 * but looks like text so it can't be Powerpoint */
82 res
= g_content_type_guess ("test.pot", (guchar
*)"ABC abc", 7, &uncertain
);
83 expected
= g_content_type_from_mime_type ("text/x-gettext-translation-template");
84 g_assert_content_type_equals (expected
, res
);
85 g_assert (!uncertain
);
89 res
= g_content_type_guess ("test.pot", (guchar
*)"msgid \"", 7, &uncertain
);
90 expected
= g_content_type_from_mime_type ("text/x-gettext-translation-template");
91 g_assert_content_type_equals (expected
, res
);
92 g_assert (!uncertain
);
96 res
= g_content_type_guess ("test.pot", (guchar
*)"\xCF\xD0\xE0\x11", 4, &uncertain
);
97 expected
= g_content_type_from_mime_type ("application/vnd.ms-powerpoint");
98 g_assert_content_type_equals (expected
, res
);
99 /* we cannot reliably detect binary powerpoint files as long as there is no
100 * defined MIME magic, so do not check uncertain here
105 res
= g_content_type_guess ("test.otf", (guchar
*)"OTTO", 4, &uncertain
);
106 expected
= g_content_type_from_mime_type ("application/x-font-otf");
107 g_assert_content_type_equals (expected
, res
);
108 g_assert (!uncertain
);
112 res
= g_content_type_guess (NULL
, (guchar
*)"%!PS-Adobe-2.0 EPSF-1.2", 23, &uncertain
);
113 expected
= g_content_type_from_mime_type ("image/x-eps");
114 g_assert_content_type_equals (expected
, res
);
115 g_assert (!uncertain
);
126 unknown
= g_content_type_from_mime_type ("application/octet-stream");
127 g_assert (g_content_type_is_unknown (unknown
));
128 str
= g_content_type_get_mime_type (unknown
);
129 g_assert_cmpstr (str
, ==, "application/octet-stream");
140 plain
= g_content_type_from_mime_type ("text/plain");
141 xml
= g_content_type_from_mime_type ("application/xml");
143 g_assert (g_content_type_is_a (xml
, plain
));
150 find_mime (gconstpointer a
, gconstpointer b
)
152 if (g_content_type_equals (a
, b
))
164 plain
= g_content_type_from_mime_type ("text/plain");
165 xml
= g_content_type_from_mime_type ("application/xml");
167 types
= g_content_types_get_registered ();
169 g_assert (g_list_length (types
) > 1);
171 /* just check that some types are in the list */
172 g_assert (g_list_find_custom (types
, plain
, find_mime
) != NULL
);
173 g_assert (g_list_find_custom (types
, xml
, find_mime
) != NULL
);
175 g_list_free_full (types
, g_free
);
182 test_executable (void)
186 type
= g_content_type_from_mime_type ("application/x-executable");
187 g_assert (g_content_type_can_be_executable (type
));
190 type
= g_content_type_from_mime_type ("text/plain");
191 g_assert (g_content_type_can_be_executable (type
));
194 type
= g_content_type_from_mime_type ("image/png");
195 g_assert (!g_content_type_can_be_executable (type
));
200 test_description (void)
205 type
= g_content_type_from_mime_type ("text/plain");
206 desc
= g_content_type_get_description (type
);
207 g_assert (desc
!= NULL
);
219 type
= g_content_type_from_mime_type ("text/plain");
220 icon
= g_content_type_get_icon (type
);
221 g_assert (G_IS_ICON (icon
));
222 if (G_IS_THEMED_ICON (icon
))
224 const gchar
*const *names
;
226 names
= g_themed_icon_get_names (G_THEMED_ICON (icon
));
227 g_assert (g_strv_contains (names
, "text-plain"));
228 g_assert (g_strv_contains (names
, "text-x-generic"));
230 g_object_unref (icon
);
233 type
= g_content_type_from_mime_type ("application/rtf");
234 icon
= g_content_type_get_icon (type
);
235 g_assert (G_IS_ICON (icon
));
236 if (G_IS_THEMED_ICON (icon
))
238 const gchar
*const *names
;
240 names
= g_themed_icon_get_names (G_THEMED_ICON (icon
));
241 g_assert (g_strv_contains (names
, "application-rtf"));
242 g_assert (g_strv_contains (names
, "x-office-document"));
244 g_object_unref (icon
);
249 test_symbolic_icon (void)
255 type
= g_content_type_from_mime_type ("text/plain");
256 icon
= g_content_type_get_symbolic_icon (type
);
257 g_assert (G_IS_ICON (icon
));
258 if (G_IS_THEMED_ICON (icon
))
260 const gchar
*const *names
;
262 names
= g_themed_icon_get_names (G_THEMED_ICON (icon
));
263 g_assert (g_strv_contains (names
, "text-plain-symbolic"));
264 g_assert (g_strv_contains (names
, "text-x-generic-symbolic"));
265 g_assert (g_strv_contains (names
, "text-plain"));
266 g_assert (g_strv_contains (names
, "text-x-generic"));
268 g_object_unref (icon
);
271 type
= g_content_type_from_mime_type ("application/rtf");
272 icon
= g_content_type_get_symbolic_icon (type
);
273 g_assert (G_IS_ICON (icon
));
274 if (G_IS_THEMED_ICON (icon
))
276 const gchar
*const *names
;
278 names
= g_themed_icon_get_names (G_THEMED_ICON (icon
));
279 g_assert (g_strv_contains (names
, "application-rtf-symbolic"));
280 g_assert (g_strv_contains (names
, "x-office-document-symbolic"));
281 g_assert (g_strv_contains (names
, "application-rtf"));
282 g_assert (g_strv_contains (names
, "x-office-document"));
284 g_object_unref (icon
);
292 const gchar
*tests
[] = {
293 "x-content/image-dcf",
294 "x-content/unix-software",
295 "x-content/win32-software"
302 for (i
= 0; i
< G_N_ELEMENTS (tests
); i
++)
304 path
= g_test_get_filename (G_TEST_DIST
, tests
[i
], NULL
);
305 file
= g_file_new_for_path (path
);
306 types
= g_content_type_guess_for_tree (file
);
307 g_assert_content_type_equals (types
[0], tests
[i
]);
309 g_object_unref (file
);
314 main (int argc
, char *argv
[])
316 g_test_init (&argc
, &argv
, NULL
);
318 g_test_add_func ("/contenttype/guess", test_guess
);
319 g_test_add_func ("/contenttype/unknown", test_unknown
);
320 g_test_add_func ("/contenttype/subtype", test_subtype
);
321 g_test_add_func ("/contenttype/list", test_list
);
322 g_test_add_func ("/contenttype/executable", test_executable
);
323 g_test_add_func ("/contenttype/description", test_description
);
324 g_test_add_func ("/contenttype/icon", test_icon
);
325 g_test_add_func ("/contenttype/symbolic-icon", test_symbolic_icon
);
326 g_test_add_func ("/contenttype/tree", test_tree
);
328 return g_test_run ();