Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/URI/Test.java
47182 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @summary Unit test for java.net.URI25* @bug 4464135 4505046 4503239 4438319 4991359 4866303 7023363 704180026* 717141527* @author Mark Reinhold28*/2930import java.io.ByteArrayInputStream;31import java.io.ByteArrayOutputStream;32import java.io.IOException;33import java.io.ObjectInputStream;34import java.io.ObjectOutputStream;35import java.io.PrintStream;36import java.net.URI;37import java.net.URISyntaxException;38import java.net.URL;39import java.net.MalformedURLException;404142public class Test {4344static PrintStream out = System.out;45static int testCount = 0;4647// Properties that we check48static final int PARSEFAIL = 1 << 0;49static final int SCHEME = 1 << 1;50static final int SSP = 1 << 2;51static final int SSP_D = 1 << 3; // Decoded form52static final int OPAQUEPART = 1 << 4; // SSP, and URI is opaque53static final int USERINFO = 1 << 5;54static final int USERINFO_D = 1 << 6; // Decoded form55static final int HOST = 1 << 7;56static final int PORT = 1 << 8;57static final int REGISTRY = 1 << 9;58static final int REGISTRY_D = 1 << 10; // Decoded form59static final int PATH = 1 << 11;60static final int PATH_D = 1 << 12; // Decoded form61static final int QUERY = 1 << 13;62static final int QUERY_D = 1 << 14; // Decoded form63static final int FRAGMENT = 1 << 15;64static final int FRAGMENT_D = 1 << 16; // Decoded form65static final int TOASCII = 1 << 17;66static final int IDENT_STR = 1 << 18; // Identities67static final int IDENT_URI1 = 1 << 19;68static final int IDENT_URI3 = 1 << 20;69static final int IDENT_URI5 = 1 << 21;70static final int IDENT_URI7 = 1 << 22;71static final int TOSTRING = 1 << 23;7273String input;74URI uri = null;75URI originalURI;76URI base = null; // Base for resolution/relativization77String op = null; // Op performed if uri != originalURI78int checked = 0; // Mask for checked properties79int failed = 0; // Mask for failed properties80Exception exc = null;8182private Test(String s) {83testCount++;84input = s;85try {86uri = new URI(s);87} catch (URISyntaxException x) {88exc = x;89}90originalURI = uri;91}9293static Test test(String s) {94return new Test(s);95}9697private Test(String s, String u, String h, int n,98String p, String q, String f)99{100testCount++;101try {102uri = new URI(s, u, h, n, p, q, f);103} catch (URISyntaxException x) {104exc = x;105input = x.getInput();106}107if (uri != null)108input = uri.toString();109originalURI = uri;110}111112static Test test(String s, String u, String h, int n,113String p, String q, String f) {114return new Test(s, u, h, n, p, q, f);115}116117private Test(String s, String a,118String p, String q, String f)119{120testCount++;121try {122uri = new URI(s, a, p, q, f);123} catch (URISyntaxException x) {124exc = x;125input = x.getInput();126}127if (uri != null)128input = uri.toString();129originalURI = uri;130}131132static Test test(String s, String a,133String p, String q, String f) {134return new Test(s, a, p, q, f);135}136137private Test(String s, String h, String p, String f) {138testCount++;139try {140uri = new URI(s, h, p, f);141} catch (URISyntaxException x) {142exc = x;143input = x.getInput();144}145if (uri != null)146input = uri.toString();147originalURI = uri;148}149150static Test test(String s, String h, String p, String f) {151return new Test(s, h, p, f);152}153154private Test(String s, String ssp, String f) {155testCount++;156try {157uri = new URI(s, ssp, f);158} catch (URISyntaxException x) {159exc = x;160input = x.getInput();161}162if (uri != null)163input = uri.toString();164originalURI = uri;165}166167static Test test(String s, String ssp, String f) {168return new Test(s, ssp, f);169}170171private Test(String s, boolean xxx) {172testCount++;173try {174uri = URI.create(s);175} catch (IllegalArgumentException x) {176exc = x;177}178if (uri != null)179input = uri.toString();180originalURI = uri;181}182183static Test testCreate(String s) {184return new Test(s, false);185}186187boolean parsed() {188return uri != null;189}190191boolean resolved() {192return base != null;193}194195URI uri() {196return uri;197}198199200// Operations on Test instances201//202// These are short so as to make test cases compact.203//204// s Scheme205// sp Scheme-specific part206// spd Scheme-specific part, decoded207// o Opaque part (isOpaque() && ssp matches)208// g reGistry (authority matches, and host is not defined)209// gd reGistry, decoded210// u User info211// ud User info, decoded212// h Host213// n port Number214// p Path215// pd Path, decoded216// q Query217// qd Query, decoded218// f Fragment219// fd Fragment, decoded220//221// rslv Resolve against given base222// rtvz Relativize223// psa Parse server Authority224// norm Normalize225// ta ASCII form226//227// x Check that parse failed as expected228// z End -- ensure that unchecked components are null229230private boolean check1(int prop) {231checked |= prop;232if (!parsed()) {233failed |= prop;234return false;235}236return true;237}238239private void check2(String s, String ans, int prop) {240if ((s == null) || !s.equals(ans))241failed |= prop;242}243244Test s(String s) {245if (check1(SCHEME)) check2(uri.getScheme(), s, SCHEME);246return this;247}248249Test u(String s) {250if (check1(USERINFO)) check2(uri.getRawUserInfo(), s, USERINFO);251return this;252}253254Test ud(String s) {255if (check1(USERINFO_D)) {256check2(uri.getUserInfo(), s, USERINFO_D);257}258return this;259}260261Test h(String s) {262if (check1(HOST)) check2(uri.getHost(), s, HOST);263return this;264}265266Test g(String s) {267if (check1(REGISTRY)) {268if (uri.getHost() != null)269failed |= REGISTRY;270else271check2(uri.getRawAuthority(), s, REGISTRY);272}273return this;274}275276Test gd(String s) {277if (check1(REGISTRY_D)) {278if (uri.getHost() != null)279failed |= REGISTRY_D;280else281check2(uri.getAuthority(), s, REGISTRY_D);282}283return this;284}285286Test n(int n) {287checked |= PORT;288if (!parsed() || (uri.getPort() != n))289failed |= PORT;290return this;291}292293Test p(String s) {294if (check1(PATH)) check2(uri.getRawPath(), s, PATH);295return this;296}297298Test pd(String s) {299if (check1(PATH_D)) check2(uri.getPath(), s, PATH_D);300return this;301}302303Test o(String s) {304if (check1(OPAQUEPART)) {305if (!uri.isOpaque())306failed |= OPAQUEPART;307else308check2(uri.getSchemeSpecificPart(), s, OPAQUEPART);309}310return this;311}312313Test sp(String s) {314if (check1(SSP)) check2(uri.getRawSchemeSpecificPart(), s, SSP);315return this;316}317318Test spd(String s) {319if (check1(SSP_D)) check2(uri.getSchemeSpecificPart(), s, SSP_D);320return this;321}322323Test q(String s) {324if (check1(QUERY)) check2(uri.getRawQuery(), s, QUERY);325return this;326}327328Test qd(String s) {329if (check1(QUERY_D)) check2(uri.getQuery(), s, QUERY_D);330return this;331}332333Test f(String s) {334if (check1(FRAGMENT)) check2(uri.getRawFragment(), s, FRAGMENT);335return this;336}337338Test fd(String s) {339if (check1(FRAGMENT_D)) check2(uri.getFragment(), s, FRAGMENT_D);340return this;341}342343Test ta(String s) {344if (check1(TOASCII))345check2(uri.toASCIIString(), s, TOASCII);346return this;347}348349Test ts(String s) {350if (check1(TOSTRING))351check2(uri.toString(), s, TOSTRING);352return this;353}354355Test x() {356checked |= PARSEFAIL;357if (parsed())358failed |= PARSEFAIL;359return this;360}361362Test rslv(URI base) {363if (!parsed())364return this;365this.base = base;366op = "rslv";367URI u = uri;368uri = null;369try {370this.uri = base.resolve(u);371} catch (IllegalArgumentException x) {372exc = x;373}374checked = 0;375failed = 0;376return this;377}378379Test norm() {380if (!parsed())381return this;382op = "norm";383uri = uri.normalize();384return this;385}386387Test rtvz(URI base) {388if (!parsed())389return this;390this.base = base;391op = "rtvz";392uri = base.relativize(uri);393checked = 0;394failed = 0;395return this;396}397398Test psa() {399try {400uri.parseServerAuthority();401} catch (URISyntaxException x) {402exc = x;403uri = null;404}405checked = 0;406failed = 0;407return this;408}409410private void checkEmpty(String s, int prop) {411if (((checked & prop) == 0) && (s != null))412failed |= prop;413}414415// Check identity for the seven-argument URI constructor416//417void checkURI7() {418// Only works on hierarchical URIs419if (uri.isOpaque())420return;421// Only works with server-based authorities422if ((uri.getAuthority() == null)423!= ((uri.getUserInfo() == null) && (uri.getHost() == null)))424return;425// Not true if non-US-ASCII chars are encoded unnecessarily426if (uri.getPath().indexOf('\u20AC') >= 0)427return;428try {429URI u2 = new URI(uri.getScheme(), uri.getUserInfo(),430uri.getHost(), uri.getPort(), uri.getPath(),431uri.getQuery(), uri.getFragment());432if (!uri.equals(u2))433failed |= IDENT_URI7;434} catch (URISyntaxException x) {435failed |= IDENT_URI7;436}437}438439// Check identity for the five-argument URI constructor440//441void checkURI5() {442// Only works on hierarchical URIs443if (uri.isOpaque())444return;445try {446URI u2 = new URI(uri.getScheme(), uri.getAuthority(),447uri.getPath(), uri.getQuery(), uri.getFragment());448if (!uri.equals(u2))449failed |= IDENT_URI5;450} catch (URISyntaxException x) {451failed |= IDENT_URI5;452}453}454455// Check identity for the three-argument URI constructor456//457void checkURI3() {458try {459URI u2 = new URI(uri.getScheme(),460uri.getSchemeSpecificPart(),461uri.getFragment());462if (!uri.equals(u2))463failed |= IDENT_URI3;464} catch (URISyntaxException x) {465failed |= IDENT_URI3;466}467}468469// Check all identities mentioned in the URI class specification470//471void checkIdentities() {472if (input != null) {473if (!uri.toString().equals(input))474failed |= IDENT_STR;475}476try {477if (!(new URI(uri.toString())).equals(uri))478failed |= IDENT_URI1;479} catch (URISyntaxException x) {480failed |= IDENT_URI1;481}482483// Remaining identities fail if "//" given but authority is undefined484if ((uri.getAuthority() == null)485&& (uri.getSchemeSpecificPart() != null)486&& (uri.getSchemeSpecificPart().startsWith("///")487|| uri.getSchemeSpecificPart().startsWith("//?")488|| uri.getSchemeSpecificPart().equals("//")))489return;490491// Remaining identities fail if ":" given but port is undefined492if ((uri.getHost() != null)493&& (uri.getAuthority() != null)494&& (uri.getAuthority().equals(uri.getHost() + ":")))495return;496497// Remaining identities fail if non-US-ASCII chars are encoded498// unnecessarily499if ((uri.getPath() != null) && uri.getPath().indexOf('\u20AC') >= 0)500return;501502checkURI3();503checkURI5();504checkURI7();505}506507// Check identities, check that unchecked component properties are not508// defined, and report any failures509//510Test z() {511if (!parsed()) {512report();513return this;514}515516if (op == null)517checkIdentities();518519// Check that unchecked components are undefined520checkEmpty(uri.getScheme(), SCHEME);521checkEmpty(uri.getUserInfo(), USERINFO);522checkEmpty(uri.getHost(), HOST);523if (((checked & PORT) == 0) && (uri.getPort() != -1)) failed |= PORT;524checkEmpty(uri.getPath(), PATH);525checkEmpty(uri.getQuery(), QUERY);526checkEmpty(uri.getFragment(), FRAGMENT);527528// Report failures529report();530return this;531}532533534// Summarization and reporting535536static void header(String s) {537out.println();538out.println();539out.println("-- " + s + " --");540}541542static void show(String prefix, URISyntaxException x) {543out.println(uquote(x.getInput()));544if (x.getIndex() >= 0) {545for (int i = 0; i < x.getIndex(); i++) {546if (x.getInput().charAt(i) >= '\u0080')547out.print(" "); // Skip over \u1234548else549out.print(" ");550}551out.println("^");552}553out.println(prefix + ": " + x.getReason());554}555556private void summarize() {557out.println();558StringBuffer sb = new StringBuffer();559if (input.length() == 0)560sb.append("\"\"");561else562sb.append(input);563if (base != null) {564sb.append(" ");565sb.append(base);566}567if (!parsed()) {568String s = (((checked & PARSEFAIL) != 0)569? "Correct exception" : "UNEXPECTED EXCEPTION");570if (exc instanceof URISyntaxException)571show(s, (URISyntaxException)exc);572else {573out.println(uquote(sb.toString()));574out.print(s + ": ");575exc.printStackTrace(out);576}577} else {578if (uri != originalURI) {579sb.append(" ");580sb.append(op);581sb.append(" --> ");582sb.append(uri);583}584out.println(uquote(sb.toString()));585}586}587588public static String uquote(String str) {589if (str == null)590return str;591StringBuffer sb = new StringBuffer();592int n = str.length();593for (int i = 0; i < n; i++) {594char c = str.charAt(i);595if ((c >= ' ') && (c < 0x7f)) {596sb.append(c);597continue;598}599sb.append("\\u");600String s = Integer.toHexString(c).toUpperCase();601while (s.length() < 4)602s = "0" + s;603sb.append(s);604}605return sb.toString();606}607608static void show(String n, String v) {609out.println(" " + n610+ " = ".substring(n.length())611+ uquote(v));612}613614static void show(String n, String v, String vd) {615if ((v == null) || v.equals(vd))616show(n, v);617else {618out.println(" " + n619+ " = ".substring(n.length())620+ uquote(v)621+ " = " + uquote(vd));622}623}624625public static void show(URI u) {626show("opaque", "" + u.isOpaque());627show("scheme", u.getScheme());628show("ssp", u.getRawSchemeSpecificPart(), u.getSchemeSpecificPart());629show("authority", u.getRawAuthority(), u.getAuthority());630show("userinfo", u.getRawUserInfo(), u.getUserInfo());631show("host", u.getHost());632show("port", "" + u.getPort());633show("path", u.getRawPath(), u.getPath());634show("query", u.getRawQuery(), u.getQuery());635show("fragment", u.getRawFragment(), u.getFragment());636if (!u.toString().equals(u.toASCIIString()))637show("toascii", u.toASCIIString());638}639640private void report() {641summarize();642if (failed == 0) return;643StringBuffer sb = new StringBuffer();644sb.append("FAIL:");645if ((failed & PARSEFAIL) != 0) sb.append(" parsefail");646if ((failed & SCHEME) != 0) sb.append(" scheme");647if ((failed & SSP) != 0) sb.append(" ssp");648if ((failed & OPAQUEPART) != 0) sb.append(" opaquepart");649if ((failed & USERINFO) != 0) sb.append(" userinfo");650if ((failed & USERINFO_D) != 0) sb.append(" userinfod");651if ((failed & HOST) != 0) sb.append(" host");652if ((failed & PORT) != 0) sb.append(" port");653if ((failed & REGISTRY) != 0) sb.append(" registry");654if ((failed & PATH) != 0) sb.append(" path");655if ((failed & PATH_D) != 0) sb.append(" pathd");656if ((failed & QUERY) != 0) sb.append(" query");657if ((failed & QUERY_D) != 0) sb.append(" queryd");658if ((failed & FRAGMENT) != 0) sb.append(" fragment");659if ((failed & FRAGMENT_D) != 0) sb.append(" fragmentd");660if ((failed & TOASCII) != 0) sb.append(" toascii");661if ((failed & IDENT_STR) != 0) sb.append(" ident-str");662if ((failed & IDENT_URI1) != 0) sb.append(" ident-uri1");663if ((failed & IDENT_URI3) != 0) sb.append(" ident-uri3");664if ((failed & IDENT_URI5) != 0) sb.append(" ident-uri5");665if ((failed & IDENT_URI7) != 0) sb.append(" ident-uri7");666if ((failed & TOSTRING) != 0) sb.append(" tostring");667out.println(sb.toString());668if (uri != null) show(uri);669throw new RuntimeException("Test failed");670}671672673674// -- Tests --675676static void rfc2396() {677678679header("RFC2396: Basic examples");680681test("ftp://ftp.is.co.za/rfc/rfc1808.txt")682.s("ftp").h("ftp.is.co.za").p("/rfc/rfc1808.txt").z();683684test("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles")685.s("gopher").h("spinaltap.micro.umn.edu")686.p("/00/Weather/California/Los%20Angeles").z();687688test("http://www.math.uio.no/faq/compression-faq/part1.html")689.s("http").h("www.math.uio.no").p("/faq/compression-faq/part1.html").z();690691test("mailto:[email protected]")692.s("mailto").o("[email protected]").z();693694test("news:comp.infosystems.www.servers.unix")695.s("news").o("comp.infosystems.www.servers.unix").z();696697test("telnet://melvyl.ucop.edu/")698.s("telnet").h("melvyl.ucop.edu").p("/").z();699700test("http://www.w3.org/Addressing/")701.s("http").h("www.w3.org").p("/Addressing/").z();702703test("ftp://ds.internic.net/rfc/")704.s("ftp").h("ds.internic.net").p("/rfc/").z();705706test("http://www.ics.uci.edu/pub/ietf/uri/historical.html#WARNING")707.s("http").h("www.ics.uci.edu").p("/pub/ietf/uri/historical.html")708.f("WARNING").z();709710test("http://www.ics.uci.edu/pub/ietf/uri/#Related")711.s("http").h("www.ics.uci.edu").p("/pub/ietf/uri/")712.f("Related").z();713714715header("RFC2396: Normal relative-URI examples (appendix C)");716717URI base = (test("http://a/b/c/d;p?q")718.s("http").h("a").p("/b/c/d;p").q("q").z().uri());719720// g:h g:h721test("g:h")722.s("g").o("h").z()723.rslv(base).s("g").o("h").z();724725// g http://a/b/c/g726test("g")727.p("g").z()728.rslv(base).s("http").h("a").p("/b/c/g").z();729730// ./g http://a/b/c/g731test("./g")732.p("./g").z()733.rslv(base).s("http").h("a").p("/b/c/g").z();734735// g/ http://a/b/c/g/736test("g/")737.p("g/").z()738.rslv(base).s("http").h("a").p("/b/c/g/").z();739740// /g http://a/g741test("/g")742.p("/g").z()743.rslv(base).s("http").h("a").p("/g").z();744745// //g http://g746test("//g")747.h("g").p("").z()748.rslv(base).s("http").h("g").p("").z();749750// ?y http://a/b/c/?y751test("?y")752.p("").q("y").z()753.rslv(base).s("http").h("a").p("/b/c/").q("y").z();754755// g?y http://a/b/c/g?y756test("g?y")757.p("g").q("y").z()758.rslv(base).s("http").h("a").p("/b/c/g").q("y").z();759760// #s (current document)#s761// DEVIATION: Lone fragment parses as relative URI with empty path762test("#s")763.p("").f("s").z()764.rslv(base).s("http").h("a").p("/b/c/d;p").f("s").q("q").z();765766// g#s http://a/b/c/g#s767test("g#s")768.p("g").f("s").z()769.rslv(base).s("http").h("a").p("/b/c/g").f("s").z();770771// g?y#s http://a/b/c/g?y#s772test("g?y#s")773.p("g").q("y").f("s").z()774.rslv(base).s("http").h("a").p("/b/c/g").q("y").f("s").z();775776// ;x http://a/b/c/;x777test(";x")778.p(";x").z()779.rslv(base).s("http").h("a").p("/b/c/;x").z();780781// g;x http://a/b/c/g;x782test("g;x")783.p("g;x").z()784.rslv(base).s("http").h("a").p("/b/c/g;x").z();785786// g;x?y#s http://a/b/c/g;x?y#s787test("g;x?y#s")788.p("g;x").q("y").f("s").z()789.rslv(base).s("http").h("a").p("/b/c/g;x").q("y").f("s").z();790791// . http://a/b/c/792test(".")793.p(".").z()794.rslv(base).s("http").h("a").p("/b/c/").z();795796// ./ http://a/b/c/797test("./")798.p("./").z()799.rslv(base).s("http").h("a").p("/b/c/").z();800801// .. http://a/b/802test("..")803.p("..").z()804.rslv(base).s("http").h("a").p("/b/").z();805806// ../ http://a/b/807test("../")808.p("../").z()809.rslv(base).s("http").h("a").p("/b/").z();810811// ../g http://a/b/g812test("../g")813.p("../g").z()814.rslv(base).s("http").h("a").p("/b/g").z();815816// ../.. http://a/817test("../..")818.p("../..").z()819.rslv(base).s("http").h("a").p("/").z();820821// ../../ http://a/822test("../../")823.p("../../").z()824.rslv(base).s("http").h("a").p("/").z();825826// ../../g http://a/g827test("../../g")828.p("../../g").z()829.rslv(base).s("http").h("a").p("/g").z();830831832header("RFC2396: Abnormal relative-URI examples (appendix C)");833834// ../../../g = http://a/../g835test("../../../g")836.p("../../../g").z()837.rslv(base).s("http").h("a").p("/../g").z();838839// ../../../../g = http://a/../../g840test("../../../../g")841.p("../../../../g").z()842.rslv(base).s("http").h("a").p("/../../g").z();843844845// /./g = http://a/./g846test("/./g")847.p("/./g").z()848.rslv(base).s("http").h("a").p("/./g").z();849850// /../g = http://a/../g851test("/../g")852.p("/../g").z()853.rslv(base).s("http").h("a").p("/../g").z();854855// g. = http://a/b/c/g.856test("g.")857.p("g.").z()858.rslv(base).s("http").h("a").p("/b/c/g.").z();859860// .g = http://a/b/c/.g861test(".g")862.p(".g").z()863.rslv(base).s("http").h("a").p("/b/c/.g").z();864865// g.. = http://a/b/c/g..866test("g..")867.p("g..").z()868.rslv(base).s("http").h("a").p("/b/c/g..").z();869870// ..g = http://a/b/c/..g871test("..g")872.p("..g").z()873.rslv(base).s("http").h("a").p("/b/c/..g").z();874875// ./../g = http://a/b/g876test("./../g")877.p("./../g").z()878.rslv(base).s("http").h("a").p("/b/g").z();879880// ./g/. = http://a/b/c/g/881test("./g/.")882.p("./g/.").z()883.rslv(base).s("http").h("a").p("/b/c/g/").z();884885// g/./h = http://a/b/c/g/h886test("g/./h")887.p("g/./h").z()888.rslv(base).s("http").h("a").p("/b/c/g/h").z();889890// g/../h = http://a/b/c/h891test("g/../h")892.p("g/../h").z()893.rslv(base).s("http").h("a").p("/b/c/h").z();894895// g;x=1/./y = http://a/b/c/g;x=1/y896test("g;x=1/./y")897.p("g;x=1/./y").z()898.rslv(base).s("http").h("a").p("/b/c/g;x=1/y").z();899900// g;x=1/../y = http://a/b/c/y901test("g;x=1/../y")902.p("g;x=1/../y").z()903.rslv(base).s("http").h("a").p("/b/c/y").z();904905// g?y/./x = http://a/b/c/g?y/./x906test("g?y/./x")907.p("g").q("y/./x").z()908.rslv(base).s("http").h("a").p("/b/c/g").q("y/./x").z();909910// g?y/../x = http://a/b/c/g?y/../x911test("g?y/../x")912.p("g").q("y/../x").z()913.rslv(base).s("http").h("a").p("/b/c/g").q("y/../x").z();914915// g#s/./x = http://a/b/c/g#s/./x916test("g#s/./x")917.p("g").f("s/./x").z()918.rslv(base).s("http").h("a").p("/b/c/g").f("s/./x").z();919920// g#s/../x = http://a/b/c/g#s/../x921test("g#s/../x")922.p("g").f("s/../x").z()923.rslv(base).s("http").h("a").p("/b/c/g").f("s/../x").z();924925// http:g = http:g926test("http:g")927.s("http").o("g").z()928.rslv(base).s("http").o("g").z();929930}931932933static void ip() {934935header("IP addresses");936937test("http://1.2.3.4:5")938.s("http").h("1.2.3.4").n(5).p("").z();939940// From RFC2732941942test("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html")943.s("http").h("[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]")944.n(80).p("/index.html").z();945946test("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:10%12]:80/index.html")947.s("http").h("[FEDC:BA98:7654:3210:FEDC:BA98:7654:10%12]")948.n(80).p("/index.html").z();949950test("http://[1080:0:0:0:8:800:200C:417A]/index.html")951.s("http").h("[1080:0:0:0:8:800:200C:417A]").p("/index.html").z();952953test("http://[1080:0:0:0:8:800:200C:417A%1]/index.html")954.s("http").h("[1080:0:0:0:8:800:200C:417A%1]").p("/index.html").z();955956test("http://[3ffe:2a00:100:7031::1]")957.s("http").h("[3ffe:2a00:100:7031::1]").p("").z();958959test("http://[1080::8:800:200C:417A]/foo")960.s("http").h("[1080::8:800:200C:417A]").p("/foo").z();961962test("http://[::192.9.5.5]/ipng")963.s("http").h("[::192.9.5.5]").p("/ipng").z();964965test("http://[::192.9.5.5%interface]/ipng")966.s("http").h("[::192.9.5.5%interface]").p("/ipng").z();967968test("http://[::FFFF:129.144.52.38]:80/index.html")969.s("http").h("[::FFFF:129.144.52.38]").n(80).p("/index.html").z();970971test("http://[2010:836B:4179::836B:4179]")972.s("http").h("[2010:836B:4179::836B:4179]").p("").z();973974// From RFC2373975976test("http://[FF01::101]")977.s("http").h("[FF01::101]").p("").z();978979test("http://[::1]")980.s("http").h("[::1]").p("").z();981982test("http://[::]")983.s("http").h("[::]").p("").z();984985test("http://[::%hme0]")986.s("http").h("[::%hme0]").p("").z();987988test("http://[0:0:0:0:0:0:13.1.68.3]")989.s("http").h("[0:0:0:0:0:0:13.1.68.3]").p("").z();990991test("http://[0:0:0:0:0:FFFF:129.144.52.38]")992.s("http").h("[0:0:0:0:0:FFFF:129.144.52.38]").p("").z();993994test("http://[0:0:0:0:0:FFFF:129.144.52.38%33]")995.s("http").h("[0:0:0:0:0:FFFF:129.144.52.38%33]").p("").z();996997test("http://[0:0:0:0:0:ffff:1.2.3.4]")998.s("http").h("[0:0:0:0:0:ffff:1.2.3.4]").p("").z();9991000test("http://[::13.1.68.3]")1001.s("http").h("[::13.1.68.3]").p("").z();10021003// Optional IPv6 brackets in constructors10041005test("s", null, "1:2:3:4:5:6:7:8", -1, null, null, null)1006.s("s").h("[1:2:3:4:5:6:7:8]").p("").z();10071008test("s", null, "[1:2:3:4:5:6:7:8]", -1, null, null, null)1009.s("s").h("[1:2:3:4:5:6:7:8]").p("").z();10101011test("s", null, "[1:2:3:4:5:6:7:8]", -1, null, null, null)1012.s("s").h("[1:2:3:4:5:6:7:8]").p("").z();10131014test("s", "1:2:3:4:5:6:7:8", null, null)1015.s("s").h("[1:2:3:4:5:6:7:8]").p("").z();10161017test("s", "1:2:3:4:5:6:7:8%hme0", null, null)1018.s("s").h("[1:2:3:4:5:6:7:8%hme0]").p("").z();10191020test("s", "1:2:3:4:5:6:7:8%1", null, null)1021.s("s").h("[1:2:3:4:5:6:7:8%1]").p("").z();10221023test("s", "[1:2:3:4:5:6:7:8]", null, null)1024.s("s").h("[1:2:3:4:5:6:7:8]").p("").z();10251026test("s", "[1:2:3:4:5:6:7:8]", null, null, null)1027.s("s").h("[1:2:3:4:5:6:7:8]").p("").z();10281029test("s", "1:2:3:4:5:6:7:8", null, null, null)1030.s("s").g("1:2:3:4:5:6:7:8").p("").z();10311032// Error cases10331034test("http://[ff01:234/foo").x().z();1035test("http://[ff01:234:zzz]/foo").x().z();1036test("http://[foo]").x().z();1037test("http://[]").x().z();1038test("http://[129.33.44.55]").x().z();1039test("http://[ff:ee:dd:cc:bb::aa:9:8]").x().z();1040test("http://[fffff::1]").x().z();1041test("http://[ff::ee::8]").x().z();1042test("http://[1:2:3:4::5:6:7:8]").x().z();1043test("http://[1:2]").x().z();1044test("http://[1:2:3:4:5:6:7:8:9]").x().z();1045test("http://[1:2:3:4:5:6:7:8%]").x().z();1046test("http://[1:2:3:4:5:6:7:8%!/]").x().z();1047test("http://[::1.2.3.300]").x().z();1048test("http://1.2.3").psa().x().z();1049test("http://1.2.3.300").psa().x().z();1050test("http://1.2.3.4.5").psa().x().z();1051test("http://[1.2.3.4:5]").x().z();1052test("http://1:2:3:4:5:6:7:8").psa().x().z();1053test("http://[1.2.3.4]/").x().z();1054test("http://[1.2.3.4/").x().z();1055test("http://[foo]/").x().z();1056test("http://[foo/").x().z();1057test("s", "[foo]", "/", null, null).x().z();1058test("s", "[foo", "/", null, null).x().z();1059test("s", "[::foo", "/", null, null).x().z();10601061// Test hostnames that might initially look like IPv4 addresses10621063test("s://1.2.3.com").psa().s("s").h("1.2.3.com").p("").z();1064test("s://1.2.3.4me.com").psa().s("s").h("1.2.3.4me.com").p("").z();10651066test("s://7up.com").psa().s("s").h("7up.com").p("").z();1067test("s://7up.com/p").psa().s("s").h("7up.com").p("/p").z();1068test("s://7up").psa().s("s").h("7up").p("").z();1069test("s://7up/p").psa().s("s").h("7up").p("/p").z();1070test("s://7up.").psa().s("s").h("7up.").p("").z();1071test("s://7up./p").psa().s("s").h("7up.").p("/p").z();1072}107310741075static void misc() throws URISyntaxException {10761077URI base = new URI("s://h/a/b");1078URI rbase = new URI("a/b/c/d");107910801081header("Corner cases");10821083// The empty URI parses as a relative URI with an empty path1084test("").p("").z()1085.rslv(base).s("s").h("h").p("/a/").z();10861087// Resolving solo queries and fragments1088test("#f").p("").f("f").z()1089.rslv(base).s("s").h("h").p("/a/b").f("f").z();1090test("?q").p("").q("q").z()1091.rslv(base).s("s").h("h").p("/a/").q("q").z();10921093// Fragment is not part of ssp1094test("p#f").p("p").f("f").sp("p").z();1095test("s:p#f").s("s").o("p").f("f").z();1096test("p#f")1097.rslv(base).s("s").h("h").p("/a/p").f("f").sp("//h/a/p").z();1098test("").p("").sp("").z();1099110011011102header("Emptiness");11031104// Components that may be empty1105test("///p").p("/p").z(); // Authority (w/ path)1106test("//@h/p").u("").h("h").p("/p").z(); // User info1107test("//h:/p").h("h").p("/p").z(); // Port1108test("//h").h("h").p("").z(); // Path1109test("//h?q").h("h").p("").q("q").z(); // Path (w/query)1110test("//?q").p("").q("q").z(); // Authority (w/query)1111test("//#f").p("").f("f").z(); // Authority (w/fragment)1112test("p?#").p("p").q("").f("").z(); // Query & fragment11131114// Components that may not be empty1115test(":").x().z(); // Scheme1116test("x:").x().z(); // Hier/opaque1117test("//").x().z(); // Authority (w/o path)111811191120header("Resolution, normalization, and relativization");11211122// Resolving relative paths1123test("../e/f").p("../e/f").z()1124.rslv(rbase).p("a/b/e/f").z();1125test("../../../../d").p("../../../../d").z()1126.rslv(rbase).p("../d").z();1127test("../../../d:e").p("../../../d:e").z()1128.rslv(rbase).p("./d:e").z();1129test("../../../d:e/f").p("../../../d:e/f").z()1130.rslv(rbase).p("./d:e/f").z();11311132// Normalization1133test("a/./c/../d/f").p("a/./c/../d/f").z()1134.norm().p("a/d/f").z();1135test("http://a/./b/c/../d?q#f")1136.s("http").h("a").p("/./b/c/../d").q("q").f("f").z()1137.norm().s("http").h("a").p("/b/d").q("q").f("f").z();1138test("a/../b").p("a/../b").z().1139norm().p("b");1140test("a/../b:c").p("a/../b:c").z()1141.norm().p("./b:c").z();11421143// Normalization of already normalized URI should yield the1144// same URI1145URI u1 = URI.create("s://h/../p");1146URI u2 = u1.normalize();1147eq(u1, u2);1148eqeq(u1, u2);11491150// Relativization1151test("/a/b").p("/a/b").z()1152.rtvz(new URI("/a")).p("b").z();1153test("/a/b").p("/a/b").z()1154.rtvz(new URI("/a/")).p("b").z();1155test("a/b").p("a/b").z()1156.rtvz(new URI("a")).p("b").z();1157test("/a/b").p("/a/b").z()1158.rtvz(new URI("/a/b")).p("").z(); // Result is empty path1159test("a/../b:c/d").p("a/../b:c/d").z()1160.rtvz(new URI("./b:c/")).p("d").z();11611162test("http://a/b/d/e?q#f")1163.s("http").h("a").p("/b/d/e").q("q").f("f").z()1164.rtvz(new URI("http://a/b/?r#g"))1165.p("d/e").q("q").f("f").z();11661167// parseServerAuthority1168test("/a/b").psa().p("/a/b").z();1169test("s://u@h:1/p")1170.psa().s("s").u("u").h("h").n(1).p("/p").z();1171test("s://u@h:-foo/p").s("s").g("u@h:-foo").p("/p").z()1172.psa().x().z();1173test("s://h:999999999999999999999999").psa().x().z();1174test("s://:/b").psa().x().z();117511761177header("Constructors and factories");11781179test("s", null, null, -1, "p", null, null).x().z();1180test(null, null, null, -1, null, null, null).p("").z();1181test(null, null, null, -1, "p", null, null).p("p").z();1182test(null, null, "foo%20bar", -1, null, null, null).x().z();1183test(null, null, "foo", -100, null, null, null).x().z();1184test("s", null, null, -1, "", null, null).x().z();1185test("s", null, null, -1, "/p", null, null).s("s").p("/p").z();1186test("s", "u", "h", 10, "/p", "q", "f")1187.s("s").u("u").h("h").n(10).p("/p").q("q").f("f").z();1188test("s", "a:b", "/p", "q", "f")1189.s("s").g("a:b").p("/p").q("q").f("f").z();1190test("s", "h", "/p", "f")1191.s("s").h("h").p("/p").f("f").z();1192test("s", "p", "f").s("s").o("p").f("f").z();1193test("s", "/p", "f").s("s").p("/p").f("f").z();1194testCreate("s://u@h/p?q#f")1195.s("s").u("u").h("h").p("/p").q("q").f("f").z();1196}11971198static void npes() throws URISyntaxException {11991200header("NullPointerException");12011202URI base = URI.create("mailto:[email protected]");12031204out.println();12051206try {1207base.resolve((URI)null);1208throw new RuntimeException("NullPointerException not thrown");1209} catch (NullPointerException x) {1210out.println("resolve((URI)null) -->");1211out.println("Correct exception: " + x);1212}12131214out.println();12151216try {1217base.resolve((String)null);1218throw new RuntimeException("NullPointerException not thrown");1219} catch (NullPointerException x) {1220out.println("resolve((String)null) -->");1221out.println("Correct exception: " + x);1222}12231224out.println();12251226try {1227base.relativize((URI)null);1228throw new RuntimeException("NullPointerException not thrown");1229} catch (NullPointerException x) {1230out.println("relativize((String)null) -->");1231out.println("Correct exception: " + x);1232}12331234testCount += 3;1235}123612371238static void chars() throws URISyntaxException {12391240header("Escapes and non-US-ASCII characters");12411242URI uri;12431244// Escape pairs1245test("%0a%0A%0f%0F%01%09zz")1246.p("%0a%0A%0f%0F%01%09zz").z();1247test("foo%1").x().z();1248test("foo%z").x().z();1249test("foo%9z").x().z();12501251// Escapes not permitted in scheme, host1252test("s%20t://a").x().z();1253test("//a%20b").g("a%20b").p("").z(); // Parses as registry12541255// Escapes permitted in opaque part, userInfo, registry, path,1256// query, and fragment1257test("//u%20v@a").u("u%20v").h("a").p("").z();1258test("/p%20q").p("/p%20q").z();1259test("/p?q%20").p("/p").q("q%20").z();1260test("/p#%20f").p("/p").f("%20f").z();12611262// Non-US-ASCII chars1263test("s\u00a7t://a").x().z();1264test("//\u00a7/b").g("\u00a7").p("/b").z(); // Parses as registry1265test("//u\u00a7v@a").u("u\u00a7v").h("a").p("").z();1266test("/p\u00a7q").p("/p\u00a7q").z();1267test("/p?q\u00a7").p("/p").q("q\u00a7").z();1268test("/p#\u00a7f").p("/p").f("\u00a7f").z();12691270// 4648111 - Escapes quoted by toString after resolution1271uri = new URI("http://a/b/c/d;p?q");1272test("/p%20p")1273.rslv(uri).s("http").h("a").p("/p%20p").ts("http://a/p%20p").z();12741275// 4464135: Forbid unwise characters throughout opaque part1276test("foo:x{bar").x().z();1277test("foo:{bar").x().z();12781279// 4438319: Single-argument constructor requires quotation,1280// preserves escapes1281test("//u%01@h/a/b/%02/c?q%03#f%04")1282.u("u%01").ud("u\1")1283.h("h")1284.p("/a/b/%02/c").pd("/a/b/\2/c")1285.q("q%03").qd("q\3")1286.f("f%04").fd("f\4")1287.z();1288test("/a/b c").x().z();12891290// 4438319: Multi-argument constructors quote illegal chars and1291// preserve legal non-ASCII chars1292// \uA001-\uA009 are visible characters, \u2000 is a space character1293test(null, "u\uA001\1", "h", -1,1294"/p% \uA002\2\u2000",1295"q% \uA003\3\u2000",1296"f% \uA004\4\u2000")1297.u("u\uA001%01").h("h")1298.p("/p%25%20\uA002%02%E2%80%80").pd("/p% \uA002\2\u2000")1299.q("q%25%20\uA003%03%E2%80%80").qd("q% \uA003\3\u2000")1300.f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();1301test(null, "g\uA001\1",1302"/p% \uA002\2\u2000",1303"q% \uA003\3\u2000",1304"f% \uA004\4\u2000")1305.g("g\uA001%01")1306.p("/p%25%20\uA002%02%E2%80%80").pd("/p% \uA002\2\u2000")1307.q("q%25%20\uA003%03%E2%80%80").qd("q% \uA003\3\u2000")1308.f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();1309test(null, null, "/p% \uA002\2\u2000", "f% \uA004\4\u2000")1310.p("/p%25%20\uA002%02%E2%80%80").pd("/p% \uA002\2\u2000")1311.f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();1312test(null, "/sp% \uA001\1\u2000", "f% \uA004\4\u2000")1313.sp("/sp%25%20\uA001%01%E2%80%80").spd("/sp% \uA001\1\u2000")1314.p("/sp%25%20\uA001%01%E2%80%80").pd("/sp% \uA001\1\u2000")1315.f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();13161317// 4438319: Non-raw accessors decode all escaped octets1318test("/%25%20%E2%82%AC%E2%80%80")1319.p("/%25%20%E2%82%AC%E2%80%80").pd("/% \u20Ac\u2000").z();13201321// 4438319: toASCIIString1322test("/\uCAFE\uBABE")1323.p("/\uCAFE\uBABE").ta("/%EC%AB%BE%EB%AA%BE").z();13241325// 4991359 and 4866303: bad quoting by defineSchemeSpecificPart()1326URI base = new URI ("http://host/foo%20bar/a/b/c/d");1327test ("resolve")1328.rslv(base).spd("//host/foo bar/a/b/c/resolve")1329.sp("//host/foo%20bar/a/b/c/resolve").s("http")1330.pd("/foo bar/a/b/c/resolve").h("host")1331.p("/foo%20bar/a/b/c/resolve").z();13321333// 6773270: java.net.URI fails to escape u00001334test("s", "a", "/\u0000", null)1335.s("s").p("/%00").h("a")1336.ta("s://a/%00").z();1337}133813391340static void eq0(URI u, URI v) throws URISyntaxException {1341testCount++;1342if (!u.equals(v))1343throw new RuntimeException("Not equal: " + u + " " + v);1344int uh = u.hashCode();1345int vh = v.hashCode();1346if (uh != vh)1347throw new RuntimeException("Hash codes not equal: "1348+ u + " " + Integer.toHexString(uh) + " "1349+ v + " " + Integer.toHexString(vh));1350out.println();1351out.println(u + " == " + v1352+ " [" + Integer.toHexString(uh) + "]");1353}13541355static void cmp0(URI u, URI v, boolean same)1356throws URISyntaxException1357{1358int c = u.compareTo(v);1359if ((c == 0) != same)1360throw new RuntimeException("Comparison inconsistent: " + u + " " + v1361+ " " + c);1362}13631364static void eq(URI u, URI v) throws URISyntaxException {1365eq0(u, v);1366cmp0(u, v, true);1367}13681369static void eqeq(URI u, URI v) {1370testCount++;1371if (u != v)1372throw new RuntimeException("Not ==: " + u + " " + v);1373}13741375static void ne0(URI u, URI v) throws URISyntaxException {1376testCount++;1377if (u.equals(v))1378throw new RuntimeException("Equal: " + u + " " + v);1379out.println();1380out.println(u + " != " + v1381+ " [" + Integer.toHexString(u.hashCode())1382+ " " + Integer.toHexString(v.hashCode())1383+ "]");1384}13851386static void ne(URI u, URI v) throws URISyntaxException {1387ne0(u, v);1388cmp0(u, v, false);1389}13901391static void lt(URI u, URI v) throws URISyntaxException {1392ne0(u, v);1393int c = u.compareTo(v);1394if (c >= 0) {1395show(u);1396show(v);1397throw new RuntimeException("Not less than: " + u + " " + v1398+ " " + c);1399}1400out.println(u + " < " + v);1401}14021403static void lt(String s, String t) throws URISyntaxException {1404lt(new URI(s), new URI(t));1405}14061407static void gt(URI u, URI v) throws URISyntaxException {1408lt(v, u);1409}14101411static void eqHashComp() throws URISyntaxException {14121413header("Equality, hashing, and comparison");14141415URI o = new URI("mailto:[email protected]");1416URI r = new URI("reg://some%20registry/b/c/d?q#f");1417URI s = new URI("http://jag:[email protected]:94/b/c/d?q#f");1418eq(o, o);1419lt(o, r);1420lt(s, o);1421lt(s, r);1422eq(o, new URI("MaILto:[email protected]"));1423gt(o, new URI("mailto:[email protected]"));1424eq(r, new URI("rEg://some%20registry/b/c/d?q#f"));1425gt(r, new URI("reg://Some%20Registry/b/c/d?q#f"));1426gt(r, new URI("reg://some%20registry/b/c/D?q#f"));1427eq(s, new URI("hTtP://jag:[email protected]:94/b/c/d?q#f"));1428gt(s, new URI("http://jag:[email protected]:94/b/c/d?q#f"));1429lt(s, new URI("http://jag:[email protected]:94/b/c/d?r#f"));1430lt(s, new URI("http://jag:[email protected]:94/b/c/d?q#g"));1431eq(new URI("http://host/a%00bcd"), new URI("http://host/a%00bcd"));1432ne(new URI("http://host/a%00bcd"), new URI("http://host/aZ00bcd"));1433eq0(new URI("http://host/abc%e2def%C3ghi"),1434new URI("http://host/abc%E2def%c3ghi"));14351436lt("p", "s:p");1437lt("s:p", "T:p");1438lt("S:p", "t:p");1439lt("s:/p", "s:p");1440lt("s:p", "s:q");1441lt("s:p#f", "s:p#g");1442lt("s://u@h:1", "s://v@h:1");1443lt("s://u@h:1", "s://u@i:1");1444lt("s://u@h:1", "s://v@h:2");1445lt("s://a%20b", "s://a%20c");1446lt("s://a%20b", "s://aab");1447lt("s://AA", "s://A_");1448lt("s:/p", "s:/q");1449lt("s:/p?q", "s:/p?r");1450lt("s:/p#f", "s:/p#g");14511452lt("s://h", "s://h/p");1453lt("s://h/p", "s://h/p?q");14541455}145614571458static void serial(URI u) throws IOException, URISyntaxException {14591460ByteArrayOutputStream bo = new ByteArrayOutputStream();1461ObjectOutputStream oo = new ObjectOutputStream(bo);14621463oo.writeObject(u);1464oo.close();14651466ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());1467ObjectInputStream oi = new ObjectInputStream(bi);1468try {1469Object o = oi.readObject();1470eq(u, (URI)o);1471} catch (ClassNotFoundException x) {1472x.printStackTrace();1473throw new RuntimeException(x.toString());1474}14751476testCount++;1477}14781479static void serial() throws IOException, URISyntaxException {1480header("Serialization");14811482serial(URI.create("http://java.sun.com/jdk/1.4?release#beta"));1483serial(URI.create("s://h/p").resolve("/long%20path/"));1484}148514861487static void urls() throws URISyntaxException {14881489header("URLs");14901491URI uri;1492URL url;1493boolean caught = false;14941495out.println();1496uri = new URI("http://a/p?q#f");1497try {1498url = uri.toURL();1499} catch (MalformedURLException x) {1500throw new RuntimeException(x.toString());1501}1502if (!url.toString().equals("http://a/p?q#f"))1503throw new RuntimeException("Incorrect URL: " + url);1504out.println(uri + " url --> " + url);15051506out.println();1507uri = new URI("a/b");1508try {1509out.println(uri + " url --> ");1510url = uri.toURL();1511} catch (IllegalArgumentException x) {1512caught = true;1513out.println("Correct exception: " + x);1514} catch (MalformedURLException x) {1515caught = true;1516throw new RuntimeException("Incorrect exception: " + x);1517}1518if (!caught)1519throw new RuntimeException("Incorrect URL: " + url);15201521out.println();1522uri = new URI("foo://bar/baz");1523caught = false;1524try {1525out.println(uri + " url --> ");1526url = uri.toURL();1527} catch (MalformedURLException x) {1528caught = true;1529out.println("Correct exception: " + x);1530} catch (IllegalArgumentException x) {1531caught = true;1532throw new RuntimeException("Incorrect exception: " + x);1533}1534if (!caught)1535throw new RuntimeException("Incorrect URL: " + url);15361537testCount += 3;1538}153915401541static void tests() throws IOException, URISyntaxException {1542rfc2396();1543ip();1544misc();1545chars();1546eqHashComp();1547serial();1548urls();1549npes();1550bugs();1551}155215531554// -- Command-line invocation --15551556static void usage() {1557out.println("Usage:");1558out.println(" java Test -- Runs all tests in this file");1559out.println(" java Test <uri> -- Parses uri, shows components");1560out.println(" java Test <base> <uri> -- Parses uri and base, then resolves");1561out.println(" uri against base");1562}15631564static void clargs(String base, String uri) {1565URI b = null, u;1566try {1567if (base != null) {1568b = new URI(base);1569out.println(base);1570show(b);1571}1572u = new URI(uri);1573out.println(uri);1574show(u);1575if (base != null) {1576URI r = b.resolve(u);1577out.println(r);1578show(r);1579}1580} catch (URISyntaxException x) {1581show("ERROR", x);1582x.printStackTrace(out);1583}1584}158515861587// miscellaneous bugs/rfes that don't fit in with the test framework15881589static void bugs() throws URISyntaxException {1590// 6339649 - include detail message from nested exception1591try {1592URI uri = URI.create("http://nowhere.net/should not be permitted");1593} catch (IllegalArgumentException e) {1594if ("".equals(e.getMessage()) || e.getMessage() == null) {1595throw new RuntimeException ("No detail message");1596}1597}15981599// 8051853 - getRawSchemeSpecificPart returns null1600String rssp = new URI("x/").resolve("..").getRawSchemeSpecificPart();1601if (!"".equals(rssp)) {1602throw new RuntimeException("Incorrect RawSchemeSpecificPart: [" + rssp + "], must be an empty string");1603}1604}16051606public static void main(String[] args) throws Exception {1607switch (args.length) {16081609case 0:1610tests();1611out.println();1612out.println("Test cases: " + testCount);1613break;16141615case 1:1616if (args[0].equals("-help")) {1617usage();1618break;1619}1620clargs(null, args[0]);1621break;16221623case 2:1624clargs(args[0], args[1]);1625break;16261627default:1628usage();1629break;16301631}1632}16331634}163516361637