Use of pre_cleanups is not the default for reslists.
[apr-util.git] / test / testuri.c
blob5ac5c5f24a06bf272673d050092b097a495d1a8f
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. 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.
17 #include <stdio.h>
18 #include <stdlib.h>
20 #include "testutil.h"
21 #include "apr_general.h"
22 #include "apr_strings.h"
23 #include "apr_uri.h"
25 struct aup_test {
26 const char *uri;
27 apr_status_t rv;
28 const char *scheme;
29 const char *hostinfo;
30 const char *user;
31 const char *password;
32 const char *hostname;
33 const char *port_str;
34 const char *path;
35 const char *query;
36 const char *fragment;
37 apr_port_t port;
40 struct aup_test aup_tests[] =
42 { "http://[/::1]/index.html", APR_EGENERAL },
43 { "http://[", APR_EGENERAL },
44 { "http://[?::1]/index.html", APR_EGENERAL },
47 "http://127.0.0.1:9999/asdf.html",
48 0, "http", "127.0.0.1:9999", NULL, NULL, "127.0.0.1", "9999", "/asdf.html", NULL, NULL, 9999
51 "http://127.0.0.1:9999a/asdf.html",
52 APR_EGENERAL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0
55 "http://[::127.0.0.1]:9999/asdf.html",
56 0, "http", "[::127.0.0.1]:9999", NULL, NULL, "::127.0.0.1", "9999", "/asdf.html", NULL, NULL, 9999
59 "http://[::127.0.0.1]:9999a/asdf.html",
60 APR_EGENERAL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0
63 "/error/include/top.html",
64 0, NULL, NULL, NULL, NULL, NULL, NULL, "/error/include/top.html", NULL, NULL, 0
67 "/error/include/../contact.html.var",
68 0, NULL, NULL, NULL, NULL, NULL, NULL, "/error/include/../contact.html.var", NULL, NULL, 0
71 "/",
72 0, NULL, NULL, NULL, NULL, NULL, NULL, "/", NULL, NULL, 0
75 "/manual/",
76 0, NULL, NULL, NULL, NULL, NULL, NULL, "/manual/", NULL, NULL, 0
79 "/cocoon/developing/graphics/Using%20Databases-label_over.jpg",
80 0, NULL, NULL, NULL, NULL, NULL, NULL, "/cocoon/developing/graphics/Using%20Databases-label_over.jpg", NULL, NULL, 0
83 "http://sonyamt:garbage@127.0.0.1/filespace/",
84 0, "http", "sonyamt:garbage@127.0.0.1", "sonyamt", "garbage", "127.0.0.1", NULL, "/filespace/", NULL, NULL, 0
87 "http://sonyamt:garbage@[fe80::1]/filespace/",
88 0, "http", "sonyamt:garbage@[fe80::1]", "sonyamt", "garbage", "fe80::1", NULL, "/filespace/", NULL, NULL, 0
91 "http://sonyamt@[fe80::1]/filespace/?arg1=store",
92 0, "http", "sonyamt@[fe80::1]", "sonyamt", NULL, "fe80::1", NULL, "/filespace/", "arg1=store", NULL, 0
95 "//www.apache.org/",
96 0, NULL, "www.apache.org", NULL, NULL, "www.apache.org", NULL, "/", NULL, NULL, 0
99 "file:image.jpg",
100 0, "file", NULL, NULL, NULL, NULL, NULL, "image.jpg", NULL, NULL, 0
103 "file:/image.jpg",
104 0, "file", NULL, NULL, NULL, NULL, NULL, "/image.jpg", NULL, NULL, 0
107 "file:///image.jpg",
108 0, "file", "", NULL, NULL, "", NULL, "/image.jpg", NULL, NULL, 0
111 "file:///tmp/photos/image.jpg",
112 0, "file", "", NULL, NULL, "", NULL, "/tmp/photos/image.jpg", NULL, NULL, 0
115 "file:./image.jpg",
116 0, "file", NULL, NULL, NULL, NULL, NULL, "./image.jpg", NULL, NULL, 0
119 "file:../photos/image.jpg",
120 0, "file", NULL, NULL, NULL, NULL, NULL, "../photos/image.jpg", NULL, NULL, 0
124 struct uph_test {
125 const char *hostinfo;
126 apr_status_t rv;
127 const char *hostname;
128 const char *port_str;
129 apr_port_t port;
132 struct uph_test uph_tests[] =
135 "www.ibm.com:443",
136 0, "www.ibm.com", "443", 443
139 "[fe80::1]:443",
140 0, "fe80::1", "443", 443
143 "127.0.0.1:443",
144 0, "127.0.0.1", "443", 443
147 "127.0.0.1",
148 APR_EGENERAL, NULL, NULL, 0
151 "[fe80:80",
152 APR_EGENERAL, NULL, NULL, 0
155 "fe80::80]:443",
156 APR_EGENERAL, NULL, NULL, 0
160 #if 0
161 static void show_info(apr_status_t rv, apr_status_t expected, const apr_uri_t *info)
163 if (rv != expected) {
164 fprintf(stderr, " actual rv: %d expected rv: %d\n", rv, expected);
166 else {
167 fprintf(stderr,
168 " scheme: %s\n"
169 " hostinfo: %s\n"
170 " user: %s\n"
171 " password: %s\n"
172 " hostname: %s\n"
173 " port_str: %s\n"
174 " path: %s\n"
175 " query: %s\n"
176 " fragment: %s\n"
177 " hostent: %p\n"
178 " port: %u\n"
179 " is_initialized: %u\n"
180 " dns_looked_up: %u\n"
181 " dns_resolved: %u\n",
182 info->scheme, info->hostinfo, info->user, info->password,
183 info->hostname, info->port_str, info->path, info->query,
184 info->fragment, info->hostent, info->port, info->is_initialized,
185 info->dns_looked_up, info->dns_resolved);
188 #endif
190 static void test_aup(abts_case *tc, void *data)
192 int i;
193 apr_status_t rv;
194 apr_uri_t info;
195 struct aup_test *t;
196 const char *s = NULL;
198 for (i = 0; i < sizeof(aup_tests) / sizeof(aup_tests[0]); i++) {
199 char msg[256];
201 memset(&info, 0, sizeof(info));
202 t = &aup_tests[i];
203 rv = apr_uri_parse(p, t->uri, &info);
204 apr_snprintf(msg, sizeof msg, "uri '%s': rv=%d not %d", t->uri,
205 rv, t->rv);
206 ABTS_ASSERT(tc, msg, rv == t->rv);
207 if (t->rv == APR_SUCCESS) {
208 ABTS_STR_EQUAL(tc, t->scheme, info.scheme);
209 ABTS_STR_EQUAL(tc, t->hostinfo, info.hostinfo);
210 ABTS_STR_EQUAL(tc, t->user, info.user);
211 ABTS_STR_EQUAL(tc, t->password, info.password);
212 ABTS_STR_EQUAL(tc, t->hostname, info.hostname);
213 ABTS_STR_EQUAL(tc, t->port_str, info.port_str);
214 ABTS_STR_EQUAL(tc, t->path, info.path);
215 ABTS_STR_EQUAL(tc, t->query, info.query);
216 ABTS_STR_EQUAL(tc, t->user, info.user);
217 ABTS_INT_EQUAL(tc, t->port, info.port);
219 s = apr_uri_unparse(p, &info, APR_URI_UNP_REVEALPASSWORD);
220 ABTS_STR_EQUAL(tc, t->uri, s);
222 s = apr_uri_unparse(p, &info, APR_URI_UNP_OMITSITEPART);
223 rv = apr_uri_parse(p, s, &info);
224 ABTS_STR_EQUAL(tc, info.scheme, NULL);
225 ABTS_STR_EQUAL(tc, info.hostinfo, NULL);
226 ABTS_STR_EQUAL(tc, info.user, NULL);
227 ABTS_STR_EQUAL(tc, info.password, NULL);
228 ABTS_STR_EQUAL(tc, info.hostname, NULL);
229 ABTS_STR_EQUAL(tc, info.port_str, NULL);
230 ABTS_STR_EQUAL(tc, info.path, t->path);
231 ABTS_STR_EQUAL(tc, info.query, t->query);
232 ABTS_STR_EQUAL(tc, info.user, NULL);
233 ABTS_INT_EQUAL(tc, info.port, 0);
238 static void test_uph(abts_case *tc, void *data)
240 int i;
241 apr_status_t rv;
242 apr_uri_t info;
243 struct uph_test *t;
245 for (i = 0; i < sizeof(uph_tests) / sizeof(uph_tests[0]); i++) {
246 memset(&info, 0, sizeof(info));
247 t = &uph_tests[i];
248 rv = apr_uri_parse_hostinfo(p, t->hostinfo, &info);
249 ABTS_INT_EQUAL(tc, t->rv, rv);
250 if (t->rv == APR_SUCCESS) {
251 ABTS_STR_EQUAL(tc, t->hostname, info.hostname);
252 ABTS_STR_EQUAL(tc, t->port_str, info.port_str);
253 ABTS_INT_EQUAL(tc, t->port, info.port);
258 abts_suite *testuri(abts_suite *suite)
260 suite = ADD_SUITE(suite);
262 abts_run_test(suite, test_aup, NULL);
263 abts_run_test(suite, test_uph, NULL);
265 return suite;