/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @summary Unit test for java.net.URL (Based on the URI tests that is authored by Mark Reinhold)
* @bug 4496251
*/
public class Test {
// Properties that we check
testCount++;
input = s;
try {
} catch (MalformedURLException x) {
exc = x;
}
originalURL = url;
}
return new Test(s);
}
testCount++;
try {
} catch (Exception x) {
exc = x;
}
originalURL = url;
}
}
testCount++;
try {
} catch (Exception x) {
exc = x;
}
originalURL = url;
}
}
testCount++;
try {
} catch (Exception x) {
exc = x;
}
originalURL = url;
}
boolean parsed() {
}
boolean resolved() {
}
return url;
}
// Operations on Test instances
//
// These are short so as to make test cases compact.
//
// s Scheme
// u User info
// h Host
// n port Number
// p Path
// q Query
// f Fragment
//
// rslv Resolve against given base
// rtvz Relativize
// psa Parse server Authority
// norm Normalize
//
// x Check that parse failed as expected
// z End -- ensure that unchecked components are null
if (!parsed()) {
return false;
}
return true;
}
return;
}
return this;
}
return this;
}
return this;
}
Test n(int n) {
return this;
}
return this;
}
return this;
}
return this;
}
Test x() {
if (parsed())
return this;
}
}
// Check that unchecked component properties are not defined,
// and report any failures
Test z() {
if (!parsed()) {
report();
return this;
}
report();
return this;
}
// Summarization and reporting
}
}
private void summarize() {
else
}
if (!parsed()) {
? "Correct exception" : "UNEXPECTED EXCEPTION");
if (exc instanceof MalformedURLException)
else {
}
} else {
if (url != originalURL) {
}
}
}
}
}
private void report() {
summarize();
if (failed == 0) return;
throw new RuntimeException("Test failed");
}
// -- Tests --
static void rfc2396() {
header("RFC2396: Basic examples");
.s("http").h("www.w3.org").p("/Addressing/").z();
.s("ftp").h("ds.internic.net").p("/rfc/").z();
.f("WARNING").z();
test("http://www.ics.uci.edu/pub/ietf/url/#Related")
.f("Related").z();
header("RFC2396: Normal relative-URL examples (appendix C)");
// g:h g:h
// test(base, "http:h").s("g").p("h").z();
// g http://a/b/c/g
// ./g http://a/b/c/g
// g/ http://a/b/c/g/
// /g http://a/g
// //g http://g
// ?y http://a/b/c/?y
// g?y http://a/b/c/g?y
// #s (current document)#s
// DEVIATION: Lone fragment parses as relative URL with empty path,
// and resolves without removing the last segment of the base path.
// test(base,"#s").s("http").h("a").p("/b/c/d;p").f("s").z();
// g#s http://a/b/c/g#s
// g?y#s http://a/b/c/g?y#s
// ;x http://a/b/c/;x
// g;x http://a/b/c/g;x
// g;x?y#s http://a/b/c/g;x?y#s
// . http://a/b/c/
// ./ http://a/b/c/
// .. http://a/b/
// ../ http://a/b/
// ../g http://a/b/g
// ../.. http://a/
// ../../ http://a/
// ../../g http://a/g
header("RFC2396: Abnormal relative-URL examples (appendix C)");
// ../../../g = http://a/../g
// ../../../../g = http://a/../../g
// /./g = http://a/./g
// /../g = http://a/../g
// g. = http://a/b/c/g.
// .g = http://a/b/c/.g
// g.. = http://a/b/c/g..
// ..g = http://a/b/c/..g
// ./../g = http://a/b/g
// ./g/. = http://a/b/c/g/
// g/./h = http://a/b/c/g/h
// g/../h = http://a/b/c/h
// g;x=1/./y = http://a/b/c/g;x=1/y
// g;x=1/../y = http://a/b/c/y
// g?y/./x = http://a/b/c/g?y/./x
// g?y/../x = http://a/b/c/g?y/../x
// g#s/./x = http://a/b/c/g#s/./x
// g#s/../x = http://a/b/c/g#s/../x
// http:g = http:g
// test(base,"http:g").s("http").p("g").z();
}
static void ip() {
header("IP addresses");
.s("http").h("1.2.3.4").n(5).p("").z();
// From RFC2732
test("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html")
.s("http").h("[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]")
.n(80).p("/index.html").z();
test("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210%12]:80/index.html")
.s("http").h("[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210%12]")
.n(80).p("/index.html").z();
test("http://[1080:0:0:0:8:800:200C:417A]/index.html")
test("http://[1080:0:0:0:8:800:200C:417A%1]/index.html")
test("http://[3ffe:2a00:100:7031::1]")
.s("http").h("[3ffe:2a00:100:7031::1]").p("").z();
test("http://[1080::8:800:200C:417A]/foo")
.s("http").h("[1080::8:800:200C:417A]").p("/foo").z();
test("http://[::192.9.5.5]/ipng")
.s("http").h("[::192.9.5.5]").p("/ipng").z();
test("http://[::192.9.5.5%interface]/ipng")
.s("http").h("[::192.9.5.5%interface]").p("/ipng").z();
test("http://[::FFFF:129.144.52.38]:80/index.html")
test("http://[2010:836B:4179::836B:4179]")
.s("http").h("[2010:836B:4179::836B:4179]").p("").z();
// From RFC2373
test("http://[FF01::101]")
.s("http").h("[FF01::101]").p("").z();
test("http://[::1]")
.s("http").h("[::1]").p("").z();
test("http://[::]")
.s("http").h("[::]").p("").z();
test("http://[::%hme0]")
.s("http").h("[::%hme0]").p("").z();
test("http://[0:0:0:0:0:0:13.1.68.3]")
.s("http").h("[0:0:0:0:0:0:13.1.68.3]").p("").z();
test("http://[0:0:0:0:0:FFFF:129.144.52.38]")
.s("http").h("[0:0:0:0:0:FFFF:129.144.52.38]").p("").z();
test("http://[0:0:0:0:0:FFFF:129.144.52.38%33]")
.s("http").h("[0:0:0:0:0:FFFF:129.144.52.38%33]").p("").z();
test("http://[::13.1.68.3]")
.s("http").h("[::13.1.68.3]").p("").z();
test("http://[::13.1.68.3]:")
.s("http").h("[::13.1.68.3]").p("").z();
// Error cases
test("http://[ff01:234/foo").x().z();
test("http://[ff01:234:zzz]/foo").x().z();
test("http://[foo]").x().z();
test("http://[]").x().z();
test("http://[129.33.44.55]").x().z();
test("http://[ff:ee:dd::cc:bb::aa:9:8]").x().z();
test("http://[1:2:3:4:5:6:7:8%]").x().z();
test("http://[1:2:3:4:5:6:7:8%!/]").x().z();
test("http://[1:2:3:4:5:6:7:8:9]").x().z();
test("http://[::1.2.3.300]").x().z();
test("http://[1.2.3.4:5]").x().z();
// Optional IPv6 brackets in constructors
.s("http").h("[1:2:3:4:5:6:7:8]").p("").z();
.s("http").h("[1:2:3:4:5:6:7:8%hme0]").p("").z();
.s("http").h("[1:2:3:4:5:6:7:8]").p("").z();
}
header("Serialization");
oo.writeObject(u);
try {
u.equals(o);
} catch (ClassNotFoundException x) {
x.printStackTrace();
throw new RuntimeException(x.toString());
}
}
rfc2396();
ip();
serial();
}
// -- Command-line invocation --
static void usage() {
}
case 0:
tests();
break;
case 1:
usage();
break;
}
// clargs(null, args[0]);
break;
case 2:
// clargs(args[0], args[1]);
break;
default:
usage();
break;
}
}
}