1 /* A test util to try out the new
2 * yelp-utils resolver for URIs
3 * Basically, tries to resolve each
4 * given URI and compares to the expected results
5 * (only checks the files exist and the type is correct)
10 #include "yelp-utils.h"
13 int DefaultTests (void);
14 int TestFile (char *uri
);
20 return (g_file_test (uri
, G_FILE_TEST_EXISTS
));
27 gchar
*section
= NULL
;
28 YelpRrnType restype
= YELP_TYPE_ERROR
;
30 /* First, normal docs - these will only work with rrn XDG_DATA_DIRS set correctly */
31 /* Normal doc, no section */
32 restype
= yelp_uri_resolve ("ghelp:user-guide", &result
, §ion
);
33 if (restype
!= YELP_TYPE_DOC
|| !TestFile (result
) ||
37 g_free (result
); result
=NULL
;
40 restype
= yelp_uri_resolve ("ghelp:user-guide#madeupsection", &result
, §ion
);
41 if (restype
!= YELP_TYPE_DOC
|| !TestFile (result
) ||
42 !g_str_equal (section
, "madeupsection")) {
45 g_free (result
); result
=NULL
;
46 g_free (section
); section
= NULL
;
49 restype
= yelp_uri_resolve ("ghelp:user-guide?madeupsection", &result
, §ion
);
50 if (restype
!= YELP_TYPE_DOC
|| !TestFile (result
) ||
51 !g_str_equal (section
, "madeupsection")) {
54 g_free (result
); result
=NULL
;
55 g_free (section
); section
= NULL
;
57 /* man pages - only work with correct man pages installed */
59 restype
= yelp_uri_resolve ("man:yelp", &result
, §ion
);
60 if (restype
!= YELP_TYPE_MAN
|| !TestFile (result
) ||
61 !g_str_equal (section
, "1")) {
64 g_free (result
); result
=NULL
;
65 g_free (section
); section
= NULL
;
67 /* man page from specific section 1*/
68 restype
= yelp_uri_resolve ("man:yelp(1)", &result
, §ion
);
69 if (restype
!= YELP_TYPE_MAN
|| !TestFile (result
) ||
70 !g_str_equal (section
, "1")) {
73 g_free (result
); result
=NULL
;
74 g_free (section
); section
= NULL
;
76 /* man page from specific section 2*/
77 restype
= yelp_uri_resolve ("man:yelp.1", &result
, §ion
);
78 if (restype
!= YELP_TYPE_MAN
|| !TestFile (result
) ||
79 !g_str_equal (section
, "1")) {
82 g_free (result
); result
=NULL
;
83 g_free (section
); section
= NULL
;
85 /* man page from specific section 3*/
86 restype
= yelp_uri_resolve ("man:yelp#1", &result
, §ion
);
87 if (restype
!= YELP_TYPE_MAN
|| !TestFile (result
) ||
88 !g_str_equal (section
, "1")) {
91 g_free (result
); result
=NULL
;
92 g_free (section
); section
= NULL
;
95 /* Simple info page */
96 restype
= yelp_uri_resolve ("info:cvs", &result
, §ion
);
97 if (restype
!= YELP_TYPE_INFO
|| !TestFile (result
) ||
101 g_free (result
); result
=NULL
;
102 g_free (section
); section
= NULL
;
104 /* info page with section */
105 restype
= yelp_uri_resolve ("info:cvs#toolbar", &result
, §ion
);
106 if (restype
!= YELP_TYPE_INFO
|| !TestFile (result
) ||
107 !g_str_equal (section
, "toolbar")) {
110 g_free (result
); result
=NULL
;
111 g_free (section
); section
= NULL
;
113 /* info page with section 2*/
114 restype
= yelp_uri_resolve ("info:cvs?toolbar", &result
, §ion
);
115 if (restype
!= YELP_TYPE_INFO
|| !TestFile (result
) ||
116 !g_str_equal (section
, "toolbar")) {
119 g_free (result
); result
=NULL
;
120 g_free (section
); section
= NULL
;
123 /* info page with section included */
124 restype
= yelp_uri_resolve ("info:autopoint", &result
, §ion
);
125 if (restype
!= YELP_TYPE_INFO
|| !TestFile (result
) ||
126 !g_str_equal (section
, "autopoint Invocation")) {
129 g_free (result
); result
=NULL
;
130 g_free (section
); section
= NULL
;
132 /* Other types: html - no html installed by default. Should be the same
136 restype
= yelp_uri_resolve ("http://www.gnome.org", &result
, §ion
);
137 if (restype
!= YELP_TYPE_EXTERNAL
) {
140 g_free (result
); result
=NULL
;
141 g_free (section
); section
= NULL
;
143 /* External, but local */
144 restype
= yelp_uri_resolve ("/usr/bin/yelp", &result
, §ion
);
145 if (restype
!= YELP_TYPE_EXTERNAL
) {
148 g_free (result
); result
=NULL
;
149 g_free (section
); section
= NULL
;
151 /* External, local using file: uri */
152 restype
= yelp_uri_resolve ("file:///usr/bin/yelp", &result
, §ion
);
153 if (restype
!= YELP_TYPE_EXTERNAL
) {
156 g_free (result
); result
=NULL
;
157 g_free (section
); section
= NULL
;
159 /* Local, file, readable */
160 restype
= yelp_uri_resolve ("file:///usr/share/gnome/help/user-guide/C/user-guide.xml", &result
, §ion
);
161 if (restype
!= YELP_TYPE_DOC
|| !TestFile (result
) ||
165 g_free (result
); result
=NULL
;
166 g_free (section
); section
= NULL
;
168 /* Local, readable, html */
169 restype
= yelp_uri_resolve ("/usr/share/doc/shared-mime-info/shared-mime-info-spec.html/index.html", &result
, §ion
);
170 if (restype
!= YELP_TYPE_HTML
|| !TestFile (result
) ||
174 g_free (result
); result
=NULL
;
175 g_free (section
); section
= NULL
;
177 /* Local, readable, html, with section */
178 restype
= yelp_uri_resolve ("/usr/share/doc/shared-mime-info/shared-mime-info-spec.html/index.html#foobar", &result
, §ion
);
179 if (restype
!= YELP_TYPE_HTML
|| !TestFile (result
) ||
180 !g_str_equal (section
, "foobar")) {
183 g_free (result
); result
=NULL
;
184 g_free (section
); section
= NULL
;
187 restype
= yelp_uri_resolve ("file:///usr/fake_file1", &result
, §ion
);
188 if (restype
!= YELP_TYPE_ERROR
|| result
!= NULL
|| section
!= NULL
) {
191 g_free (result
); result
=NULL
;
192 g_free (section
); section
= NULL
;
201 main (int argc
, char *argv
[])
206 printf ("Usage: %s [<test-uri> <type> <test-uri> <type> ... ]\n", argv
[0]);
207 printf ("type can be one of:\n");
208 printf ("man, info, doc, html, external, fail\n");
214 ret
= DefaultTests ();
219 char *type
= argv
[i
+1];
221 char *section
= NULL
;
222 YelpRrnType restype
= YELP_TYPE_ERROR
;
225 printf ("uri: %s type: %s\n", argv
[i
], argv
[i
+1]);
227 if (g_str_equal (type
, "doc")) {
228 restype
= yelp_uri_resolve (argv
[i
], &result
, §ion
);
229 if (restype
!= YELP_TYPE_DOC
|| !TestFile (result
)) {
230 printf ("Failed doc test %s. Aborting.\n", uri
);
233 } else if (g_str_equal (type
, "info")) {
234 restype
= yelp_uri_resolve (argv
[i
], &result
, §ion
);
235 if (restype
!= YELP_TYPE_INFO
|| !TestFile (result
)) {
236 printf ("Failed doc test %s. Aborting.\n", uri
);
239 } else if (g_str_equal (type
, "man")) {
240 restype
= yelp_uri_resolve (argv
[i
], &result
, §ion
);
241 if (restype
!= YELP_TYPE_MAN
|| !TestFile (result
)) {
242 printf ("Failed doc test %s. Aborting.\n", uri
);
245 } else if (g_str_equal (type
, "external")) {
246 restype
= yelp_uri_resolve (argv
[i
], &result
, §ion
);
247 if (restype
!= YELP_TYPE_EXTERNAL
) {
248 printf ("Failed doc test %s. Aborting.\n", uri
, restype
, YELP_TYPE_EXTERNAL
);
251 } else if (g_str_equal (type
, "error")) {
252 restype
= yelp_uri_resolve (argv
[i
], &result
, §ion
);
253 if (restype
!= YELP_TYPE_ERROR
|| result
!= NULL
) {
254 printf ("Failed doc test %s. Aborting.\n", uri
);
258 printf ("Unknown test: %s. Ignoring.\n", type
);