Test.java revision 2362
2362N/A * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * @summary Unit test for java.net.URI 0N/A * @bug 4464135 4505046 4503239 4438319 4991359 4866303 0N/A * @author Mark Reinhold 0N/A // Properties that we check 0N/A static final int SSP =
1 <<
2;
0N/A static final int SSP_D =
1 <<
3;
// Decoded form 0N/A static final int PATH_D =
1 <<
12;
// Decoded form 0N/A static final int QUERY_D =
1 <<
14;
// Decoded form 0N/A int failed =
0;
// Mask for failed properties 0N/A return new Test(s, u, h, n, p, q, f);
0N/A // Operations on Test instances 0N/A // These are short so as to make test cases compact. 0N/A // sp Scheme-specific part 0N/A // spd Scheme-specific part, decoded 0N/A // o Opaque part (isOpaque() && ssp matches) 0N/A // g reGistry (authority matches, and host is not defined) 0N/A // gd reGistry, decoded 0N/A // ud User info, decoded 0N/A // qd Query, decoded 0N/A // fd Fragment, decoded 0N/A // rslv Resolve against given base 0N/A // psa Parse server Authority 0N/A // x Check that parse failed as expected 0N/A // z End -- ensure that unchecked components are null 0N/A // Check identity for the seven-argument URI constructor 0N/A // Only works on hierarchical URIs 0N/A // Only works with server-based authorities 0N/A // Not true if non-US-ASCII chars are encoded unnecessarily 0N/A // Check identity for the five-argument URI constructor 0N/A // Only works on hierarchical URIs 0N/A // Check identity for the three-argument URI constructor 0N/A // Check all identities mentioned in the URI class specification 0N/A // Remaining identities fail if "//" given but authority is undefined 0N/A // Remaining identities fail if ":" given but port is undefined 0N/A // Remaining identities fail if non-US-ASCII chars are encoded 0N/A // Check identities, check that unchecked component properties are not 0N/A // defined, and report any failures 0N/A // Check that unchecked components are undefined 0N/A // Summarization and reporting 0N/A ?
"Correct exception" :
"UNEXPECTED EXCEPTION");
0N/A for (
int i =
0; i < n; i++) {
0N/A if ((c >=
' ') && (c <
0x7f)) {
0N/A .s(
"gopher").h(
"spinaltap.micro.umn.edu")
0N/A test(
"mailto:mduerst@ifi.unizh.ch")
0N/A .s(
"mailto").o(
"mduerst@ifi.unizh.ch").z();
0N/A test(
"news:comp.infosystems.www.servers.unix")
0N/A .s(
"news").o(
"comp.infosystems.www.servers.unix").z();
0N/A .s(
"telnet").h(
"melvyl.ucop.edu").p(
"/").z();
0N/A .s(
"http").h(
"www.w3.org").p(
"/Addressing/").z();
0N/A .s(
"ftp").h(
"ds.internic.net").p(
"/rfc/").z();
0N/A header(
"RFC2396: Normal relative-URI examples (appendix C)");
0N/A .s(
"http").h(
"a").p(
"/b/c/d;p").q(
"q").z().
uri());
0N/A // #s (current document)#s 0N/A // DEVIATION: Lone fragment parses as relative URI with empty path 0N/A .
rslv(
base).s(
"http").h(
"a").p(
"/b/c/d;p").f(
"s").q(
"q").z();
0N/A .p(
"g").q(
"y").f(
"s").z()
0N/A .
rslv(
base).s(
"http").h(
"a").p(
"/b/c/g").q(
"y").f(
"s").z();
0N/A .p(
"g;x").q(
"y").f(
"s").z()
0N/A .
rslv(
base).s(
"http").h(
"a").p(
"/b/c/g;x").q(
"y").f(
"s").z();
0N/A header(
"RFC2396: Abnormal relative-URI examples (appendix C)");
0N/A .p(
"../../../g").z()
0N/A .p(
"../../../../g").z()
0N/A .p(
"g;x=1/../y").z()
0N/A .p(
"g").q(
"y/./x").z()
0N/A .
rslv(
base).s(
"http").h(
"a").p(
"/b/c/g").q(
"y/./x").z();
0N/A .p(
"g").q(
"y/../x").z()
0N/A .
rslv(
base).s(
"http").h(
"a").p(
"/b/c/g").q(
"y/../x").z();
0N/A .p(
"g").f(
"s/./x").z()
0N/A .
rslv(
base).s(
"http").h(
"a").p(
"/b/c/g").f(
"s/./x").z();
0N/A .p(
"g").f(
"s/../x").z()
0N/A .
rslv(
base).s(
"http").h(
"a").p(
"/b/c/g").f(
"s/../x").z();
0N/A .s(
"http").o(
"g").z()
0N/A .s(
"http").h(
"1.2.3.4").n(
5).p(
"").z();
0N/A .s(
"http").h(
"[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]")
0N/A .s(
"http").h(
"[FEDC:BA98:7654:3210:FEDC:BA98:7654:10%12]")
0N/A .s(
"http").h(
"[1080:0:0:0:8:800:200C:417A]").p(
"/index.html").z();
0N/A .s(
"http").h(
"[1080:0:0:0:8:800:200C:417A%1]").p(
"/index.html").z();
0N/A test(
"http://[3ffe:2a00:100:7031::1]")
0N/A .s(
"http").h(
"[3ffe:2a00:100:7031::1]").p(
"").z();
0N/A test(
"http://[1080::8:800:200C:417A]/foo")
0N/A .s(
"http").h(
"[1080::8:800:200C:417A]").p(
"/foo").z();
0N/A .s(
"http").h(
"[::192.9.5.5]").p(
"/ipng").z();
0N/A test(
"http://[::192.9.5.5%interface]/ipng")
0N/A .s(
"http").h(
"[::192.9.5.5%interface]").p(
"/ipng").z();
0N/A .s(
"http").h(
"[::FFFF:129.144.52.38]").n(
80).p(
"/index.html").z();
0N/A test(
"http://[2010:836B:4179::836B:4179]")
0N/A .s(
"http").h(
"[2010:836B:4179::836B:4179]").p(
"").z();
0N/A .s(
"http").h(
"[FF01::101]").p(
"").z();
0N/A .s(
"http").h(
"[::1]").p(
"").z();
0N/A .s(
"http").h(
"[::]").p(
"").z();
0N/A .s(
"http").h(
"[::%hme0]").p(
"").z();
0N/A test(
"http://[0:0:0:0:0:0:13.1.68.3]")
0N/A .s(
"http").h(
"[0:0:0:0:0:0:13.1.68.3]").p(
"").z();
0N/A test(
"http://[0:0:0:0:0:FFFF:129.144.52.38]")
0N/A .s(
"http").h(
"[0:0:0:0:0:FFFF:129.144.52.38]").p(
"").z();
0N/A test(
"http://[0:0:0:0:0:FFFF:129.144.52.38%33]")
0N/A .s(
"http").h(
"[0:0:0:0:0:FFFF:129.144.52.38%33]").p(
"").z();
0N/A test(
"http://[0:0:0:0:0:ffff:1.2.3.4]")
0N/A .s(
"http").h(
"[0:0:0:0:0:ffff:1.2.3.4]").p(
"").z();
0N/A .s(
"http").h(
"[::13.1.68.3]").p(
"").z();
0N/A // Optional IPv6 brackets in constructors 0N/A .s(
"s").h(
"[1:2:3:4:5:6:7:8]").p(
"").z();
0N/A .s(
"s").h(
"[1:2:3:4:5:6:7:8]").p(
"").z();
0N/A .s(
"s").h(
"[1:2:3:4:5:6:7:8]").p(
"").z();
0N/A .s(
"s").h(
"[1:2:3:4:5:6:7:8]").p(
"").z();
0N/A .s(
"s").h(
"[1:2:3:4:5:6:7:8%hme0]").p(
"").z();
0N/A .s(
"s").h(
"[1:2:3:4:5:6:7:8%1]").p(
"").z();
0N/A .s(
"s").h(
"[1:2:3:4:5:6:7:8]").p(
"").z();
0N/A .s(
"s").h(
"[1:2:3:4:5:6:7:8]").p(
"").z();
0N/A .s(
"s").g(
"1:2:3:4:5:6:7:8").p(
"").z();
0N/A test(
"http://[ff01:234/foo").x().z();
0N/A test(
"http://[ff01:234:zzz]/foo").x().z();
0N/A test(
"http://[129.33.44.55]").x().z();
0N/A test(
"http://[ff:ee:dd:cc:bb::aa:9:8]").x().z();
0N/A test(
"http://[ff::ee::8]").x().z();
0N/A test(
"http://[1:2:3:4::5:6:7:8]").x().z();
0N/A test(
"http://[1:2:3:4:5:6:7:8:9]").x().z();
0N/A test(
"http://[1:2:3:4:5:6:7:8%]").x().z();
0N/A test(
"http://[1:2:3:4:5:6:7:8%!/]").x().z();
0N/A test(
"http://[::1.2.3.300]").x().z();
0N/A test(
"http://[1.2.3.4:5]").x().z();
0N/A // Test hostnames that might initially look like IPv4 addresses 0N/A test(
"s://1.2.3.com").
psa().s(
"s").h(
"1.2.3.com").p(
"").z();
0N/A test(
"s://1.2.3.4me.com").
psa().s(
"s").h(
"1.2.3.4me.com").p(
"").z();
0N/A test(
"s://7up.com").
psa().s(
"s").h(
"7up.com").p(
"").z();
0N/A test(
"s://7up.com/p").
psa().s(
"s").h(
"7up.com").p(
"/p").z();
0N/A test(
"s://7up/p").
psa().s(
"s").h(
"7up").p(
"/p").z();
0N/A test(
"s://7up.").
psa().s(
"s").h(
"7up.").p(
"").z();
0N/A test(
"s://7up./p").
psa().s(
"s").h(
"7up.").p(
"/p").z();
0N/A // The empty URI parses as a relative URI with an empty path 0N/A // Resolving solo queries and fragments 0N/A // Fragment is not part of ssp 0N/A test(
"s:p#f").s(
"s").o(
"p").f(
"f").z();
0N/A // Components that may be empty 0N/A test(
"///p").p(
"/p").z();
// Authority (w/ path) 0N/A test(
"//@h/p").u(
"").h(
"h").p(
"/p").z();
// User info 0N/A test(
"//h:/p").h(
"h").p(
"/p").z();
// Port 0N/A test(
"//h").h(
"h").p(
"").z();
// Path 0N/A test(
"p?#").p(
"p").q(
"").f(
"").z();
// Query & fragment 0N/A // Components that may not be empty 0N/A test(
"//").x().z();
// Authority (w/o path) 0N/A header(
"Resolution, normalization, and relativization");
0N/A // Resolving relative paths 0N/A test(
"../../../../d").p(
"../../../../d").z()
0N/A test(
"../../../d:e").p(
"../../../d:e").z()
0N/A test(
"../../../d:e/f").p(
"../../../d:e/f").z()
0N/A test(
"a/./c/../d/f").p(
"a/./c/../d/f").z()
0N/A .s(
"http").h(
"a").p(
"/./b/c/../d").q(
"q").f(
"f").z()
0N/A .
norm().s(
"http").h(
"a").p(
"/b/d").q(
"q").f(
"f").z();
0N/A // Normalization of already normalized URI should yield the 0N/A .
rtvz(
new URI(
"/a/b")).p(
"").z();
// Result is empty path 0N/A test(
"a/../b:c/d").p(
"a/../b:c/d").z()
0N/A .s(
"http").h(
"a").p(
"/b/d/e").q(
"q").f(
"f").z()
0N/A .p(
"d/e").q(
"q").f(
"f").z();
0N/A // parseServerAuthority 0N/A .
psa().s(
"s").u(
"u").h(
"h").n(
1).p(
"/p").z();
0N/A test(
"s://u@h:-foo/p").s(
"s").g(
"u@h:-foo").p(
"/p").z()
0N/A test(
"s://h:999999999999999999999999").
psa().x().z();
0N/A test(
"s",
"u",
"h",
10,
"/p",
"q",
"f")
0N/A .s(
"s").u(
"u").h(
"h").n(
10).p(
"/p").q(
"q").f(
"f").z();
0N/A .s(
"s").g(
"a:b").p(
"/p").q(
"q").f(
"f").z();
0N/A .s(
"s").h(
"h").p(
"/p").f(
"f").z();
0N/A test(
"s",
"p",
"f").s(
"s").o(
"p").f(
"f").z();
0N/A test(
"s",
"/p",
"f").s(
"s").p(
"/p").f(
"f").z();
0N/A .s(
"s").u(
"u").h(
"h").p(
"/p").q(
"q").f(
"f").z();
0N/A header(
"Escapes and non-US-ASCII characters");
0N/A .p(
"%0a%0A%0f%0F%01%09zz").z();
0N/A // Escapes not permitted in scheme, host 0N/A test(
"//a%20b").g(
"a%20b").p(
"").z();
// Parses as registry 0N/A // Escapes permitted in opaque part, userInfo, registry, path, 0N/A // query, and fragment 0N/A test(
"//u%20v@a").u(
"u%20v").h(
"a").p(
"").z();
0N/A test(
"/p?q%20").p(
"/p").q(
"q%20").z();
0N/A test(
"/p#%20f").p(
"/p").f(
"%20f").z();
0N/A // Non-US-ASCII chars 0N/A test(
"//\u00a7/b").g(
"\u00a7").p(
"/b").z();
// Parses as registry 0N/A test(
"//u\u00a7v@a").u(
"u\u00a7v").h(
"a").p(
"").z();
0N/A test(
"/p\u00a7q").p(
"/p\u00a7q").z();
0N/A test(
"/p?q\u00a7").p(
"/p").q(
"q\u00a7").z();
0N/A test(
"/p#\u00a7f").p(
"/p").f(
"\u00a7f").z();
0N/A // 4648111 - Escapes quoted by toString after resolution 0N/A // 4464135: Forbid unwise characters throughout opaque part 0N/A // 4438319: Single-argument constructor requires quotation, 0N/A // preserves escapes 0N/A test(
"//u%01@h/a/b/%02/c?q%03#f%04")
0N/A .p(
"/a/b/%02/c").
pd(
"/a/b/\2/c")
0N/A // 4438319: Multi-argument constructors quote illegal chars and 0N/A // preserve legal non-ASCII chars 0N/A // \uA001-\uA009 are visible characters, \u2000 is a space character 0N/A "/p% \uA002\2\u2000",
0N/A "q% \uA003\3\u2000",
0N/A "f% \uA004\4\u2000")
0N/A .u(
"u\uA001%01").h(
"h")
0N/A .p(
"/p%25%20\uA002%02%E2%80%80").
pd(
"/p% \uA002\2\u2000")
0N/A .q(
"q%25%20\uA003%03%E2%80%80").
qd(
"q% \uA003\3\u2000")
0N/A .f(
"f%25%20\uA004%04%E2%80%80").
fd(
"f% \uA004\4\u2000").z();
0N/A "/p% \uA002\2\u2000",
0N/A "q% \uA003\3\u2000",
0N/A "f% \uA004\4\u2000")
0N/A .p(
"/p%25%20\uA002%02%E2%80%80").
pd(
"/p% \uA002\2\u2000")
0N/A .q(
"q%25%20\uA003%03%E2%80%80").
qd(
"q% \uA003\3\u2000")
0N/A .f(
"f%25%20\uA004%04%E2%80%80").
fd(
"f% \uA004\4\u2000").z();
0N/A .p(
"/p%25%20\uA002%02%E2%80%80").
pd(
"/p% \uA002\2\u2000")
0N/A .f(
"f%25%20\uA004%04%E2%80%80").
fd(
"f% \uA004\4\u2000").z();
0N/A .
sp(
"/sp%25%20\uA001%01%E2%80%80").
spd(
"/sp% \uA001\1\u2000")
0N/A .p(
"/sp%25%20\uA001%01%E2%80%80").
pd(
"/sp% \uA001\1\u2000")
0N/A .f(
"f%25%20\uA004%04%E2%80%80").
fd(
"f% \uA004\4\u2000").z();
0N/A // 4438319: Non-raw accessors decode all escaped octets 0N/A .p(
"/%25%20%E2%82%AC%E2%80%80").
pd(
"/% \u20Ac\u2000").z();
0N/A // 4438319: toASCIIString 0N/A .p(
"/\uCAFE\uBABE").
ta(
"/%EC%AB%BE%EB%AA%BE").z();
0N/A // 4991359 and 4866303: bad quoting by defineSchemeSpecificPart() 0N/A URI r =
new URI(
"reg://some%20registry/b/c/d?q#f");
0N/A eq(r,
new URI(
"rEg://some%20registry/b/c/d?q#f"));
0N/A gt(r,
new URI(
"reg://Some%20Registry/b/c/d?q#f"));
0N/A gt(r,
new URI(
"reg://some%20registry/b/c/D?q#f"));
0N/A lt(
"s://u@h:1",
"s://v@h:1");
0N/A lt(
"s://u@h:1",
"s://u@i:1");
0N/A lt(
"s://u@h:1",
"s://v@h:2");
0N/A lt(
"s://a%20b",
"s://a%20c");
0N/A lt(
"s://a%20b",
"s://aab");
0N/A lt(
"s://h/p",
"s://h/p?q");
0N/A // -- Command-line invocation -- 0N/A out.
println(
" java Test <base> <uri> -- Parses uri and base, then resolves");