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); \
26 "Exec=./appinfo-test --option\n";
28 res = g_content_type_guess ("/etc/", NULL, 0, &uncertain);
29 expected = g_content_type_from_mime_type ("inode/directory");
30 g_assert_content_type_equals (expected, res);
35 res = g_content_type_guess ("foo.txt", NULL, 0, &uncertain);
36 expected = g_content_type_from_mime_type ("text/plain");
37 g_assert_content_type_equals (expected, res);
41 res = g_content_type_guess ("foo.desktop", data, sizeof (data) - 1, &uncertain);
42 expected = g_content_type_from_mime_type ("application/x-desktop");
43 g_assert_content_type_equals (expected, res);
44 g_assert (!uncertain);
48 res = g_content_type_guess ("foo.txt", data, sizeof (data) - 1, &uncertain);
49 expected = g_content_type_from_mime_type ("text/plain");
50 g_assert_content_type_equals (expected, res);
51 g_assert (!uncertain);
55 res = g_content_type_guess ("foo", data, sizeof (data) - 1, &uncertain);
56 expected = g_content_type_from_mime_type ("text/plain");
57 g_assert_content_type_equals (expected, res);
58 g_assert (!uncertain);
62 res = g_content_type_guess (NULL, data, sizeof (data) - 1, &uncertain);
63 expected = g_content_type_from_mime_type ("application/x-desktop");
64 g_assert_content_type_equals (expected, res);
65 g_assert (!uncertain);
69 /* this is potentially ambiguous: it does not match the PO template format,
70 * but looks like text so it can't be Powerpoint */
71 res = g_content_type_guess ("test.pot", (guchar *)"ABC abc", 7, &uncertain);
72 expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
73 g_assert_content_type_equals (expected, res);
74 g_assert (!uncertain);
78 res = g_content_type_guess ("test.pot", (guchar *)"msgid \"", 7, &uncertain);
79 expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
80 g_assert_content_type_equals (expected, res);
81 g_assert (!uncertain);
85 res = g_content_type_guess ("test.pot", (guchar *)"\xCF\xD0\xE0\x11", 4, &uncertain);
86 expected = g_content_type_from_mime_type ("application/vnd.ms-powerpoint");
87 g_assert_content_type_equals (expected, res);
88 /* we cannot reliably detect binary powerpoint files as long as there is no
89 * defined MIME magic, so do not check uncertain here
94 res = g_content_type_guess ("test.otf", (guchar *)"OTTO", 4, &uncertain);
95 expected = g_content_type_from_mime_type ("application/x-font-otf");
96 g_assert_content_type_equals (expected, res);
97 g_assert (!uncertain);
101 res = g_content_type_guess (NULL, (guchar *)"%!PS-Adobe-2.0 EPSF-1.2", 23, &uncertain);
102 expected = g_content_type_from_mime_type ("image/x-eps");
103 g_assert_content_type_equals (expected, res);
104 g_assert (!uncertain);
115 unknown = g_content_type_from_mime_type ("application/octet-stream");
116 g_assert (g_content_type_is_unknown (unknown));
117 str = g_content_type_get_mime_type (unknown);
118 g_assert_cmpstr (str, ==, "application/octet-stream");
129 plain = g_content_type_from_mime_type ("text/plain");
130 xml = g_content_type_from_mime_type ("application/xml");
132 g_assert (g_content_type_is_a (xml, plain));
139 find_mime (gconstpointer a, gconstpointer b)
141 if (g_content_type_equals (a, b))
153 plain = g_content_type_from_mime_type ("text/plain");
154 xml = g_content_type_from_mime_type ("application/xml");
156 types = g_content_types_get_registered ();
158 g_assert (g_list_length (types) > 1);
160 /* just check that some types are in the list */
161 g_assert (g_list_find_custom (types, plain, find_mime) != NULL);
162 g_assert (g_list_find_custom (types, xml, find_mime) != NULL);
164 g_list_free_full (types, g_free);
171 test_executable (void)
175 type = g_content_type_from_mime_type ("application/x-executable");
176 g_assert (g_content_type_can_be_executable (type));
179 type = g_content_type_from_mime_type ("text/plain");
180 g_assert (g_content_type_can_be_executable (type));
183 type = g_content_type_from_mime_type ("image/png");
184 g_assert (!g_content_type_can_be_executable (type));
189 test_description (void)
194 type = g_content_type_from_mime_type ("text/plain");
195 desc = g_content_type_get_description (type);
196 g_assert (desc != NULL);
208 type = g_content_type_from_mime_type ("text/plain");
209 icon = g_content_type_get_icon (type);
210 g_assert (G_IS_ICON (icon));
211 g_object_unref (icon);
214 type = g_content_type_from_mime_type ("application/rtf");
215 icon = g_content_type_get_icon (type);
216 g_assert (G_IS_ICON (icon));
217 g_object_unref (icon);
224 const gchar *tests[] = {
225 "x-content/image-dcf",
226 "x-content/unix-software",
227 "x-content/win32-software"
234 for (i = 0; i < G_N_ELEMENTS (tests); i++)
236 path = g_test_get_filename (G_TEST_DIST, tests[i], NULL);
237 file = g_file_new_for_path (path);
238 types = g_content_type_guess_for_tree (file);
239 g_assert_content_type_equals (types[0], tests[i]);
241 g_object_unref (file);
246 main (int argc, char *argv[])
248 g_test_init (&argc, &argv, NULL);
250 g_test_add_func ("/contenttype/guess", test_guess);
251 g_test_add_func ("/contenttype/unknown", test_unknown);
252 g_test_add_func ("/contenttype/subtype", test_subtype);
253 g_test_add_func ("/contenttype/list", test_list);
254 g_test_add_func ("/contenttype/executable", test_executable);
255 g_test_add_func ("/contenttype/description", test_description);
256 g_test_add_func ("/contenttype/icon", test_icon);
257 g_test_add_func ("/contenttype/tree", test_tree);
259 return g_test_run ();