1 /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "apr_general.h"
38 struct aup_test aup_tests[] =
40 { "http://[/::1]/index.html", APR_EGENERAL },
41 { "http://[", APR_EGENERAL },
42 { "http://[?::1]/index.html", APR_EGENERAL },
46 "http://127.0.0.1:9999/asdf.html",
47 0, "http", "127.0.0.1:9999", NULL, NULL, "127.0.0.1", "9999", "/asdf.html", NULL, NULL, 9999
50 "http://127.0.0.1:9999a/asdf.html",
51 APR_EGENERAL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0
54 "http://[::127.0.0.1]:9999/asdf.html",
55 0, "http", "[::127.0.0.1]:9999", NULL, NULL, "::127.0.0.1", "9999", "/asdf.html", NULL, NULL, 9999
58 "http://[::127.0.0.1]:9999a/asdf.html",
59 APR_EGENERAL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0
62 "/error/include/top.html",
63 0, NULL, NULL, NULL, NULL, NULL, NULL, "/error/include/top.html", NULL, NULL, 0
66 "/error/include/../contact.html.var",
67 0, NULL, NULL, NULL, NULL, NULL, NULL, "/error/include/../contact.html.var", NULL, NULL, 0
71 0, NULL, NULL, NULL, NULL, NULL, NULL, "/", NULL, NULL, 0
75 0, NULL, NULL, NULL, NULL, NULL, NULL, "/manual/", NULL, NULL, 0
78 "/cocoon/developing/graphics/Using%20Databases-label_over.jpg",
79 0, NULL, NULL, NULL, NULL, NULL, NULL, "/cocoon/developing/graphics/Using%20Databases-label_over.jpg", NULL, NULL, 0
82 "http://sonyamt:garbage@127.0.0.1/filespace/",
83 0, "http", "sonyamt:garbage@127.0.0.1", "sonyamt", "garbage", "127.0.0.1", NULL, "/filespace/", NULL, NULL, 0
86 "http://sonyamt:garbage@[fe80::1]/filespace/",
87 0, "http", "sonyamt:garbage@[fe80::1]", "sonyamt", "garbage", "fe80::1", NULL, "/filespace/", NULL, NULL, 0
90 "http://sonyamt@[fe80::1]/filespace/?arg1=store",
91 0, "http", "sonyamt@[fe80::1]", "sonyamt", NULL, "fe80::1", NULL, "/filespace/", "arg1=store", NULL, 0
103 struct uph_test uph_tests[] =
107 0, "www.ibm.com", "443", 443
111 0, "fe80::1", "443", 443
115 0, "127.0.0.1", "443", 443
119 APR_EGENERAL, NULL, NULL, 0
123 APR_EGENERAL, NULL, NULL, 0
127 APR_EGENERAL, NULL, NULL, 0
131 static void show_info(apr_status_t rv, apr_status_t expected, const apr_uri_t *info)
133 if (rv != expected) {
134 fprintf(stderr, " actual rv: %d expected rv: %d\n", rv, expected);
149 " is_initialized: %u\n"
150 " dns_looked_up: %u\n"
151 " dns_resolved: %u\n",
152 info->scheme, info->hostinfo, info->user, info->password,
153 info->hostname, info->port_str, info->path, info->query,
154 info->fragment, info->hostent, info->port, info->is_initialized,
155 info->dns_looked_up, info->dns_resolved);
159 static int same_str(const char *s1, const char *s2)
161 if (s1 == s2) { /* e.g., NULL and NULL */
164 else if (!s1 || !s2) { /* only 1 is NULL */
168 return strcmp(s1, s2) == 0;
172 static int test_aup(apr_pool_t *p)
181 for (i = 0; i < sizeof(aup_tests) / sizeof(aup_tests[0]); i++) {
182 memset(&info, 0, sizeof(info));
184 rv = apr_uri_parse(p, t->uri, &info);
185 failed = (rv != t->rv) ? "bad rc" : NULL;
186 if (!failed && t->rv == APR_SUCCESS) {
187 if (!same_str(info.scheme, t->scheme))
188 failed = "bad scheme";
189 if (!same_str(info.hostinfo, t->hostinfo))
190 failed = "bad hostinfo";
191 if (!same_str(info.user, t->user))
193 if (!same_str(info.password, t->password))
194 failed = "bad password";
195 if (!same_str(info.hostname, t->hostname))
196 failed = "bad hostname";
197 if (!same_str(info.port_str, t->port_str))
198 failed = "bad port_str";
199 if (!same_str(info.path, t->path))
201 if (!same_str(info.query, t->query))
202 failed = "bad query";
203 if (!same_str(info.fragment, t->fragment))
204 failed = "bad fragment";
205 if (info.port != t->port)
210 fprintf(stderr, "failure for testcase %d/uri %s: %s\n", i,
212 show_info(rv, t->rv, &info);
214 else if (t->rv == APR_SUCCESS) {
215 const char *s = apr_uri_unparse(p, &info,
216 APR_URI_UNP_REVEALPASSWORD);
218 if (strcmp(s, t->uri)) {
219 fprintf(stderr, "apr_uri_unparsed failed for testcase %d\n", i);
220 fprintf(stderr, " got %s, expected %s\n", s, t->uri);
228 static int test_uph(apr_pool_t *p)
237 for (i = 0; i < sizeof(uph_tests) / sizeof(uph_tests[0]); i++) {
238 memset(&info, 0, sizeof(info));
240 rv = apr_uri_parse_hostinfo(p, t->hostinfo, &info);
241 failed = (rv != t->rv) ? "bad rc" : NULL;
242 if (!failed && t->rv == APR_SUCCESS) {
243 if (!same_str(info.hostname, t->hostname))
244 failed = "bad hostname";
245 if (!same_str(info.port_str, t->port_str))
246 failed = "bad port_str";
247 if (info.port != t->port)
252 fprintf(stderr, "failure for testcase %d/hostinfo %s: %s\n", i,
253 t->hostinfo, failed);
254 show_info(rv, t->rv, &info);
267 atexit(apr_terminate);
269 apr_pool_create(&pool, NULL);