1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright 2004 Ximian, Inc. (www.ximian.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 #include <camel/camel-mime-filter-tohtml.h>
34 #include "camel-test.h"
39 { "bob@foo.com", "mailto:bob@foo.com" },
40 { "Ends with bob@foo.com", "mailto:bob@foo.com" },
41 { "bob@foo.com at start", "mailto:bob@foo.com" },
42 { "bob@foo.com.", "mailto:bob@foo.com" },
43 { "\"bob@foo.com\"", "mailto:bob@foo.com" },
44 { "<bob@foo.com>", "mailto:bob@foo.com" },
45 { "(bob@foo.com)", "mailto:bob@foo.com" },
46 { "bob@foo.com, 555-9999", "mailto:bob@foo.com" },
47 { "|bob@foo.com|555-9999|", "mailto:bob@foo.com" },
48 { "bob@ no match bob@", NULL },
49 { "@foo.com no match @foo.com", NULL },
50 { "\"bob\"@foo.com", NULL },
51 { "M@ke money fast!", NULL },
52 { "ASCII art @_@ @>->-", NULL },
54 { "http://www.foo.com", "http://www.foo.com" },
55 { "Ends with http://www.foo.com", "http://www.foo.com" },
56 { "http://www.foo.com at start", "http://www.foo.com" },
57 { "http://www.foo.com.", "http://www.foo.com" },
58 { "http://www.foo.com/.", "http://www.foo.com/" },
59 { "<http://www.foo.com>", "http://www.foo.com" },
60 { "(http://www.foo.com)", "http://www.foo.com" },
61 { "http://www.foo.com, 555-9999", "http://www.foo.com" },
62 { "|http://www.foo.com|555-9999|", "http://www.foo.com" },
63 { "foo http://www.foo.com/ bar", "http://www.foo.com/" },
64 { "foo http://www.foo.com/index.html bar", "http://www.foo.com/index.html" },
65 { "foo http://www.foo.com/q?99 bar", "http://www.foo.com/q?99" },
66 { "foo http://www.foo.com/;foo=bar&baz=quux bar", "http://www.foo.com/;foo=bar&baz=quux" },
67 { "foo http://www.foo.com/index.html#anchor bar", "http://www.foo.com/index.html#anchor" },
68 { "http://www.foo.com/index.html; foo", "http://www.foo.com/index.html" },
69 { "http://www.foo.com/index.html: foo", "http://www.foo.com/index.html" },
70 { "http://www.foo.com/index.html-- foo", "http://www.foo.com/index.html" },
71 { "http://www.foo.com/index.html?", "http://www.foo.com/index.html" },
72 { "http://www.foo.com/index.html!", "http://www.foo.com/index.html" },
73 { "\"http://www.foo.com/index.html\"", "http://www.foo.com/index.html" },
74 { "'http://www.foo.com/index.html'", "http://www.foo.com/index.html" },
75 { "http://bob@www.foo.com/bar/baz/", "http://bob@www.foo.com/bar/baz/" },
76 { "http no match http", NULL },
77 { "http: no match http:", NULL },
78 { "http:// no match http://", NULL },
79 { "unrecognized://bob@foo.com/path", "mailto:bob@foo.com" },
81 { "src/www.c", NULL },
82 { "Ewwwwww.Gross.", NULL },
86 static int num_url_tests = G_N_ELEMENTS (url_tests);
88 int main (int argc, char **argv)
94 camel_test_init (argc, argv);
96 camel_test_start ("URL scanning");
98 flags = CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS | CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES;
99 for (i = 0; i < num_url_tests; i++) {
100 camel_test_push ("'%s' => '%s'", url_tests[i].text, url_tests[i].url ? url_tests[i].url : "None");
102 html = camel_text_to_html (url_tests[i].text, flags, 0);
104 url = strstr (html, "href=\"");
107 p = strchr (url, '"');
111 while ((p = strstr (url, "&")))
112 memmove (p + 1, p + 5, strlen (p + 5) + 1);
115 if ((url && (!url_tests[i].url || strcmp (url, url_tests[i].url) != 0)) ||
116 (!url && url_tests[i].url)) {
117 printf ("FAILED on \"%s\" -> %s\n (got %s)\n\n",
119 url_tests[i].url ? url_tests[i].url : "(nothing)",
120 url ? url : "(nothing)");
127 printf ("\n%d errors\n", errors);