1 /*
2  * Copyright © 2010 Canonical Ltd.
3  *             By Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 3 as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18 
19 #include <glib.h>
20 #include <glib-object.h>
21 #include "zeitgeist.h"
22 
23 typedef struct
24 {
25 } Fixture;
26 
27 static void setup    (Fixture *fix, gconstpointer data);
28 static void teardown (Fixture *fix, gconstpointer data);
29 
30 static void
setup(Fixture * fix,gconstpointer data)31 setup (Fixture *fix, gconstpointer data)
32 {
33 }
34 
35 static void
teardown(Fixture * fix,gconstpointer data)36 teardown (Fixture *fix, gconstpointer data)
37 {
38 }
39 
40 static void
test_mime_textplain(Fixture * fix,gconstpointer data)41 test_mime_textplain (Fixture *fix, gconstpointer data)
42 {
43   g_assert_cmpstr (ZEITGEIST_NFO_TEXT_DOCUMENT, ==,
44                    zeitgeist_interpretation_for_mimetype ("text/plain"));
45 }
46 
47 static void
test_mime_none(Fixture * fix,gconstpointer data)48 test_mime_none (Fixture *fix, gconstpointer data)
49 {
50   g_assert (zeitgeist_interpretation_for_mimetype ("asdfasdf") == NULL);
51 }
52 
53 static void
test_mime_regex(Fixture * fix,gconstpointer data)54 test_mime_regex (Fixture *fix, gconstpointer data)
55 {
56   /* We should have a fallback for application/x-applix-* */
57   g_assert_cmpstr (ZEITGEIST_NFO_DOCUMENT, ==,
58                    zeitgeist_interpretation_for_mimetype ("application/x-applix-FOOOOBAR!"));
59 
60   /* Still application/x-applix-spreadsheet should be a spreadsheet */
61   g_assert_cmpstr (ZEITGEIST_NFO_SPREADSHEET, ==,
62                    zeitgeist_interpretation_for_mimetype ("application/x-applix-spreadsheet"));
63 }
64 
65 static void
test_scheme_file(Fixture * fix,gconstpointer data)66 test_scheme_file (Fixture *fix, gconstpointer data)
67 {
68   g_assert_cmpstr (ZEITGEIST_NFO_FILE_DATA_OBJECT, ==,
69                    zeitgeist_manifestation_for_uri ("file:///tmp/foo.txt"));
70 }
71 
72 static void
test_scheme_none(Fixture * fix,gconstpointer data)73 test_scheme_none (Fixture *fix, gconstpointer data)
74 {
75   g_assert (zeitgeist_manifestation_for_uri ("asdf://asdfasdf") == NULL);
76 }
77 
78 int
main(int argc,char * argv[])79 main (int   argc,
80       char *argv[])
81 {
82   g_test_init (&argc, &argv, NULL);
83 
84   g_test_add ("/Zeitgeist/Mime/TextPlain", Fixture, NULL,
85               setup, test_mime_textplain, teardown);
86   g_test_add ("/Zeitgeist/Mime/None", Fixture, NULL,
87               setup, test_mime_none, teardown);
88   g_test_add ("/Zeitgeist/Mime/Regex", Fixture, NULL,
89               setup, test_mime_regex, teardown);
90   g_test_add ("/Zeitgeist/UriScheme/File", Fixture, NULL,
91               setup, test_scheme_file, teardown);
92   g_test_add ("/Zeitgeist/UriScheme/None", Fixture, NULL,
93               setup, test_scheme_none, teardown);
94 
95   return g_test_run();
96 }
97