Fixing some navigation wonkiness with error pages
[yelp.git] / src / test-resolver.c
blobcfadb956753535345da44b762ce9b0964dc4d9ab
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)
6 */
8 #include <stdio.h>
9 #include <glib.h>
10 #include "yelp-utils.h"
13 int DefaultTests (void);
14 int TestFile (char *uri);
17 int
18 TestFile (char *uri)
20 return (g_file_test (uri, G_FILE_TEST_EXISTS));
23 int
24 DefaultTests (void)
26 gchar *result = NULL;
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, &section);
33 if (restype != YELP_TYPE_DOC || !TestFile (result) ||
34 section != NULL) {
35 return 101;
37 g_free (result); result=NULL;
39 /* Section type 1*/
40 restype = yelp_uri_resolve ("ghelp:user-guide#madeupsection", &result, &section);
41 if (restype != YELP_TYPE_DOC || !TestFile (result) ||
42 !g_str_equal (section, "madeupsection")) {
43 return 102;
45 g_free (result); result=NULL;
46 g_free (section); section = NULL;
48 /* Section type 2 */
49 restype = yelp_uri_resolve ("ghelp:user-guide?madeupsection", &result, &section);
50 if (restype != YELP_TYPE_DOC || !TestFile (result) ||
51 !g_str_equal (section, "madeupsection")) {
52 return 103;
54 g_free (result); result=NULL;
55 g_free (section); section = NULL;
57 /* man pages - only work with correct man pages installed */
58 /* Simple man page */
59 restype = yelp_uri_resolve ("man:yelp", &result, &section);
60 if (restype != YELP_TYPE_MAN || !TestFile (result) ||
61 !g_str_equal (section, "1")) {
62 return 104;
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, &section);
69 if (restype != YELP_TYPE_MAN || !TestFile (result) ||
70 !g_str_equal (section, "1")) {
71 return 105;
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, &section);
78 if (restype != YELP_TYPE_MAN || !TestFile (result) ||
79 !g_str_equal (section, "1")) {
80 return 106;
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, &section);
87 if (restype != YELP_TYPE_MAN || !TestFile (result) ||
88 !g_str_equal (section, "1")) {
89 return 107;
91 g_free (result); result=NULL;
92 g_free (section); section = NULL;
94 /* Info pages */
95 /* Simple info page */
96 restype = yelp_uri_resolve ("info:cvs", &result, &section);
97 if (restype != YELP_TYPE_INFO || !TestFile (result) ||
98 section != NULL) {
99 return 108;
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, &section);
106 if (restype != YELP_TYPE_INFO || !TestFile (result) ||
107 !g_str_equal (section, "toolbar")) {
108 return 109;
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, &section);
115 if (restype != YELP_TYPE_INFO || !TestFile (result) ||
116 !g_str_equal (section, "toolbar")) {
117 return 110;
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, &section);
125 if (restype != YELP_TYPE_INFO || !TestFile (result) ||
126 !g_str_equal (section, "autopoint Invocation")) {
127 return 111;
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
133 * as ghelp
135 /* External */
136 restype = yelp_uri_resolve ("http://www.gnome.org", &result, &section);
137 if (restype != YELP_TYPE_EXTERNAL) {
138 return 112;
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, &section);
145 if (restype != YELP_TYPE_EXTERNAL) {
146 return 113;
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, &section);
153 if (restype != YELP_TYPE_EXTERNAL) {
154 return 114;
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, &section);
161 if (restype != YELP_TYPE_DOC || !TestFile (result) ||
162 section != NULL) {
163 return 115;
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, &section);
170 if (restype != YELP_TYPE_HTML || !TestFile (result) ||
171 section != NULL) {
172 return 116;
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, &section);
179 if (restype != YELP_TYPE_HTML || !TestFile (result) ||
180 !g_str_equal (section, "foobar")) {
181 return 117;
183 g_free (result); result=NULL;
184 g_free (section); section = NULL;
186 /* error */
187 restype = yelp_uri_resolve ("file:///usr/fake_file1", &result, &section);
188 if (restype != YELP_TYPE_ERROR || result != NULL || section != NULL) {
189 return 118;
191 g_free (result); result=NULL;
192 g_free (section); section = NULL;
197 return 0;
201 main (int argc, char *argv[])
203 int i=1;
205 if (argc % 2 != 1) {
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");
209 return 1;
212 if (argc == 1) {
213 int ret;
214 ret = DefaultTests ();
215 return ret;
217 while (i < argc) {
218 char *uri = argv[i];
219 char *type = argv[i+1];
220 char *result = NULL;
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, &section);
229 if (restype != YELP_TYPE_DOC || !TestFile (result)) {
230 printf ("Failed doc test %s. Aborting.\n", uri);
231 return 2;
233 } else if (g_str_equal (type, "info")) {
234 restype = yelp_uri_resolve (argv[i], &result, &section);
235 if (restype != YELP_TYPE_INFO || !TestFile (result)) {
236 printf ("Failed doc test %s. Aborting.\n", uri);
237 return 3;
239 } else if (g_str_equal (type, "man")) {
240 restype = yelp_uri_resolve (argv[i], &result, &section);
241 if (restype != YELP_TYPE_MAN || !TestFile (result)) {
242 printf ("Failed doc test %s. Aborting.\n", uri);
243 return 4;
245 } else if (g_str_equal (type, "external")) {
246 restype = yelp_uri_resolve (argv[i], &result, &section);
247 if (restype != YELP_TYPE_EXTERNAL) {
248 printf ("Failed doc test %s. Aborting.\n", uri, restype, YELP_TYPE_EXTERNAL);
249 return 5;
251 } else if (g_str_equal (type, "error")) {
252 restype = yelp_uri_resolve (argv[i], &result, &section);
253 if (restype != YELP_TYPE_ERROR || result != NULL) {
254 printf ("Failed doc test %s. Aborting.\n", uri);
255 return 6;
257 } else {
258 printf ("Unknown test: %s. Ignoring.\n", type);
260 i+=2;
261 g_free (result);
262 result = NULL;
264 return 0;