Merge lp:~zeitgeist/zeitgeist/mimetypes into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Siegfried Gevatter
Status: Merged
Approved by: Michal Hruby
Approved revision: 349
Merged at revision: 349
Proposed branch: lp:~zeitgeist/zeitgeist/mimetypes
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 546 lines (+467/-1)
6 files modified
.bzrignore (+1/-0)
src/Makefile.am (+1/-0)
src/mimetype.vala (+349/-0)
test/direct/Makefile.am (+7/-0)
test/direct/assertions.vapi (+1/-1)
test/direct/mimetype-test.vala (+108/-0)
To merge this branch: bzr merge lp:~zeitgeist/zeitgeist/mimetypes
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+87033@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

A couple of optimizations, pls:

- turn the private structs into compact classes (this will require explicit ownership transfer when adding them to the lists)
- the *_for_* methods should return `unowned string?`
- it'd be nice to sort the register_mimetype calls alphabetically

review: Needs Fixing
lp:~zeitgeist/zeitgeist/mimetypes updated
347. By Michal Hruby

Fix warning about delegate copying

348. By Siegfried Gevatter

Add interpretation_for_mimetype and manifestation_for_uri functions,
ported from libzeitgeist.

This is needed to implement https://bugs.launchpad.net/zeitgeist/+bug/899602

349. By Siegfried Gevatter

Use compact classes instead of structs, return unowned strings and
sort mimetypes alphabetically.

Revision history for this message
Michal Hruby (mhr3) wrote :

Perfection.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2011-11-01 18:12:14 +0000
+++ .bzrignore 2011-12-29 12:20:30 +0000
@@ -54,3 +54,4 @@
54extra/python/_ontology.py54extra/python/_ontology.py
55test/direct/*.c55test/direct/*.c
56src/zeitgeist-daemon56src/zeitgeist-daemon
57mimetype-test
5758
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2011-11-01 18:30:37 +0000
+++ src/Makefile.am 2011-12-29 12:20:30 +0000
@@ -44,6 +44,7 @@
44 where-clause.vala \44 where-clause.vala \
45 ontology.vala \45 ontology.vala \
46 ontology-uris.vala \46 ontology-uris.vala \
47 mimetype.vala \
47 $(NULL)48 $(NULL)
4849
49zeitgeist_daemon_SOURCES = \50zeitgeist_daemon_SOURCES = \
5051
=== added file 'src/mimetype.vala'
--- src/mimetype.vala 1970-01-01 00:00:00 +0000
+++ src/mimetype.vala 2011-12-29 12:20:30 +0000
@@ -0,0 +1,349 @@
1/* datamodel.vala
2 *
3 * Copyright © 2011 Collabora Ltd.
4 * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
5 * Copyright © 2010 Canonical, Ltd.
6 * By Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 2.1 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23using Zeitgeist;
24
25namespace Zeitgeist
26{
27
28 private static bool mimetypes_loaded = false;
29 private static bool schemes_loaded = false;
30
31 private static HashTable<string, string>? mimetypes = null;
32 private static SList<MimeRegex?> mimetypes_regexs;
33 private static SList<UriScheme?> schemes;
34
35 [Compact]
36 private class MimeRegex
37 {
38 public Regex regex;
39 public string interpretation_uri;
40
41 public MimeRegex (string mimetype_regex, string interpretation_uri)
42 throws RegexError
43 {
44 this.regex = new Regex (mimetype_regex, 0, 0);
45 this.interpretation_uri = interpretation_uri;
46 }
47 }
48
49 [Compact]
50 private class UriScheme
51 {
52 public string uri_scheme;
53 public string manifestation_uri;
54
55 public UriScheme (string uri_scheme, string manifestation_uri)
56 {
57 this.uri_scheme = uri_scheme;
58 this.manifestation_uri = manifestation_uri;
59 }
60 }
61
62 /**
63 * zeitgeist_register_mimetype:
64 * @mimetype: A MIME-type string. Eg. <emphasis>text/plain</emphasis>
65 * @interpretation_uri: A URI defining the subject interpretation type to
66 * associate with @mimetype
67 *
68 * Associate a MIME-type with a given interpretation type. Registered
69 * MIME-types can be looked up with zeitgeist_interpretation_for_mimetype().
70 *
71 * You can register a regular expression as mimetype if instead of this
72 * function you invoke zeitgeist_register_mimetype_regex().
73 *
74 * MIME-types are first looked up by their exact name and then if none is
75 * found the regular expressions will be checked as fallbacks.
76 *
77 * This library will install a wide range a common mimetypes for you, so
78 * unless you have very specific needs you will normally not have to call
79 * this function.
80 *
81 * FIXME: link to list of interpretations
82 */
83 public void register_mimetype (string mimetype, string interpretation_uri)
84 {
85 if (mimetypes == null)
86 mimetypes = new HashTable<string, string>(str_hash, str_equal);
87
88 mimetypes.insert (mimetype, interpretation_uri);
89 }
90
91 /**
92 * zeitgeist_register_mimetype_regex:
93 * @mimetype: A regular expression matching a certain range of mimetypes.
94 * Eg. <emphasis>text/.*</emphasis> to match all
95 * <emphasis>text</emphasis> subtypes.
96 * @interpretation_uri: A URI defining the subject interpretation type to
97 * associate with the matched MIME-types
98 *
99 * Associate a range of MIME-types with a given interpretation type.
100 * Registered MIME-types can be looked up with
101 * zeitgeist_interpretation_for_mimetype().
102 *
103 * If you only need to register one specific MIME-type, it is more efficient
104 * to use zeitgeist_register_mimetype() instead of this function.
105 *
106 * MIME-types are first looked up by their exact name and then if none is
107 * found the regular expressions will be checked as fallbacks.
108 *
109 * This library will install a wide range a common mimetypes for you, so
110 * unless you have very specific needs you will normally not have to call
111 * this function.
112 *
113 * FIXME: link to list of interpretations
114 */
115 public void register_mimetype_regex (string mimetype_regex,
116 string interpretation_uri) throws RegexError
117 {
118 var entry = new MimeRegex (mimetype_regex, interpretation_uri);
119 mimetypes_regexs.append ((owned) entry);
120 }
121
122 /**
123 * zeitgeist_interpretation_for_mimetype:
124 * @mimetype: A MIME-type string. Eg. <emphasis>text/plain</emphasis>
125 *
126 * Look up the subject interpretation type associated with @mimetype.
127 * FIXME: link to list of interpretations
128 *
129 * Returns: A URI defining the subject interpretation type associated with
130 * @mimetype or %NULL in case @mimetype is unknown.
131 */
132 public unowned string? interpretation_for_mimetype (string mimetype)
133 {
134 ensure_mimetypes_loaded ();
135
136 unowned string? interpretation = mimetypes.lookup (mimetype);
137 if (interpretation != null)
138 return interpretation;
139
140 foreach (unowned MimeRegex mime_regex in mimetypes_regexs)
141 {
142 if (mime_regex.regex.match (mimetype, 0))
143 return mime_regex.interpretation_uri;
144 }
145
146 return null;
147 }
148
149 /**
150 * zeitgeist_register_uri_scheme:
151 * @uri_scheme: A URI scheme such as <emphasis>http://</emphasis>
152 * @manifestation_uri: A URI defining the subject manifestation type
153 * to associate with @uri_scheme
154 *
155 * Associate a URI scheme with a given subject manifestation type.
156 * You can find the manifestation type of a given URI by passing it to
157 * zeitgeist_manifestation_for_uri().
158 *
159 * This library will install a range a common URI schemes for you, so unless
160 * you have very specific needs you will normally not have to call this
161 * function.
162 *
163 * FIXME: link to list of manifestations
164 */
165 public void register_uri_scheme (string uri_scheme,
166 string manifestation_type)
167 {
168 var scheme = new UriScheme (uri_scheme, manifestation_type);
169 schemes.append ((owned) scheme);
170 }
171
172 /**
173 * zeitgeist_manifestation_for_uri:
174 * @uri: An URI
175 *
176 * Look up a subject manifestation type for a given URI. Eg. if you pass in
177 * <emphasis>file:///tmp/foo.txt</emphasis> you will get back
178 * #ZEITGEIST_NFO_FILE_DATA_OBJECT.
179 *
180 * FIXME: link to list of manifestations
181 *
182 * Returns: A subject manifestation type for @uri or %NULL in case no
183 * suitable manifestation type is known
184 */
185 public unowned string? manifestation_for_uri (string uri) {
186 ensure_schemes_loaded ();
187
188 foreach (unowned UriScheme scheme in schemes)
189 {
190 if (uri.has_prefix (scheme.uri_scheme))
191 return scheme.manifestation_uri;
192 }
193
194 return null;
195 }
196
197 private static void ensure_mimetypes_loaded ()
198 {
199 if (mimetypes_loaded)
200 return;
201
202 try {
203 register_mimetype ("application/ecmascript", NFO.SOURCE_CODE);
204 register_mimetype ("application/javascript", NFO.SOURCE_CODE);
205 register_mimetype ("application/ms-excel", NFO.SPREADSHEET);
206 register_mimetype ("application/ms-powerpoint", NFO.PRESENTATION);
207 register_mimetype ("application/msexcel", NFO.SPREADSHEET);
208 register_mimetype ("application/msword", NFO.PAGINATED_TEXT_DOCUMENT);
209 register_mimetype ("application/ogg", NFO.AUDIO);
210 register_mimetype ("application/pdf", NFO.PAGINATED_TEXT_DOCUMENT);
211 register_mimetype ("application/postscript", NFO.PAGINATED_TEXT_DOCUMENT);
212 register_mimetype ("application/ps", NFO.PAGINATED_TEXT_DOCUMENT);
213 register_mimetype ("application/rtf", NFO.PAGINATED_TEXT_DOCUMENT);
214 register_mimetype ("application/vnd.corel-draw", NFO.VECTOR_IMAGE);
215 register_mimetype ("application/vnd.ms-excel", NFO.SPREADSHEET);
216 register_mimetype ("application/vnd.ms-powerpoint", NFO.PRESENTATION);
217 register_mimetype ("application/x-7z-compressed", NFO.ARCHIVE);
218 register_mimetype ("application/x-abiword", NFO.PAGINATED_TEXT_DOCUMENT);
219 register_mimetype ("application/x-applix-presents", NFO.PRESENTATION);
220 register_mimetype ("application/x-applix-spreadsheet", NFO.SPREADSHEET);
221 register_mimetype ("application/x-applix-word", NFO.PAGINATED_TEXT_DOCUMENT);
222 register_mimetype ("application/x-archive", NFO.ARCHIVE);
223 register_mimetype ("application/x-bzip", NFO.ARCHIVE);
224 register_mimetype ("application/x-bzip-compressed-tar", NFO.ARCHIVE);
225 register_mimetype ("application/x-cd-image", NFO.FILESYSTEM_IMAGE);
226 register_mimetype ("application/x-compressed-tar", NFO.ARCHIVE);
227 register_mimetype ("application/x-csh", NFO.SOURCE_CODE);
228 register_mimetype ("application/x-deb", NFO.SOFTWARE);
229 register_mimetype ("application/x-designer", NFO.SOURCE_CODE);
230 register_mimetype ("application/x-desktop", NFO.SOFTWARE);
231 register_mimetype ("application/x-dia-diagram", NFO.SOURCE_CODE);
232 register_mimetype ("application/x-executable", NFO.SOFTWARE);
233 register_mimetype ("application/x-fluid", NFO.SOURCE_CODE);
234 register_mimetype ("application/x-glade", NFO.SOURCE_CODE);
235 register_mimetype ("application/x-gnucash", NFO.SPREADSHEET);
236 register_mimetype ("application/x-gnumeric", NFO.SPREADSHEET);
237 register_mimetype ("application/x-gzip", NFO.ARCHIVE);
238 register_mimetype ("application/x-java-archive", NFO.SOURCE_CODE);
239 register_mimetype ("application/x-killustrator", NFO.VECTOR_IMAGE);
240 register_mimetype ("application/x-kpresenter", NFO.PRESENTATION);
241 register_mimetype ("application/x-kspread", NFO.SPREADSHEET);
242 register_mimetype ("application/x-kword", NFO.PAGINATED_TEXT_DOCUMENT);
243 register_mimetype ("application/x-lzma", NFO.ARCHIVE);
244 register_mimetype ("application/x-lzma-compressed-tar", NFO.ARCHIVE);
245 register_mimetype ("application/x-m4", NFO.SOURCE_CODE);
246 register_mimetype ("application/x-ms-dos-executable", NFO.SOFTWARE);
247 register_mimetype ("application/x-object", NFO.SOURCE_CODE);
248 register_mimetype ("application/x-perl", NFO.SOURCE_CODE);
249 register_mimetype ("application/x-php", NFO.SOURCE_CODE);
250 register_mimetype ("application/x-rpm", NFO.SOFTWARE);
251 register_mimetype ("application/x-ruby", NFO.SOURCE_CODE);
252 register_mimetype ("application/x-shellscript", NFO.SOURCE_CODE);
253 register_mimetype ("application/x-sql", NFO.SOURCE_CODE);
254 register_mimetype ("application/xhtml+xml", NFO.SOURCE_CODE);
255 register_mimetype ("application/xml", NFO.SOURCE_CODE);
256 register_mimetype ("application/zip", NFO.ARCHIVE);
257 register_mimetype ("audio/x-scpls", NFO.MEDIA_LIST);
258 register_mimetype ("image/gif", NFO.RASTER_IMAGE);
259 register_mimetype ("image/jpeg", NFO.RASTER_IMAGE);
260 register_mimetype ("image/png", NFO.RASTER_IMAGE);
261 register_mimetype ("image/svg+xml", NFO.VECTOR_IMAGE);
262 register_mimetype ("image/tiff", NFO.RASTER_IMAGE);
263 register_mimetype ("image/x-xcf", NFO.RASTER_IMAGE);
264 register_mimetype ("text/css", NFO.SOURCE_CODE);
265 register_mimetype ("text/html", NFO.HTML_DOCUMENT);
266 register_mimetype ("text/plain", NFO.TEXT_DOCUMENT);
267 register_mimetype ("text/x-c", NFO.SOURCE_CODE);
268 register_mimetype ("text/x-c++", NFO.SOURCE_CODE);
269 register_mimetype ("text/x-c++src", NFO.SOURCE_CODE);
270 register_mimetype ("text/x-chdr", NFO.SOURCE_CODE);
271 register_mimetype ("text/x-copying", NFO.SOURCE_CODE);
272 register_mimetype ("text/x-credits", NFO.SOURCE_CODE);
273 register_mimetype ("text/x-csharp", NFO.SOURCE_CODE);
274 register_mimetype ("text/x-csrc", NFO.SOURCE_CODE);
275 register_mimetype ("text/x-dsrc", NFO.SOURCE_CODE);
276 register_mimetype ("text/x-eiffel", NFO.SOURCE_CODE);
277 register_mimetype ("text/x-gettext-translation", NFO.SOURCE_CODE);
278 register_mimetype ("text/x-gettext-translation-template", NFO.SOURCE_CODE);
279 register_mimetype ("text/x-haskell", NFO.SOURCE_CODE);
280 register_mimetype ("text/x-idl", NFO.SOURCE_CODE);
281 register_mimetype ("text/x-java", NFO.SOURCE_CODE);
282 register_mimetype ("text/x-latex", NFO.SOURCE_CODE);
283 register_mimetype ("text/x-lisp", NFO.SOURCE_CODE);
284 register_mimetype ("text/x-lua", NFO.SOURCE_CODE);
285 register_mimetype ("text/x-m4", NFO.SOURCE_CODE);
286 register_mimetype ("text/x-makefile", NFO.SOURCE_CODE);
287 register_mimetype ("text/x-objcsrc", NFO.SOURCE_CODE);
288 register_mimetype ("text/x-ocaml", NFO.SOURCE_CODE);
289 register_mimetype ("text/x-pascal", NFO.SOURCE_CODE);
290 register_mimetype ("text/x-patch", NFO.SOURCE_CODE);
291 register_mimetype ("text/x-python", NFO.SOURCE_CODE);
292 register_mimetype ("text/x-sql", NFO.SOURCE_CODE);
293 register_mimetype ("text/x-tcl", NFO.SOURCE_CODE);
294 register_mimetype ("text/x-tex", NFO.SOURCE_CODE);
295 register_mimetype ("text/x-troff", NFO.SOURCE_CODE);
296 register_mimetype ("text/x-vala", NFO.SOURCE_CODE);
297 register_mimetype ("text/x-vhdl", NFO.SOURCE_CODE);
298
299 register_mimetype_regex (".*/x-dvi", NFO.PAGINATED_TEXT_DOCUMENT);
300 register_mimetype_regex (
301 "application/vnd.oasis.opendocument.text.*",
302 NFO.PAGINATED_TEXT_DOCUMENT);
303 register_mimetype_regex (
304 "application/vnd.oasis.opendocument.presentation.*",
305 NFO.PRESENTATION);
306 register_mimetype_regex (
307 "application/vnd.oasis.opendocument.spreadsheet.*",
308 NFO.SPREADSHEET);
309 register_mimetype_regex (
310 "application/vnd.oasis.opendocument.graphics.*",
311 NFO.VECTOR_IMAGE);
312 register_mimetype_regex ("application/vnd\\..*", NFO.DOCUMENT);
313 register_mimetype_regex ("application/x-applix-.*", NFO.DOCUMENT);
314 register_mimetype_regex ("application/vnd.ms-excel.*",
315 NFO.SPREADSHEET);
316 register_mimetype_regex ("application/vnd.ms-powerpoint.*",
317 NFO.PRESENTATION);
318 register_mimetype_regex ("audio/.*", NFO.AUDIO);
319 register_mimetype_regex ("image/.*", NFO.IMAGE);
320 register_mimetype_regex ("video/.*", NFO.VIDEO);
321 } catch (RegexError e) {
322 // This won't happen.
323 assert (false);
324 }
325
326 mimetypes_loaded = true;
327 }
328
329 private static void ensure_schemes_loaded ()
330 {
331 if (schemes_loaded)
332 return;
333
334 register_uri_scheme ("file://", NFO.FILE_DATA_OBJECT);
335 register_uri_scheme ("http://", NFO.REMOTE_DATA_OBJECT);
336 register_uri_scheme ("https://", NFO.REMOTE_DATA_OBJECT);
337 register_uri_scheme ("ssh://", NFO.REMOTE_DATA_OBJECT);
338 register_uri_scheme ("sftp://", NFO.REMOTE_DATA_OBJECT);
339 register_uri_scheme ("ftp://", NFO.REMOTE_DATA_OBJECT);
340 register_uri_scheme ("dav://", NFO.REMOTE_DATA_OBJECT);
341 register_uri_scheme ("davs://", NFO.REMOTE_DATA_OBJECT);
342 register_uri_scheme ("smb://", NFO.REMOTE_DATA_OBJECT);
343
344 schemes_loaded = true;
345 }
346
347}
348
349// vim:expandtab:ts=4:sw=4
0350
=== modified file 'test/direct/Makefile.am'
--- test/direct/Makefile.am 2011-10-12 21:13:12 +0000
+++ test/direct/Makefile.am 2011-12-29 12:20:30 +0000
@@ -13,6 +13,7 @@
13 query-operators-test \13 query-operators-test \
14 where-clause-test \14 where-clause-test \
15 table-lookup-test \15 table-lookup-test \
16 mimetype-test \
16 $(NULL)17 $(NULL)
1718
18SRC_FILES = \19SRC_FILES = \
@@ -31,6 +32,7 @@
31 $(top_srcdir)/src/sql.vala \32 $(top_srcdir)/src/sql.vala \
32 $(top_srcdir)/src/ontology.vala \33 $(top_srcdir)/src/ontology.vala \
33 $(top_srcdir)/src/ontology-uris.vala \34 $(top_srcdir)/src/ontology-uris.vala \
35 $(top_srcdir)/src/mimetype.vala \
34 $(NULL)36 $(NULL)
3537
36marshalling: marshalling.vala $(SRC_FILES)38marshalling: marshalling.vala $(SRC_FILES)
@@ -45,6 +47,9 @@
45table-lookup-test: table-lookup-test.vala $(SRC_FILES)47table-lookup-test: table-lookup-test.vala $(SRC_FILES)
46 $(VALAC) $(VALAFLAGS) -o $@ $^48 $(VALAC) $(VALAFLAGS) -o $@ $^
4749
50mimetype-test: mimetype-test.vala $(SRC_FILES)
51 $(VALAC) $(VALAFLAGS) -o $@ $^
52
48clean-local:53clean-local:
49 rm -f *.~[0-9]~54 rm -f *.~[0-9]~
5055
@@ -53,6 +58,7 @@
53 query-operators-test \58 query-operators-test \
54 where-clause-test \59 where-clause-test \
55 table-lookup-test \60 table-lookup-test \
61 mimetype-test \
56 $(NULL)62 $(NULL)
5763
58EXTRA_DIST = \64EXTRA_DIST = \
@@ -60,6 +66,7 @@
60 query-operators-test.vala \66 query-operators-test.vala \
61 where-clause-test.vala \67 where-clause-test.vala \
62 table-lookup-test.vala \68 table-lookup-test.vala \
69 mimetype-test.vala \
63 assertions.vapi \70 assertions.vapi \
64 $(NULL)71 $(NULL)
6572
6673
=== modified file 'test/direct/assertions.vapi'
--- test/direct/assertions.vapi 2011-08-12 15:00:59 +0000
+++ test/direct/assertions.vapi 2011-12-29 12:20:30 +0000
@@ -14,7 +14,7 @@
14 [CCode (cname = ">=")]14 [CCode (cname = ">=")]
15 GREATER_OR_EQUAL15 GREATER_OR_EQUAL
16 }16 }
17 17
18 public void assert_cmpstr (string? s1, OperatorType op, string? s2);18 public void assert_cmpstr (string? s1, OperatorType op, string? s2);
19 public void assert_cmpint (int n1, OperatorType op, int n2);19 public void assert_cmpint (int n1, OperatorType op, int n2);
20 public void assert_cmpuint (uint n1, OperatorType op, uint n2);20 public void assert_cmpuint (uint n1, OperatorType op, uint n2);
2121
=== added file 'test/direct/mimetype-test.vala'
--- test/direct/mimetype-test.vala 1970-01-01 00:00:00 +0000
+++ test/direct/mimetype-test.vala 2011-12-29 12:20:30 +0000
@@ -0,0 +1,108 @@
1/* where-clause-test.vala
2 *
3 * Copyright © 2011 Collabora Ltd.
4 * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
5 * Copyright © 2010 Canonical, Ltd.
6 * By Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 2.1 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23using Zeitgeist;
24using Assertions;
25
26void main (string[] args)
27{
28 Test.init (ref args);
29
30 Test.add_func ("/MimeType/basic", mime_type_basic_test);
31 Test.add_func ("/MimeType/regex", mime_type_regex_test);
32 Test.add_func ("/MimeType/none", mime_type_none_test);
33 Test.add_func ("/MimeType/register", mime_type_registration_test);
34
35 Test.add_func ("/UriScheme/basic", uri_scheme_basic_test);
36 Test.add_func ("/UriScheme/none", uri_scheme_none_test);
37 Test.add_func ("/UriScheme/register", uri_scheme_registration_test);
38
39 Test.run ();
40}
41
42public void mime_type_basic_test ()
43{
44 assert_cmpstr (NFO.TEXT_DOCUMENT, OperatorType.EQUAL,
45 interpretation_for_mimetype ("text/plain"));
46}
47
48public void mime_type_regex_test ()
49{
50 // We should have a fallack for application/x-applix-*
51 assert_cmpstr (NFO.DOCUMENT, OperatorType.EQUAL,
52 interpretation_for_mimetype ("application/x-applix-FOOBAR"));
53
54 // Still application/x-applix-speadsheet should be a spreadsheet
55 assert_cmpstr (NFO.SPREADSHEET, OperatorType.EQUAL,
56 interpretation_for_mimetype ("application/x-applix-spreadsheet"));
57}
58
59public void mime_type_none_test ()
60{
61 assert (interpretation_for_mimetype ("foo/bar") == null);
62}
63
64public void mime_type_registration_test ()
65{
66 register_mimetype ("awesome/bird", "Bluebird");
67 try
68 {
69 register_mimetype_regex ("everything/.*", "is nothing");
70 } catch (RegexError e) {
71 assert (false);
72 }
73
74 mime_type_basic_test ();
75 mime_type_regex_test ();
76 mime_type_none_test ();
77
78 assert_cmpstr ("Bluebird", OperatorType.EQUAL,
79 interpretation_for_mimetype ("awesome/bird"));
80 assert_cmpstr ("is nothing", OperatorType.EQUAL,
81 interpretation_for_mimetype ("everything/everywhere"));
82}
83
84public void uri_scheme_basic_test ()
85{
86 assert_cmpstr (NFO.FILE_DATA_OBJECT, OperatorType.EQUAL,
87 manifestation_for_uri ("file:///tmp/foo.txt"));
88 assert_cmpstr (NFO.REMOTE_DATA_OBJECT, OperatorType.EQUAL,
89 manifestation_for_uri ("ftp://ftp.example.com"));
90}
91
92public void uri_scheme_none_test ()
93{
94 assert (manifestation_for_uri ("asdf://awesomehttp://") == null);
95}
96
97public void uri_scheme_registration_test ()
98{
99 register_uri_scheme ("42://", "the answer");
100
101 uri_scheme_basic_test ();
102 uri_scheme_none_test ();
103
104 assert_cmpstr ("the answer", OperatorType.EQUAL,
105 manifestation_for_uri ("42://what is it?"));
106}
107
108// vim:expandtab:ts=4:sw=4

Subscribers

People subscribed via source and target branches