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));
26 g_assert (!uncertain);
30 res = g_content_type_guess ("foo.desktop", data, sizeof (data) - 1, &uncertain);
31 expected = g_content_type_from_mime_type ("application/x-desktop");
32 g_assert (g_content_type_equals (expected, res));
33 g_assert (!uncertain);
37 res = g_content_type_guess ("foo.txt", data, sizeof (data) - 1, &uncertain);
38 expected = g_content_type_from_mime_type ("text/plain");
39 g_assert (g_content_type_equals (expected, res));
40 g_assert (!uncertain);
44 res = g_content_type_guess ("foo", data, sizeof (data) - 1, &uncertain);
45 expected = g_content_type_from_mime_type ("text/plain");
46 g_assert (g_content_type_equals (expected, res));
47 g_assert (!uncertain);
51 res = g_content_type_guess (NULL, data, sizeof (data) - 1, &uncertain);
52 expected = g_content_type_from_mime_type ("application/x-desktop");
53 g_assert (g_content_type_equals (expected, res));
54 g_assert (!uncertain);
58 /* this is potentially ambiguous: it does not match the PO template format,
59 * but looks like text so it can't be Powerpoint */
60 res = g_content_type_guess ("test.pot", (guchar *)"ABC abc", 7, &uncertain);
61 expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
62 g_assert (g_content_type_equals (expected, res));
63 g_assert (!uncertain);
67 res = g_content_type_guess ("test.pot", (guchar *)"msgid \"", 7, &uncertain);
68 expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
69 g_assert (g_content_type_equals (expected, res));
70 g_assert (!uncertain);
74 res = g_content_type_guess ("test.pot", (guchar *)"\xCF\xD0\xE0\x11", 4, &uncertain);
75 expected = g_content_type_from_mime_type ("application/vnd.ms-powerpoint");
76 g_assert (g_content_type_equals (expected, res));
77 /* we cannot reliably detect binary powerpoint files as long as there is no
78 * defined MIME magic, so do not check uncertain here */
82 res = g_content_type_guess ("test.otf", (guchar *)"OTTO", 4, &uncertain);
83 expected = g_content_type_from_mime_type ("application/x-font-otf");
84 g_assert (g_content_type_equals (expected, res));
85 g_assert (!uncertain);
96 unknown = g_content_type_from_mime_type ("application/octet-stream");
97 g_assert (g_content_type_is_unknown (unknown));
98 str = g_content_type_get_mime_type (unknown);
99 g_assert_cmpstr (str, ==, "application/octet-stream");
110 plain = g_content_type_from_mime_type ("text/plain");
111 xml = g_content_type_from_mime_type ("application/xml");
113 g_assert (g_content_type_is_a (xml, plain));
120 find_mime (gconstpointer a, gconstpointer b)
122 if (g_content_type_equals (a, b))
134 plain = g_content_type_from_mime_type ("text/plain");
135 xml = g_content_type_from_mime_type ("application/xml");
137 types = g_content_types_get_registered ();
139 g_assert (g_list_length (types) > 1);
141 /* just check that some types are in the list */
142 g_assert (g_list_find_custom (types, plain, find_mime) != NULL);
143 g_assert (g_list_find_custom (types, xml, find_mime) != NULL);
145 g_list_free_full (types, g_free);
152 test_executable (void)
156 type = g_content_type_from_mime_type ("application/x-executable");
157 g_assert (g_content_type_can_be_executable (type));
160 type = g_content_type_from_mime_type ("text/plain");
161 g_assert (g_content_type_can_be_executable (type));
164 type = g_content_type_from_mime_type ("image/png");
165 g_assert (!g_content_type_can_be_executable (type));
170 test_description (void)
175 type = g_content_type_from_mime_type ("text/plain");
176 desc = g_content_type_get_description (type);
177 g_assert (desc != NULL);
189 type = g_content_type_from_mime_type ("text/plain");
190 icon = g_content_type_get_icon (type);
191 g_assert (G_IS_ICON (icon));
192 g_object_unref (icon);
195 type = g_content_type_from_mime_type ("application/rtf");
196 icon = g_content_type_get_icon (type);
197 g_assert (G_IS_ICON (icon));
198 g_object_unref (icon);
204 main (int argc, char *argv[])
206 g_test_init (&argc, &argv, NULL);
208 g_test_add_func ("/contenttype/guess", test_guess);
209 g_test_add_func ("/contenttype/unknown", test_unknown);
210 g_test_add_func ("/contenttype/subtype", test_subtype);
211 g_test_add_func ("/contenttype/list", test_list);
212 g_test_add_func ("/contenttype/executable", test_executable);
213 g_test_add_func ("/contenttype/description", test_description);
214 g_test_add_func ("/contenttype/icon", test_icon);
216 return g_test_run ();