14 "Exec=./appinfo-test --option\n";
16 res = g_content_type_guess ("/etc/", NULL, 0, &uncertain);
17 expected = g_content_type_from_mime_type ("inode/directory");
18 g_assert (g_content_type_equals (expected, res));
23 res = g_content_type_guess ("foo.txt", NULL, 0, &uncertain);
24 expected = g_content_type_from_mime_type ("text/plain");
25 g_assert (g_content_type_equals (expected, res));
29 res = g_content_type_guess ("foo.desktop", data, sizeof (data) - 1, &uncertain);
30 expected = g_content_type_from_mime_type ("application/x-desktop");
31 g_assert (g_content_type_equals (expected, res));
32 g_assert (!uncertain);
36 res = g_content_type_guess ("foo.txt", data, sizeof (data) - 1, &uncertain);
37 expected = g_content_type_from_mime_type ("text/plain");
38 g_assert (g_content_type_equals (expected, res));
39 g_assert (!uncertain);
43 res = g_content_type_guess ("foo", data, sizeof (data) - 1, &uncertain);
44 expected = g_content_type_from_mime_type ("text/plain");
45 g_assert (g_content_type_equals (expected, res));
46 g_assert (!uncertain);
50 res = g_content_type_guess (NULL, data, sizeof (data) - 1, &uncertain);
51 expected = g_content_type_from_mime_type ("application/x-desktop");
52 g_assert (g_content_type_equals (expected, res));
53 g_assert (!uncertain);
57 /* this is potentially ambiguous: it does not match the PO template format,
58 * but looks like text so it can't be Powerpoint */
59 res = g_content_type_guess ("test.pot", (guchar *)"ABC abc", 7, &uncertain);
60 expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
61 g_assert (g_content_type_equals (expected, res));
62 g_assert (!uncertain);
66 res = g_content_type_guess ("test.pot", (guchar *)"msgid \"", 7, &uncertain);
67 expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
68 g_assert (g_content_type_equals (expected, res));
69 g_assert (!uncertain);
73 res = g_content_type_guess ("test.pot", (guchar *)"\xCF\xD0\xE0\x11", 4, &uncertain);
74 expected = g_content_type_from_mime_type ("application/vnd.ms-powerpoint");
75 g_assert (g_content_type_equals (expected, res));
76 /* we cannot reliably detect binary powerpoint files as long as there is no
77 * defined MIME magic, so do not check uncertain here */
81 res = g_content_type_guess ("test.otf", (guchar *)"OTTO", 4, &uncertain);
82 expected = g_content_type_from_mime_type ("application/x-font-otf");
83 g_assert (g_content_type_equals (expected, res));
84 g_assert (!uncertain);
95 unknown = g_content_type_from_mime_type ("application/octet-stream");
96 g_assert (g_content_type_is_unknown (unknown));
97 str = g_content_type_get_mime_type (unknown);
98 g_assert_cmpstr (str, ==, "application/octet-stream");
109 plain = g_content_type_from_mime_type ("text/plain");
110 xml = g_content_type_from_mime_type ("application/xml");
112 g_assert (g_content_type_is_a (xml, plain));
119 find_mime (gconstpointer a, gconstpointer b)
121 if (g_content_type_equals (a, b))
133 plain = g_content_type_from_mime_type ("text/plain");
134 xml = g_content_type_from_mime_type ("application/xml");
136 types = g_content_types_get_registered ();
138 g_assert (g_list_length (types) > 1);
140 /* just check that some types are in the list */
141 g_assert (g_list_find_custom (types, plain, find_mime) != NULL);
142 g_assert (g_list_find_custom (types, xml, find_mime) != NULL);
144 g_list_free_full (types, g_free);
151 test_executable (void)
155 type = g_content_type_from_mime_type ("application/x-executable");
156 g_assert (g_content_type_can_be_executable (type));
159 type = g_content_type_from_mime_type ("text/plain");
160 g_assert (g_content_type_can_be_executable (type));
163 type = g_content_type_from_mime_type ("image/png");
164 g_assert (!g_content_type_can_be_executable (type));
169 test_description (void)
174 type = g_content_type_from_mime_type ("text/plain");
175 desc = g_content_type_get_description (type);
176 g_assert (desc != NULL);
188 type = g_content_type_from_mime_type ("text/plain");
189 icon = g_content_type_get_icon (type);
190 g_assert (G_IS_ICON (icon));
191 g_object_unref (icon);
194 type = g_content_type_from_mime_type ("application/rtf");
195 icon = g_content_type_get_icon (type);
196 g_assert (G_IS_ICON (icon));
197 g_object_unref (icon);
203 main (int argc, char *argv[])
205 g_test_init (&argc, &argv, NULL);
207 g_test_add_func ("/contenttype/guess", test_guess);
208 g_test_add_func ("/contenttype/unknown", test_unknown);
209 g_test_add_func ("/contenttype/subtype", test_subtype);
210 g_test_add_func ("/contenttype/list", test_list);
211 g_test_add_func ("/contenttype/executable", test_executable);
212 g_test_add_func ("/contenttype/description", test_description);
213 g_test_add_func ("/contenttype/icon", test_icon);
215 return g_test_run ();