2 * Copyright (C) 2003,2004 Red Hat, Inc.
3 * Copyright (C) 2003,2004 Jonathan Blandford <jrb@alum.mit.edu>
5 * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
8 #include "xdgmimeglob.h"
15 test_individual_glob (const char *glob
,
16 XdgGlobType expected_type
)
18 XdgGlobType test_type
;
20 test_type
= _xdg_glob_determine_type (glob
);
21 if (test_type
!= expected_type
)
23 printf ("Test Failed: %s is of type %s, but %s is expected\n",
25 ((test_type
== XDG_GLOB_LITERAL
)?"XDG_GLOB_LITERAL":
26 ((test_type
== XDG_GLOB_SIMPLE
)?"XDG_GLOB_SIMPLE":"XDG_GLOB_FULL")),
27 ((expected_type
== XDG_GLOB_LITERAL
)?"XDG_GLOB_LITERAL":
28 ((expected_type
== XDG_GLOB_SIMPLE
)?"XDG_GLOB_SIMPLE":"XDG_GLOB_COMPLEX")));
36 test_individual_glob ("*.gif", XDG_GLOB_SIMPLE
);
37 test_individual_glob ("Foo*.gif", XDG_GLOB_FULL
);
38 test_individual_glob ("*[4].gif", XDG_GLOB_FULL
);
39 test_individual_glob ("Makefile", XDG_GLOB_LITERAL
);
40 test_individual_glob ("sldkfjvlsdf\\\\slkdjf", XDG_GLOB_FULL
);
41 test_individual_glob ("tree.[ch]", XDG_GLOB_FULL
);
45 test_alias (const char *mime_a
,
51 actual
= xdg_mime_mime_type_equal (mime_a
, mime_b
);
53 if (actual
!= expected
)
55 printf ("Test Failed: %s is %s to %s\n",
56 mime_a
, actual
? "equal" : "not equal", mime_b
);
64 test_alias ("application/wordperfect", "application/vnd.wordperfect", 1);
65 test_alias ("application/x-gnome-app-info", "application/x-desktop", 1);
66 test_alias ("application/x-wordperfect", "application/vnd.wordperfect", 1);
67 test_alias ("application/x-wordperfect", "audio/x-midi", 0);
68 test_alias ("/", "vnd/vnd", 0);
69 test_alias ("application/octet-stream", "text/plain", 0);
70 test_alias ("text/plain", "text/*", 0);
74 test_subclass (const char *mime_a
,
80 actual
= xdg_mime_mime_type_subclass (mime_a
, mime_b
);
82 if (actual
!= expected
)
84 printf ("Test Failed: %s is %s of %s\n",
85 mime_a
, actual
? "subclass" : "not subclass", mime_b
);
91 test_subclassing (void)
93 test_subclass ("application/rtf", "text/plain", 1);
94 test_subclass ("message/news", "text/plain", 1);
95 test_subclass ("message/news", "message/*", 1);
96 test_subclass ("message/news", "text/*", 1);
97 test_subclass ("message/news", "application/octet-stream", 1);
98 test_subclass ("application/rtf", "application/octet-stream", 1);
99 test_subclass ("application/x-gnome-app-info", "text/plain", 1);
100 test_subclass ("image/x-djvu", "image/vnd.djvu", 1);
101 test_subclass ("image/vnd.djvu", "image/x-djvu", 1);
102 test_subclass ("image/vnd.djvu", "text/plain", 0);
103 test_subclass ("image/vnd.djvu", "text/*", 0);
104 test_subclass ("text/*", "text/plain", 1);
108 test_one_match (const char *filename
, const char *expected
)
112 actual
= xdg_mime_get_mime_type_from_file_name (filename
);
114 if (strcasecmp (actual
, expected
) != 0)
116 printf ("Test Failed: mime type of %s is %s, expected %s\n",
117 filename
, actual
, expected
);
125 test_one_match ("foo.bar.epub", "application/epub+zip");
126 test_one_match ("core", "application/x-core");
127 test_one_match ("README.in", "text/x-readme");
128 test_one_match ("README.gz", "application/gzip");
129 test_one_match ("blabla.cs", "text/x-csharp");
130 test_one_match ("blabla.f90", "text/x-fortran");
131 test_one_match ("blabla.F95", "text/x-fortran");
132 test_one_match ("tarball.tar.gz", "application/x-compressed-tar");
133 test_one_match ("file.gz", "application/gzip");
134 test_one_match ("file.tar.lzo", "application/x-tzo");
135 test_one_match ("file.lzo", "application/x-lzop");
139 test_one_icon (const char *mimetype
, const char *expected
)
143 actual
= xdg_mime_get_generic_icon (mimetype
);
145 if (actual
!= expected
&& (actual
== NULL
|| strcmp (actual
, expected
) != 0))
147 printf ("Test Failed: icon of %s is %s, expected %s\n",
148 mimetype
, actual
, expected
);
156 test_one_icon ("application/x-font-ttx", "font-x-generic");
157 test_one_icon ("application/mathematica", "x-office-document");
158 test_one_icon ("text/plain", NULL
);
162 main (int argc
, char *argv
[])
165 const char *file_name
;
174 for (i
= 1; i
< argc
; i
++)
177 result
= xdg_mime_get_mime_type_for_file (file_name
, NULL
);
178 printf ("File \"%s\" has a mime-type of %s\n", file_name
, result
);