You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/10/31 09:42:35 UTC
svn commit: r590591 [9/12] - in /harmony/enhanced/classlib/branches/java6:
depends/build/platform/ depends/files/ depends/jars/icu4j_3.8/
depends/libs/freebsd.x86/ depends/manifests/icu4j_3.4.4/
depends/manifests/icu4j_3.8/ depends/manifests/icu4j_3.8/...
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/URLTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/URLTest.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/URLTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/URLTest.java Wed Oct 31 01:42:07 2007
@@ -72,176 +72,163 @@
/**
* @tests java.net.URL#URL(java.lang.String)
*/
- public void test_ConstructorLjava_lang_String() {
+ public void test_ConstructorLjava_lang_String() throws Exception {
// Test for method java.net.URL(java.lang.String)
// Tests for multiple URL instantiation
- try {
- // basic parsing test
- u = new URL(
- "http://www.yahoo1.com:8080/dir1/dir2/test.cgi?point1.html#anchor1");
- assertEquals("u returns a wrong protocol",
- "http", u.getProtocol());
- assertEquals("u returns a wrong host",
- "www.yahoo1.com", u.getHost());
- assertEquals("u returns a wrong port", 8080, u.getPort());
- assertEquals("u returns a wrong file",
- "/dir1/dir2/test.cgi?point1.html", u.getFile());
- assertEquals("u returns a wrong anchor", "anchor1", u.getRef());
-
- // test for no file
- u1 = new URL("http://www.yahoo2.com:9999");
- assertEquals("u1 returns a wrong protocol",
- "http", u1.getProtocol());
- assertEquals("u1 returns a wrong host",
- "www.yahoo2.com", u1.getHost());
- assertEquals("u1 returns a wrong port", 9999, u1.getPort());
- assertTrue("u1 returns a wrong file", u1.getFile().equals(""));
- assertNull("u1 returns a wrong anchor", u1.getRef());
-
- // test for no port
- u2 = new URL(
- "http://www.yahoo3.com/dir1/dir2/test.cgi?point1.html#anchor1");
- assertEquals("u2 returns a wrong protocol",
- "http", u2.getProtocol());
- assertEquals("u2 returns a wrong host",
- "www.yahoo3.com", u2.getHost());
- assertEquals("u2 returns a wrong port", -1, u2.getPort());
- assertEquals("u2 returns a wrong file",
- "/dir1/dir2/test.cgi?point1.html", u2.getFile());
- assertEquals("u2 returns a wrong anchor",
- "anchor1", u2.getRef());
-
- // test for no port
- URL u2a = new URL(
- "file://www.yahoo3.com/dir1/dir2/test.cgi#anchor1");
- assertEquals("u2a returns a wrong protocol", "file", u2a.getProtocol()
- );
- assertEquals("u2a returns a wrong host",
- "www.yahoo3.com", u2a.getHost());
- assertEquals("u2a returns a wrong port", -1, u2a.getPort());
- assertEquals("u2a returns a wrong file",
- "/dir1/dir2/test.cgi", u2a.getFile());
- assertEquals("u2a returns a wrong anchor",
- "anchor1", u2a.getRef());
-
- // test for no file, no port
- u3 = new URL("http://www.yahoo4.com/");
- assertEquals("u3 returns a wrong protocol",
- "http", u3.getProtocol());
- assertEquals("u3 returns a wrong host",
- "www.yahoo4.com", u3.getHost());
- assertEquals("u3 returns a wrong port", -1, u3.getPort());
- assertEquals("u3 returns a wrong file", "/", u3.getFile());
- assertNull("u3 returns a wrong anchor", u3.getRef());
-
- // test for no file, no port
- URL u3a = new URL("file://www.yahoo4.com/");
- assertEquals("u3a returns a wrong protocol", "file", u3a.getProtocol()
- );
- assertEquals("u3a returns a wrong host",
- "www.yahoo4.com", u3a.getHost());
- assertEquals("u3a returns a wrong port", -1, u3a.getPort());
- assertEquals("u3a returns a wrong file", "/", u3a.getFile());
- assertNull("u3a returns a wrong anchor", u3a.getRef());
-
- // test for no file, no port
- URL u3b = new URL("file://www.yahoo4.com");
- assertEquals("u3b returns a wrong protocol", "file", u3b.getProtocol()
- );
- assertEquals("u3b returns a wrong host",
- "www.yahoo4.com", u3b.getHost());
- assertEquals("u3b returns a wrong port", -1, u3b.getPort());
- assertTrue("u3b returns a wrong file", u3b.getFile().equals(""));
- assertNull("u3b returns a wrong anchor", u3b.getRef());
-
- // test for non-port ":" and wierd characters occurrences
- u4 = new URL(
- "http://www.yahoo5.com/di!@$%^&*()_+r1/di:::r2/test.cgi?point1.html#anchor1");
- assertEquals("u4 returns a wrong protocol",
- "http", u4.getProtocol());
- assertEquals("u4 returns a wrong host",
- "www.yahoo5.com", u4.getHost());
- assertEquals("u4 returns a wrong port", -1, u4.getPort());
- assertEquals("u4 returns a wrong file",
- "/di!@$%^&*()_+r1/di:::r2/test.cgi?point1.html", u4.getFile());
- assertEquals("u4 returns a wrong anchor",
- "anchor1", u4.getRef());
-
- u5 = new URL("file:/testing.tst");
- assertEquals("u5 returns a wrong protocol",
- "file", u5.getProtocol());
- assertTrue("u5 returns a wrong host", u5.getHost().equals(""));
- assertEquals("u5 returns a wrong port", -1, u5.getPort());
- assertEquals("u5 returns a wrong file",
- "/testing.tst", u5.getFile());
- assertNull("u5 returns a wrong anchor", u5.getRef());
-
- URL u5a = new URL("file:testing.tst");
- assertEquals("u5a returns a wrong protocol", "file", u5a.getProtocol()
- );
- assertTrue("u5a returns a wrong host", u5a.getHost().equals(""));
- assertEquals("u5a returns a wrong port", -1, u5a.getPort());
- assertEquals("u5a returns a wrong file",
- "testing.tst", u5a.getFile());
- assertNull("u5a returns a wrong anchor", u5a.getRef());
-
- URL u6 = new URL("http://host:/file");
- assertEquals("u6 return a wrong port", -1, u6.getPort());
-
- URL u7 = new URL("file:../../file.txt");
- assertTrue("u7 returns a wrong file: " + u7.getFile(), u7.getFile()
- .equals("../../file.txt"));
-
- URL u8 = new URL("http://[fec0::1:20d:60ff:fe24:7410]:35/file.txt");
- assertTrue("u8 returns a wrong protocol " + u8.getProtocol(), u8
- .getProtocol().equals("http"));
- assertTrue("u8 returns a wrong host " + u8.getHost(), u8.getHost()
- .equals("[fec0::1:20d:60ff:fe24:7410]"));
- assertTrue("u8 returns a wrong port " + u8.getPort(),
- u8.getPort() == 35);
- assertTrue("u8 returns a wrong file " + u8.getFile(), u8.getFile()
- .equals("/file.txt"));
- assertNull("u8 returns a wrong anchor " + u8.getRef(),
- u8.getRef());
-
- URL u9 = new URL(
- "file://[fec0::1:20d:60ff:fe24:7410]/file.txt#sogood");
- assertTrue("u9 returns a wrong protocol " + u9.getProtocol(), u9
- .getProtocol().equals("file"));
- assertTrue("u9 returns a wrong host " + u9.getHost(), u9.getHost()
- .equals("[fec0::1:20d:60ff:fe24:7410]"));
- assertTrue("u9 returns a wrong port " + u9.getPort(),
- u9.getPort() == -1);
- assertTrue("u9 returns a wrong file " + u9.getFile(), u9.getFile()
- .equals("/file.txt"));
- assertTrue("u9 returns a wrong anchor " + u9.getRef(), u9.getRef()
- .equals("sogood"));
-
- URL u10 = new URL("file://[fec0::1:20d:60ff:fe24:7410]");
- assertTrue("u10 returns a wrong protocol " + u10.getProtocol(), u10
- .getProtocol().equals("file"));
- assertTrue("u10 returns a wrong host " + u10.getHost(), u10
- .getHost().equals("[fec0::1:20d:60ff:fe24:7410]"));
- assertTrue("u10 returns a wrong port " + u10.getPort(), u10
- .getPort() == -1);
-
- } catch (Exception e) {
- fail("Exception during tests : " + e.getMessage());
- }
+ // basic parsing test
+ u = new URL(
+ "http://www.yahoo1.com:8080/dir1/dir2/test.cgi?point1.html#anchor1");
+ assertEquals("u returns a wrong protocol",
+ "http", u.getProtocol());
+ assertEquals("u returns a wrong host",
+ "www.yahoo1.com", u.getHost());
+ assertEquals("u returns a wrong port", 8080, u.getPort());
+ assertEquals("u returns a wrong file",
+ "/dir1/dir2/test.cgi?point1.html", u.getFile());
+ assertEquals("u returns a wrong anchor", "anchor1", u.getRef());
+
+ // test for no file
+ u1 = new URL("http://www.yahoo2.com:9999");
+ assertEquals("u1 returns a wrong protocol",
+ "http", u1.getProtocol());
+ assertEquals("u1 returns a wrong host",
+ "www.yahoo2.com", u1.getHost());
+ assertEquals("u1 returns a wrong port", 9999, u1.getPort());
+ assertTrue("u1 returns a wrong file", u1.getFile().equals(""));
+ assertNull("u1 returns a wrong anchor", u1.getRef());
+
+ // test for no port
+ u2 = new URL(
+ "http://www.yahoo3.com/dir1/dir2/test.cgi?point1.html#anchor1");
+ assertEquals("u2 returns a wrong protocol",
+ "http", u2.getProtocol());
+ assertEquals("u2 returns a wrong host",
+ "www.yahoo3.com", u2.getHost());
+ assertEquals("u2 returns a wrong port", -1, u2.getPort());
+ assertEquals("u2 returns a wrong file",
+ "/dir1/dir2/test.cgi?point1.html", u2.getFile());
+ assertEquals("u2 returns a wrong anchor",
+ "anchor1", u2.getRef());
+
+ // test for no port
+ URL u2a = new URL(
+ "file://www.yahoo3.com/dir1/dir2/test.cgi#anchor1");
+ assertEquals("u2a returns a wrong protocol", "file", u2a.getProtocol()
+ );
+ assertEquals("u2a returns a wrong host",
+ "www.yahoo3.com", u2a.getHost());
+ assertEquals("u2a returns a wrong port", -1, u2a.getPort());
+ assertEquals("u2a returns a wrong file",
+ "/dir1/dir2/test.cgi", u2a.getFile());
+ assertEquals("u2a returns a wrong anchor",
+ "anchor1", u2a.getRef());
+
+ // test for no file, no port
+ u3 = new URL("http://www.yahoo4.com/");
+ assertEquals("u3 returns a wrong protocol",
+ "http", u3.getProtocol());
+ assertEquals("u3 returns a wrong host",
+ "www.yahoo4.com", u3.getHost());
+ assertEquals("u3 returns a wrong port", -1, u3.getPort());
+ assertEquals("u3 returns a wrong file", "/", u3.getFile());
+ assertNull("u3 returns a wrong anchor", u3.getRef());
+
+ // test for no file, no port
+ URL u3a = new URL("file://www.yahoo4.com/");
+ assertEquals("u3a returns a wrong protocol", "file", u3a.getProtocol()
+ );
+ assertEquals("u3a returns a wrong host",
+ "www.yahoo4.com", u3a.getHost());
+ assertEquals("u3a returns a wrong port", -1, u3a.getPort());
+ assertEquals("u3a returns a wrong file", "/", u3a.getFile());
+ assertNull("u3a returns a wrong anchor", u3a.getRef());
+
+ // test for no file, no port
+ URL u3b = new URL("file://www.yahoo4.com");
+ assertEquals("u3b returns a wrong protocol", "file", u3b.getProtocol()
+ );
+ assertEquals("u3b returns a wrong host",
+ "www.yahoo4.com", u3b.getHost());
+ assertEquals("u3b returns a wrong port", -1, u3b.getPort());
+ assertTrue("u3b returns a wrong file", u3b.getFile().equals(""));
+ assertNull("u3b returns a wrong anchor", u3b.getRef());
+
+ // test for non-port ":" and wierd characters occurrences
+ u4 = new URL(
+ "http://www.yahoo5.com/di!@$%^&*()_+r1/di:::r2/test.cgi?point1.html#anchor1");
+ assertEquals("u4 returns a wrong protocol",
+ "http", u4.getProtocol());
+ assertEquals("u4 returns a wrong host",
+ "www.yahoo5.com", u4.getHost());
+ assertEquals("u4 returns a wrong port", -1, u4.getPort());
+ assertEquals("u4 returns a wrong file",
+ "/di!@$%^&*()_+r1/di:::r2/test.cgi?point1.html", u4.getFile());
+ assertEquals("u4 returns a wrong anchor",
+ "anchor1", u4.getRef());
+
+ u5 = new URL("file:/testing.tst");
+ assertEquals("u5 returns a wrong protocol",
+ "file", u5.getProtocol());
+ assertTrue("u5 returns a wrong host", u5.getHost().equals(""));
+ assertEquals("u5 returns a wrong port", -1, u5.getPort());
+ assertEquals("u5 returns a wrong file",
+ "/testing.tst", u5.getFile());
+ assertNull("u5 returns a wrong anchor", u5.getRef());
+
+ URL u5a = new URL("file:testing.tst");
+ assertEquals("u5a returns a wrong protocol", "file", u5a.getProtocol()
+ );
+ assertTrue("u5a returns a wrong host", u5a.getHost().equals(""));
+ assertEquals("u5a returns a wrong port", -1, u5a.getPort());
+ assertEquals("u5a returns a wrong file",
+ "testing.tst", u5a.getFile());
+ assertNull("u5a returns a wrong anchor", u5a.getRef());
+
+ URL u6 = new URL("http://host:/file");
+ assertEquals("u6 return a wrong port", -1, u6.getPort());
+
+ URL u7 = new URL("file:../../file.txt");
+ assertTrue("u7 returns a wrong file: " + u7.getFile(), u7.getFile()
+ .equals("../../file.txt"));
+
+ URL u8 = new URL("http://[fec0::1:20d:60ff:fe24:7410]:35/file.txt");
+ assertTrue("u8 returns a wrong protocol " + u8.getProtocol(), u8
+ .getProtocol().equals("http"));
+ assertTrue("u8 returns a wrong host " + u8.getHost(), u8.getHost()
+ .equals("[fec0::1:20d:60ff:fe24:7410]"));
+ assertTrue("u8 returns a wrong port " + u8.getPort(),
+ u8.getPort() == 35);
+ assertTrue("u8 returns a wrong file " + u8.getFile(), u8.getFile()
+ .equals("/file.txt"));
+ assertNull("u8 returns a wrong anchor " + u8.getRef(),
+ u8.getRef());
+
+ URL u9 = new URL(
+ "file://[fec0::1:20d:60ff:fe24:7410]/file.txt#sogood");
+ assertTrue("u9 returns a wrong protocol " + u9.getProtocol(), u9
+ .getProtocol().equals("file"));
+ assertTrue("u9 returns a wrong host " + u9.getHost(), u9.getHost()
+ .equals("[fec0::1:20d:60ff:fe24:7410]"));
+ assertTrue("u9 returns a wrong port " + u9.getPort(),
+ u9.getPort() == -1);
+ assertTrue("u9 returns a wrong file " + u9.getFile(), u9.getFile()
+ .equals("/file.txt"));
+ assertTrue("u9 returns a wrong anchor " + u9.getRef(), u9.getRef()
+ .equals("sogood"));
+
+ URL u10 = new URL("file://[fec0::1:20d:60ff:fe24:7410]");
+ assertTrue("u10 returns a wrong protocol " + u10.getProtocol(), u10
+ .getProtocol().equals("file"));
+ assertTrue("u10 returns a wrong host " + u10.getHost(), u10
+ .getHost().equals("[fec0::1:20d:60ff:fe24:7410]"));
+ assertTrue("u10 returns a wrong port " + u10.getPort(), u10
+ .getPort() == -1);
// test for error catching
// Bad HTTP format - no "//"
-
- try {
- u = new URL(
- "http:www.yahoo5.com::22/dir1/di:::r2/test.cgi?point1.html#anchor1");
- } catch (MalformedURLException e) {
- fail("1 Should not have thrown MalformedURLException : "
- + e.getMessage());
- } catch (Exception e) {
- fail("1 Threw exception : " + e.getMessage());
- }
+ u = new URL(
+ "http:www.yahoo5.com::22/dir1/di:::r2/test.cgi?point1.html#anchor1");
caught = false;
try {
@@ -249,8 +236,6 @@
"http://www.yahoo5.com::22/dir1/di:::r2/test.cgi?point1.html#anchor1");
} catch (MalformedURLException e) {
caught = true;
- } catch (Exception e) {
- fail("2 Threw exception : " + e.getMessage());
}
assertTrue("Should have throw MalformedURLException", caught);
@@ -259,8 +244,6 @@
u = new URL("myProtocol://www.yahoo.com:22");
} catch (MalformedURLException e) {
caught = true;
- } catch (Exception e) {
- fail("3 Threw the wrong kind of exception : " + e);
}
assertTrue("3 Failed to throw MalformedURLException", caught);
@@ -270,8 +253,6 @@
u = new URL("www.yahoo.com");
} catch (MalformedURLException e) {
caught = true;
- } catch (Exception e) {
- fail("4 Threw the wrong kind of exception : " + e);
}
assertTrue("4 Failed to throw MalformedURLException", caught);
@@ -319,252 +300,246 @@
/**
* @tests java.net.URL#URL(java.net.URL, java.lang.String)
*/
- public void test_ConstructorLjava_net_URLLjava_lang_String() {
+ public void test_ConstructorLjava_net_URLLjava_lang_String() throws Exception {
// Test for method java.net.URL(java.net.URL, java.lang.String)
- try {
- u = new URL("http://www.yahoo.com");
- URL uf = new URL("file://www.yahoo.com");
- // basic ones
- u1 = new URL(u, "file.java");
- assertEquals("1 returns a wrong protocol",
- "http", u1.getProtocol());
- assertEquals("1 returns a wrong host",
- "www.yahoo.com", u1.getHost());
- assertEquals("1 returns a wrong port", -1, u1.getPort());
- assertEquals("1 returns a wrong file",
- "/file.java", u1.getFile());
- assertNull("1 returns a wrong anchor", u1.getRef());
-
- URL u1f = new URL(uf, "file.java");
- assertEquals("1f returns a wrong protocol",
- "file", u1f.getProtocol());
- assertEquals("1f returns a wrong host",
- "www.yahoo.com", u1f.getHost());
- assertEquals("1f returns a wrong port", -1, u1f.getPort());
- assertEquals("1f returns a wrong file",
- "/file.java", u1f.getFile());
- assertNull("1f returns a wrong anchor", u1f.getRef());
-
- u1 = new URL(u, "dir1/dir2/../file.java");
- assertEquals("3 returns a wrong protocol",
- "http", u1.getProtocol());
- assertTrue("3 returns a wrong host: " + u1.getHost(), u1.getHost()
- .equals("www.yahoo.com"));
- assertEquals("3 returns a wrong port", -1, u1.getPort());
- assertEquals("3 returns a wrong file",
- "/dir1/dir2/../file.java", u1.getFile());
- assertNull("3 returns a wrong anchor", u1.getRef());
-
- u1 = new URL(u, "http:dir1/dir2/../file.java");
- assertEquals("3a returns a wrong protocol",
- "http", u1.getProtocol());
- assertTrue("3a returns a wrong host: " + u1.getHost(), u1.getHost()
- .equals(""));
- assertEquals("3a returns a wrong port", -1, u1.getPort());
- assertEquals("3a returns a wrong file",
- "dir1/dir2/../file.java", u1.getFile());
- assertNull("3a returns a wrong anchor", u1.getRef());
-
- u = new URL("http://www.apache.org/testing/");
- u1 = new URL(u, "file.java");
- assertEquals("4 returns a wrong protocol",
- "http", u1.getProtocol());
- assertEquals("4 returns a wrong host",
- "www.apache.org", u1.getHost());
- assertEquals("4 returns a wrong port", -1, u1.getPort());
- assertEquals("4 returns a wrong file",
- "/testing/file.java", u1.getFile());
- assertNull("4 returns a wrong anchor", u1.getRef());
-
- uf = new URL("file://www.apache.org/testing/");
- u1f = new URL(uf, "file.java");
- assertEquals("4f returns a wrong protocol",
- "file", u1f.getProtocol());
- assertEquals("4f returns a wrong host",
- "www.apache.org", u1f.getHost());
- assertEquals("4f returns a wrong port", -1, u1f.getPort());
- assertEquals("4f returns a wrong file",
- "/testing/file.java", u1f.getFile());
- assertNull("4f returns a wrong anchor", u1f.getRef());
-
- uf = new URL("file:/testing/");
- u1f = new URL(uf, "file.java");
- assertEquals("4fa returns a wrong protocol", "file", u1f.getProtocol()
- );
- assertTrue("4fa returns a wrong host", u1f.getHost().equals(""));
- assertEquals("4fa returns a wrong port", -1, u1f.getPort());
- assertEquals("4fa returns a wrong file",
- "/testing/file.java", u1f.getFile());
- assertNull("4fa returns a wrong anchor", u1f.getRef());
-
- uf = new URL("file:testing/");
- u1f = new URL(uf, "file.java");
- assertEquals("4fb returns a wrong protocol", "file", u1f.getProtocol()
- );
- assertTrue("4fb returns a wrong host", u1f.getHost().equals(""));
- assertEquals("4fb returns a wrong port", -1, u1f.getPort());
- assertEquals("4fb returns a wrong file",
- "testing/file.java", u1f.getFile());
- assertNull("4fb returns a wrong anchor", u1f.getRef());
-
- u1f = new URL(uf, "file:file.java");
- assertEquals("4fc returns a wrong protocol", "file", u1f.getProtocol()
- );
- assertTrue("4fc returns a wrong host", u1f.getHost().equals(""));
- assertEquals("4fc returns a wrong port", -1, u1f.getPort());
- assertEquals("4fc returns a wrong file",
- "file.java", u1f.getFile());
- assertNull("4fc returns a wrong anchor", u1f.getRef());
-
- u1f = new URL(uf, "file:");
- assertEquals("4fd returns a wrong protocol", "file", u1f.getProtocol()
- );
- assertTrue("4fd returns a wrong host", u1f.getHost().equals(""));
- assertEquals("4fd returns a wrong port", -1, u1f.getPort());
- assertTrue("4fd returns a wrong file", u1f.getFile().equals(""));
- assertNull("4fd returns a wrong anchor", u1f.getRef());
-
- u = new URL("http://www.apache.org/testing");
- u1 = new URL(u, "file.java");
- assertEquals("5 returns a wrong protocol",
- "http", u1.getProtocol());
- assertEquals("5 returns a wrong host",
- "www.apache.org", u1.getHost());
- assertEquals("5 returns a wrong port", -1, u1.getPort());
- assertEquals("5 returns a wrong file",
- "/file.java", u1.getFile());
- assertNull("5 returns a wrong anchor", u1.getRef());
-
- uf = new URL("file://www.apache.org/testing");
- u1f = new URL(uf, "file.java");
- assertEquals("5f returns a wrong protocol",
- "file", u1f.getProtocol());
- assertEquals("5f returns a wrong host",
- "www.apache.org", u1f.getHost());
- assertEquals("5f returns a wrong port", -1, u1f.getPort());
- assertEquals("5f returns a wrong file",
- "/file.java", u1f.getFile());
- assertNull("5f returns a wrong anchor", u1f.getRef());
-
- uf = new URL("file:/testing");
- u1f = new URL(uf, "file.java");
- assertEquals("5fa returns a wrong protocol", "file", u1f.getProtocol()
- );
- assertTrue("5fa returns a wrong host", u1f.getHost().equals(""));
- assertEquals("5fa returns a wrong port", -1, u1f.getPort());
- assertEquals("5fa returns a wrong file",
- "/file.java", u1f.getFile());
- assertNull("5fa returns a wrong anchor", u1f.getRef());
-
- uf = new URL("file:testing");
- u1f = new URL(uf, "file.java");
- assertEquals("5fb returns a wrong protocol", "file", u1f.getProtocol()
- );
- assertTrue("5fb returns a wrong host", u1f.getHost().equals(""));
- assertEquals("5fb returns a wrong port", -1, u1f.getPort());
- assertEquals("5fb returns a wrong file",
- "file.java", u1f.getFile());
- assertNull("5fb returns a wrong anchor", u1f.getRef());
-
- u = new URL("http://www.apache.org/testing/foobaz");
- u1 = new URL(u, "/file.java");
- assertEquals("6 returns a wrong protocol",
- "http", u1.getProtocol());
- assertEquals("6 returns a wrong host",
- "www.apache.org", u1.getHost());
- assertEquals("6 returns a wrong port", -1, u1.getPort());
- assertEquals("6 returns a wrong file",
- "/file.java", u1.getFile());
- assertNull("6 returns a wrong anchor", u1.getRef());
-
- uf = new URL("file://www.apache.org/testing/foobaz");
- u1f = new URL(uf, "/file.java");
- assertEquals("6f returns a wrong protocol",
- "file", u1f.getProtocol());
- assertEquals("6f returns a wrong host",
- "www.apache.org", u1f.getHost());
- assertEquals("6f returns a wrong port", -1, u1f.getPort());
- assertEquals("6f returns a wrong file",
- "/file.java", u1f.getFile());
- assertNull("6f returns a wrong anchor", u1f.getRef());
-
- u = new URL("http://www.apache.org:8000/testing/foobaz");
- u1 = new URL(u, "/file.java");
- assertEquals("7 returns a wrong protocol",
- "http", u1.getProtocol());
- assertEquals("7 returns a wrong host",
- "www.apache.org", u1.getHost());
- assertEquals("7 returns a wrong port", 8000, u1.getPort());
- assertEquals("7 returns a wrong file",
- "/file.java", u1.getFile());
- assertNull("7 returns a wrong anchor", u1.getRef());
-
- u = new URL("http://www.apache.org/index.html");
- u1 = new URL(u, "#bar");
- assertEquals("8 returns a wrong host",
- "www.apache.org", u1.getHost());
- assertEquals("8 returns a wrong file",
- "/index.html", u1.getFile());
- assertEquals("8 returns a wrong anchor", "bar", u1.getRef());
-
- u = new URL("http://www.apache.org/index.html#foo");
- u1 = new URL(u, "http:#bar");
- assertEquals("9 returns a wrong host",
- "www.apache.org", u1.getHost());
- assertEquals("9 returns a wrong file",
- "/index.html", u1.getFile());
- assertEquals("9 returns a wrong anchor", "bar", u1.getRef());
-
- u = new URL("http://www.apache.org/index.html");
- u1 = new URL(u, "");
- assertEquals("10 returns a wrong host",
- "www.apache.org", u1.getHost());
- assertEquals("10 returns a wrong file",
- "/index.html", u1.getFile());
- assertNull("10 returns a wrong anchor", u1.getRef());
-
- uf = new URL("file://www.apache.org/index.html");
- u1f = new URL(uf, "");
- assertEquals("10f returns a wrong host",
- "www.apache.org", u1.getHost());
- assertEquals("10f returns a wrong file",
- "/index.html", u1.getFile());
- assertNull("10f returns a wrong anchor", u1.getRef());
-
- u = new URL("http://www.apache.org/index.html");
- u1 = new URL(u, "http://www.apache.org");
- assertEquals("11 returns a wrong host",
- "www.apache.org", u1.getHost());
- assertTrue("11 returns a wrong file", u1.getFile().equals(""));
- assertNull("11 returns a wrong anchor", u1.getRef());
-
- // test for question mark processing
- u = new URL("http://www.foo.com/d0/d1/d2/cgi-bin?foo=bar/baz");
-
- // test for relative file and out of bound "/../" processing
- u1 = new URL(u, "../dir1/./dir2/../file.java");
- assertTrue("A) returns a wrong file: " + u1.getFile(), u1.getFile()
- .equals("/d0/d1/dir1/file.java"));
-
- // test for absolute and relative file processing
- u1 = new URL(u, "/../dir1/./dir2/../file.java");
- assertEquals("B) returns a wrong file",
- "/../dir1/./dir2/../file.java", u1.getFile());
- } catch (Exception e) {
- fail("1 Exception during tests : " + e.getMessage());
- }
-
- try {
- // u should raise a MalFormedURLException because u, the context is
- // null
- u = null;
- u1 = new URL(u, "file.java");
- fail("didn't throw the expected MalFormedURLException");
- } catch (MalformedURLException e) {
+ u = new URL("http://www.yahoo.com");
+ URL uf = new URL("file://www.yahoo.com");
+ // basic ones
+ u1 = new URL(u, "file.java");
+ assertEquals("1 returns a wrong protocol",
+ "http", u1.getProtocol());
+ assertEquals("1 returns a wrong host",
+ "www.yahoo.com", u1.getHost());
+ assertEquals("1 returns a wrong port", -1, u1.getPort());
+ assertEquals("1 returns a wrong file",
+ "/file.java", u1.getFile());
+ assertNull("1 returns a wrong anchor", u1.getRef());
+
+ URL u1f = new URL(uf, "file.java");
+ assertEquals("1f returns a wrong protocol",
+ "file", u1f.getProtocol());
+ assertEquals("1f returns a wrong host",
+ "www.yahoo.com", u1f.getHost());
+ assertEquals("1f returns a wrong port", -1, u1f.getPort());
+ assertEquals("1f returns a wrong file",
+ "/file.java", u1f.getFile());
+ assertNull("1f returns a wrong anchor", u1f.getRef());
+
+ u1 = new URL(u, "dir1/dir2/../file.java");
+ assertEquals("3 returns a wrong protocol",
+ "http", u1.getProtocol());
+ assertTrue("3 returns a wrong host: " + u1.getHost(), u1.getHost()
+ .equals("www.yahoo.com"));
+ assertEquals("3 returns a wrong port", -1, u1.getPort());
+ assertEquals("3 returns a wrong file",
+ "/dir1/dir2/../file.java", u1.getFile());
+ assertNull("3 returns a wrong anchor", u1.getRef());
+
+ u1 = new URL(u, "http:dir1/dir2/../file.java");
+ assertEquals("3a returns a wrong protocol",
+ "http", u1.getProtocol());
+ assertTrue("3a returns a wrong host: " + u1.getHost(), u1.getHost()
+ .equals(""));
+ assertEquals("3a returns a wrong port", -1, u1.getPort());
+ assertEquals("3a returns a wrong file",
+ "dir1/dir2/../file.java", u1.getFile());
+ assertNull("3a returns a wrong anchor", u1.getRef());
+
+ u = new URL("http://www.apache.org/testing/");
+ u1 = new URL(u, "file.java");
+ assertEquals("4 returns a wrong protocol",
+ "http", u1.getProtocol());
+ assertEquals("4 returns a wrong host",
+ "www.apache.org", u1.getHost());
+ assertEquals("4 returns a wrong port", -1, u1.getPort());
+ assertEquals("4 returns a wrong file",
+ "/testing/file.java", u1.getFile());
+ assertNull("4 returns a wrong anchor", u1.getRef());
+
+ uf = new URL("file://www.apache.org/testing/");
+ u1f = new URL(uf, "file.java");
+ assertEquals("4f returns a wrong protocol",
+ "file", u1f.getProtocol());
+ assertEquals("4f returns a wrong host",
+ "www.apache.org", u1f.getHost());
+ assertEquals("4f returns a wrong port", -1, u1f.getPort());
+ assertEquals("4f returns a wrong file",
+ "/testing/file.java", u1f.getFile());
+ assertNull("4f returns a wrong anchor", u1f.getRef());
+
+ uf = new URL("file:/testing/");
+ u1f = new URL(uf, "file.java");
+ assertEquals("4fa returns a wrong protocol", "file", u1f.getProtocol()
+ );
+ assertTrue("4fa returns a wrong host", u1f.getHost().equals(""));
+ assertEquals("4fa returns a wrong port", -1, u1f.getPort());
+ assertEquals("4fa returns a wrong file",
+ "/testing/file.java", u1f.getFile());
+ assertNull("4fa returns a wrong anchor", u1f.getRef());
+
+ uf = new URL("file:testing/");
+ u1f = new URL(uf, "file.java");
+ assertEquals("4fb returns a wrong protocol", "file", u1f.getProtocol()
+ );
+ assertTrue("4fb returns a wrong host", u1f.getHost().equals(""));
+ assertEquals("4fb returns a wrong port", -1, u1f.getPort());
+ assertEquals("4fb returns a wrong file",
+ "testing/file.java", u1f.getFile());
+ assertNull("4fb returns a wrong anchor", u1f.getRef());
+
+ u1f = new URL(uf, "file:file.java");
+ assertEquals("4fc returns a wrong protocol", "file", u1f.getProtocol()
+ );
+ assertTrue("4fc returns a wrong host", u1f.getHost().equals(""));
+ assertEquals("4fc returns a wrong port", -1, u1f.getPort());
+ assertEquals("4fc returns a wrong file",
+ "file.java", u1f.getFile());
+ assertNull("4fc returns a wrong anchor", u1f.getRef());
+
+ u1f = new URL(uf, "file:");
+ assertEquals("4fd returns a wrong protocol", "file", u1f.getProtocol()
+ );
+ assertTrue("4fd returns a wrong host", u1f.getHost().equals(""));
+ assertEquals("4fd returns a wrong port", -1, u1f.getPort());
+ assertTrue("4fd returns a wrong file", u1f.getFile().equals(""));
+ assertNull("4fd returns a wrong anchor", u1f.getRef());
+
+ u = new URL("http://www.apache.org/testing");
+ u1 = new URL(u, "file.java");
+ assertEquals("5 returns a wrong protocol",
+ "http", u1.getProtocol());
+ assertEquals("5 returns a wrong host",
+ "www.apache.org", u1.getHost());
+ assertEquals("5 returns a wrong port", -1, u1.getPort());
+ assertEquals("5 returns a wrong file",
+ "/file.java", u1.getFile());
+ assertNull("5 returns a wrong anchor", u1.getRef());
+
+ uf = new URL("file://www.apache.org/testing");
+ u1f = new URL(uf, "file.java");
+ assertEquals("5f returns a wrong protocol",
+ "file", u1f.getProtocol());
+ assertEquals("5f returns a wrong host",
+ "www.apache.org", u1f.getHost());
+ assertEquals("5f returns a wrong port", -1, u1f.getPort());
+ assertEquals("5f returns a wrong file",
+ "/file.java", u1f.getFile());
+ assertNull("5f returns a wrong anchor", u1f.getRef());
+
+ uf = new URL("file:/testing");
+ u1f = new URL(uf, "file.java");
+ assertEquals("5fa returns a wrong protocol", "file", u1f.getProtocol()
+ );
+ assertTrue("5fa returns a wrong host", u1f.getHost().equals(""));
+ assertEquals("5fa returns a wrong port", -1, u1f.getPort());
+ assertEquals("5fa returns a wrong file",
+ "/file.java", u1f.getFile());
+ assertNull("5fa returns a wrong anchor", u1f.getRef());
+
+ uf = new URL("file:testing");
+ u1f = new URL(uf, "file.java");
+ assertEquals("5fb returns a wrong protocol", "file", u1f.getProtocol()
+ );
+ assertTrue("5fb returns a wrong host", u1f.getHost().equals(""));
+ assertEquals("5fb returns a wrong port", -1, u1f.getPort());
+ assertEquals("5fb returns a wrong file",
+ "file.java", u1f.getFile());
+ assertNull("5fb returns a wrong anchor", u1f.getRef());
+
+ u = new URL("http://www.apache.org/testing/foobaz");
+ u1 = new URL(u, "/file.java");
+ assertEquals("6 returns a wrong protocol",
+ "http", u1.getProtocol());
+ assertEquals("6 returns a wrong host",
+ "www.apache.org", u1.getHost());
+ assertEquals("6 returns a wrong port", -1, u1.getPort());
+ assertEquals("6 returns a wrong file",
+ "/file.java", u1.getFile());
+ assertNull("6 returns a wrong anchor", u1.getRef());
+
+ uf = new URL("file://www.apache.org/testing/foobaz");
+ u1f = new URL(uf, "/file.java");
+ assertEquals("6f returns a wrong protocol",
+ "file", u1f.getProtocol());
+ assertEquals("6f returns a wrong host",
+ "www.apache.org", u1f.getHost());
+ assertEquals("6f returns a wrong port", -1, u1f.getPort());
+ assertEquals("6f returns a wrong file",
+ "/file.java", u1f.getFile());
+ assertNull("6f returns a wrong anchor", u1f.getRef());
+
+ u = new URL("http://www.apache.org:8000/testing/foobaz");
+ u1 = new URL(u, "/file.java");
+ assertEquals("7 returns a wrong protocol",
+ "http", u1.getProtocol());
+ assertEquals("7 returns a wrong host",
+ "www.apache.org", u1.getHost());
+ assertEquals("7 returns a wrong port", 8000, u1.getPort());
+ assertEquals("7 returns a wrong file",
+ "/file.java", u1.getFile());
+ assertNull("7 returns a wrong anchor", u1.getRef());
+
+ u = new URL("http://www.apache.org/index.html");
+ u1 = new URL(u, "#bar");
+ assertEquals("8 returns a wrong host",
+ "www.apache.org", u1.getHost());
+ assertEquals("8 returns a wrong file",
+ "/index.html", u1.getFile());
+ assertEquals("8 returns a wrong anchor", "bar", u1.getRef());
+
+ u = new URL("http://www.apache.org/index.html#foo");
+ u1 = new URL(u, "http:#bar");
+ assertEquals("9 returns a wrong host",
+ "www.apache.org", u1.getHost());
+ assertEquals("9 returns a wrong file",
+ "/index.html", u1.getFile());
+ assertEquals("9 returns a wrong anchor", "bar", u1.getRef());
+
+ u = new URL("http://www.apache.org/index.html");
+ u1 = new URL(u, "");
+ assertEquals("10 returns a wrong host",
+ "www.apache.org", u1.getHost());
+ assertEquals("10 returns a wrong file",
+ "/index.html", u1.getFile());
+ assertNull("10 returns a wrong anchor", u1.getRef());
+
+ uf = new URL("file://www.apache.org/index.html");
+ u1f = new URL(uf, "");
+ assertEquals("10f returns a wrong host",
+ "www.apache.org", u1.getHost());
+ assertEquals("10f returns a wrong file",
+ "/index.html", u1.getFile());
+ assertNull("10f returns a wrong anchor", u1.getRef());
+
+ u = new URL("http://www.apache.org/index.html");
+ u1 = new URL(u, "http://www.apache.org");
+ assertEquals("11 returns a wrong host",
+ "www.apache.org", u1.getHost());
+ assertTrue("11 returns a wrong file", u1.getFile().equals(""));
+ assertNull("11 returns a wrong anchor", u1.getRef());
+
+ // test for question mark processing
+ u = new URL("http://www.foo.com/d0/d1/d2/cgi-bin?foo=bar/baz");
+
+ // test for relative file and out of bound "/../" processing
+ u1 = new URL(u, "../dir1/./dir2/../file.java");
+ assertTrue("A) returns a wrong file: " + u1.getFile(), u1.getFile()
+ .equals("/d0/d1/dir1/file.java"));
+
+ // test for absolute and relative file processing
+ u1 = new URL(u, "/../dir1/./dir2/../file.java");
+ assertEquals("B) returns a wrong file",
+ "/../dir1/./dir2/../file.java", u1.getFile());
+
+ try {
+ // u should raise a MalFormedURLException because u, the context is
+ // null
+ u = null;
+ u1 = new URL(u, "file.java");
+ fail("didn't throw the expected MalFormedURLException");
+ } catch (MalformedURLException e) {
// valid
- } catch (Exception e) {
- fail("2 Exception during tests : " + e.getMessage());
- }
+ }
// Regression test for HARMONY-3258
// testing jar context url with relative file
@@ -610,57 +585,53 @@
* @tests java.net.URL#URL(java.net.URL, java.lang.String,
* java.net.URLStreamHandler)
*/
- public void test_ConstructorLjava_net_URLLjava_lang_StringLjava_net_URLStreamHandler() {
+ public void test_ConstructorLjava_net_URLLjava_lang_StringLjava_net_URLStreamHandler() throws Exception {
// Test for method java.net.URL(java.net.URL, java.lang.String,
// java.net.URLStreamHandler)
- try {
- u = new URL("http://www.yahoo.com");
- // basic ones
- u1 = new URL(u, "file.java", new MyHandler());
- assertEquals("1 returns a wrong protocol",
- "http", u1.getProtocol());
- assertEquals("1 returns a wrong host",
- "www.yahoo.com", u1.getHost());
- assertEquals("1 returns a wrong port", -1, u1.getPort());
- assertEquals("1 returns a wrong file",
- "/file.java", u1.getFile());
- assertNull("1 returns a wrong anchor", u1.getRef());
-
- u1 = new URL(u, "systemresource:/+/FILE0/test.java",
- new MyHandler());
- assertEquals("2 returns a wrong protocol",
- "systemresource", u1.getProtocol());
- assertTrue("2 returns a wrong host", u1.getHost().equals(""));
- assertEquals("2 returns a wrong port", -1, u1.getPort());
- assertEquals("2 returns a wrong file",
- "/+/FILE0/test.java", u1.getFile());
- assertNull("2 returns a wrong anchor", u1.getRef());
-
- u1 = new URL(u, "dir1/dir2/../file.java", null);
- assertEquals("3 returns a wrong protocol",
- "http", u1.getProtocol());
- assertEquals("3 returns a wrong host",
- "www.yahoo.com", u1.getHost());
- assertEquals("3 returns a wrong port", -1, u1.getPort());
- assertEquals("3 returns a wrong file",
- "/dir1/dir2/../file.java", u1.getFile());
- assertNull("3 returns a wrong anchor", u1.getRef());
-
- // test for question mark processing
- u = new URL("http://www.foo.com/d0/d1/d2/cgi-bin?foo=bar/baz");
-
- // test for relative file and out of bound "/../" processing
- u1 = new URL(u, "../dir1/dir2/../file.java", new MyHandler());
- assertTrue("A) returns a wrong file: " + u1.getFile(), u1.getFile()
- .equals("/d0/d1/dir1/file.java"));
-
- // test for absolute and relative file processing
- u1 = new URL(u, "/../dir1/dir2/../file.java", null);
- assertEquals("B) returns a wrong file",
- "/../dir1/dir2/../file.java", u1.getFile());
- } catch (Exception e) {
- fail("1 Exception during tests : " + e.getMessage());
- }
+ u = new URL("http://www.yahoo.com");
+ // basic ones
+ u1 = new URL(u, "file.java", new MyHandler());
+ assertEquals("1 returns a wrong protocol",
+ "http", u1.getProtocol());
+ assertEquals("1 returns a wrong host",
+ "www.yahoo.com", u1.getHost());
+ assertEquals("1 returns a wrong port", -1, u1.getPort());
+ assertEquals("1 returns a wrong file",
+ "/file.java", u1.getFile());
+ assertNull("1 returns a wrong anchor", u1.getRef());
+
+ u1 = new URL(u, "systemresource:/+/FILE0/test.java",
+ new MyHandler());
+ assertEquals("2 returns a wrong protocol",
+ "systemresource", u1.getProtocol());
+ assertTrue("2 returns a wrong host", u1.getHost().equals(""));
+ assertEquals("2 returns a wrong port", -1, u1.getPort());
+ assertEquals("2 returns a wrong file",
+ "/+/FILE0/test.java", u1.getFile());
+ assertNull("2 returns a wrong anchor", u1.getRef());
+
+ u1 = new URL(u, "dir1/dir2/../file.java", null);
+ assertEquals("3 returns a wrong protocol",
+ "http", u1.getProtocol());
+ assertEquals("3 returns a wrong host",
+ "www.yahoo.com", u1.getHost());
+ assertEquals("3 returns a wrong port", -1, u1.getPort());
+ assertEquals("3 returns a wrong file",
+ "/dir1/dir2/../file.java", u1.getFile());
+ assertNull("3 returns a wrong anchor", u1.getRef());
+
+ // test for question mark processing
+ u = new URL("http://www.foo.com/d0/d1/d2/cgi-bin?foo=bar/baz");
+
+ // test for relative file and out of bound "/../" processing
+ u1 = new URL(u, "../dir1/dir2/../file.java", new MyHandler());
+ assertTrue("A) returns a wrong file: " + u1.getFile(), u1.getFile()
+ .equals("/d0/d1/dir1/file.java"));
+
+ // test for absolute and relative file processing
+ u1 = new URL(u, "/../dir1/dir2/../file.java", null);
+ assertEquals("B) returns a wrong file",
+ "/../dir1/dir2/../file.java", u1.getFile());
URL one;
try {
@@ -683,8 +654,6 @@
u1 = new URL(u, "file.java", new MyHandler());
} catch (MalformedURLException e) {
return;
- } catch (Exception e) {
- fail("2 Exception during tests : " + e.getMessage());
}
fail("didn't throw expected MalFormedURLException");
}
@@ -716,64 +685,50 @@
* @tests java.net.URL#URL(java.lang.String, java.lang.String, int,
* java.lang.String)
*/
- public void test_ConstructorLjava_lang_StringLjava_lang_StringILjava_lang_String() {
+ public void test_ConstructorLjava_lang_StringLjava_lang_StringILjava_lang_String() throws Exception {
// Test for method java.net.URL(java.lang.String, java.lang.String, int,
// java.lang.String)
- try {
- u = new URL("http", "www.yahoo.com", 8080, "test.html#foo");
- assertEquals("SSIS returns a wrong protocol",
- "http", u.getProtocol());
- assertEquals("SSIS returns a wrong host",
- "www.yahoo.com", u.getHost());
- assertEquals("SSIS returns a wrong port", 8080, u.getPort());
- assertEquals("SSIS returns a wrong file",
- "test.html", u.getFile());
- assertTrue("SSIS returns a wrong anchor: " + u.getRef(), u.getRef()
- .equals("foo"));
- } catch (Exception e) {
- fail("SSIS Exception during test : " + e.getMessage());
- }
-
+ u = new URL("http", "www.yahoo.com", 8080, "test.html#foo");
+ assertEquals("SSIS returns a wrong protocol",
+ "http", u.getProtocol());
+ assertEquals("SSIS returns a wrong host",
+ "www.yahoo.com", u.getHost());
+ assertEquals("SSIS returns a wrong port", 8080, u.getPort());
+ assertEquals("SSIS returns a wrong file",
+ "test.html", u.getFile());
+ assertTrue("SSIS returns a wrong anchor: " + u.getRef(), u.getRef()
+ .equals("foo"));
}
/**
* @tests java.net.URL#URL(java.lang.String, java.lang.String, int,
* java.lang.String, java.net.URLStreamHandler)
*/
- public void test_ConstructorLjava_lang_StringLjava_lang_StringILjava_lang_StringLjava_net_URLStreamHandler() {
+ public void test_ConstructorLjava_lang_StringLjava_lang_StringILjava_lang_StringLjava_net_URLStreamHandler() throws Exception {
// Test for method java.net.URL(java.lang.String, java.lang.String, int,
// java.lang.String, java.net.URLStreamHandler)
- try {
- u = new URL("http", "www.yahoo.com", 8080, "test.html#foo", null);
- assertEquals("SSISH1 returns a wrong protocol", "http", u.getProtocol()
- );
- assertEquals("SSISH1 returns a wrong host",
- "www.yahoo.com", u.getHost());
- assertEquals("SSISH1 returns a wrong port", 8080, u.getPort());
- assertEquals("SSISH1 returns a wrong file",
- "test.html", u.getFile());
- assertTrue("SSISH1 returns a wrong anchor: " + u.getRef(), u
- .getRef().equals("foo"));
- } catch (Exception e) {
- fail("SSISH1 Exception during test : " + e.getMessage());
- }
-
- try {
- u = new URL("http", "www.yahoo.com", 8080, "test.html#foo",
- new MyHandler());
- assertEquals("SSISH2 returns a wrong protocol", "http", u.getProtocol()
- );
- assertEquals("SSISH2 returns a wrong host",
- "www.yahoo.com", u.getHost());
- assertEquals("SSISH2 returns a wrong port", 8080, u.getPort());
- assertEquals("SSISH2 returns a wrong file",
- "test.html", u.getFile());
- assertTrue("SSISH2 returns a wrong anchor: " + u.getRef(), u
- .getRef().equals("foo"));
- } catch (Exception e) {
- fail("SSISH2 Exception during test : " + e.getMessage());
- }
-
+ u = new URL("http", "www.yahoo.com", 8080, "test.html#foo", null);
+ assertEquals("SSISH1 returns a wrong protocol", "http", u.getProtocol()
+ );
+ assertEquals("SSISH1 returns a wrong host",
+ "www.yahoo.com", u.getHost());
+ assertEquals("SSISH1 returns a wrong port", 8080, u.getPort());
+ assertEquals("SSISH1 returns a wrong file",
+ "test.html", u.getFile());
+ assertTrue("SSISH1 returns a wrong anchor: " + u.getRef(), u
+ .getRef().equals("foo"));
+
+ u = new URL("http", "www.yahoo.com", 8080, "test.html#foo",
+ new MyHandler());
+ assertEquals("SSISH2 returns a wrong protocol", "http", u.getProtocol()
+ );
+ assertEquals("SSISH2 returns a wrong host",
+ "www.yahoo.com", u.getHost());
+ assertEquals("SSISH2 returns a wrong port", 8080, u.getPort());
+ assertEquals("SSISH2 returns a wrong file",
+ "test.html", u.getFile());
+ assertTrue("SSISH2 returns a wrong anchor: " + u.getRef(), u
+ .getRef().equals("foo"));
}
/**
@@ -916,41 +871,34 @@
try {
url.openStream();
fail("should throw FNFE.");
- } catch (Exception e){
- assertEquals("java.io.FileNotFoundException", e.getClass().getName());
+ } catch (java.io.FileNotFoundException e){
+ // Expected
}
- // Test for method java.io.InputStream java.net.URL.openStream()
- File resources = Support_Resources.createTempFolder();
- try {
- Support_Resources.copyFile(resources, null, "hyts_htmltest.html");
- u = new URL("file", "", resources.getAbsolutePath() +
- "/hyts_htmltest.html");
- // HTTP connection
- InputStream is1 = u.openStream();
- assertTrue("Unable to read from stream", is1.read() != 0);
- is1.close();
-
- boolean exception = false;
- try {
- u = new URL("file:///nonexistenttestdir/tstfile");
- u.openStream();
- } catch (IOException e) {
- // Correct behaviour
- exception = true;
- }
- assertTrue("openStream succeeded for non existent resource",
- exception);
+ // Test for method java.io.InputStream java.net.URL.openStream()
+ File resources = Support_Resources.createTempFolder();
+ Support_Resources.copyFile(resources, null, "hyts_htmltest.html");
+ u = new URL("file", "", resources.getAbsolutePath() +
+ "/hyts_htmltest.html");
+ // HTTP connection
+ InputStream is1 = u.openStream();
+ assertTrue("Unable to read from stream", is1.read() != 0);
+ is1.close();
- } catch (MalformedURLException e) {
- fail("Incorrect url specified : " + e.getMessage());
- } catch (IOException e) {
- fail("IOException opening stream : " + e.getMessage());
- }
+ boolean exception = false;
+ try {
+ u = new URL("file:///nonexistenttestdir/tstfile");
+ u.openStream();
+ } catch (IOException e) {
+ // Correct behaviour
+ exception = true;
+ }
+ assertTrue("openStream succeeded for non existent resource",
+ exception);
- int port = Support_Jetty.startHttpServerWithDocRoot("./src/test/resources/tests/api/java/net/");
- URL u = new URL("jar:" + "http://localhost:" + port
- + "/lf.jar!/plus.bmp");
+ int port = Support_Jetty.startHttpServerWithDocRoot("./src/test/resources/tests/api/java/net/");
+ URL u = new URL("jar:" + "http://localhost:" + port
+ + "/lf.jar!/plus.bmp");
InputStream in = u.openStream();
byte[] buf = new byte[3];
int result = in.read(buf);
@@ -1052,18 +1000,14 @@
/**
* @tests java.net.URL#getFile()
*/
- public void test_getFile() {
+ public void test_getFile() throws Exception {
// Test for method java.lang.String java.net.URL.getFile()
- try {
- u = new URL("http", "www.yahoo.com:8080", 1233,
- "test/!@$%^&*/test.html#foo");
- assertEquals("returns a wrong file",
- "test/!@$%^&*/test.html", u.getFile());
- u = new URL("http", "www.yahoo.com:8080", 1233, "");
- assertTrue("returns a wrong file", u.getFile().equals(""));
- } catch (Exception e) {
- fail("Exception raised : " + e.getMessage());
- }
+ u = new URL("http", "www.yahoo.com:8080", 1233,
+ "test/!@$%^&*/test.html#foo");
+ assertEquals("returns a wrong file",
+ "test/!@$%^&*/test.html", u.getFile());
+ u = new URL("http", "www.yahoo.com:8080", 1233, "");
+ assertTrue("returns a wrong file", u.getFile().equals(""));
}
/**
@@ -1077,17 +1021,13 @@
/**
* @tests java.net.URL#getPort()
*/
- public void test_getPort() {
+ public void test_getPort() throws Exception {
// Test for method int java.net.URL.getPort()
- try {
- u = new URL("http://member12.c++.com:9999");
- assertTrue("return wrong port number " + u.getPort(),
- u.getPort() == 9999);
- u = new URL("http://member12.c++.com:9999/");
- assertEquals("return wrong port number", 9999, u.getPort());
- } catch (Exception e) {
- fail("Threw exception : " + e.getMessage());
- }
+ u = new URL("http://member12.c++.com:9999");
+ assertTrue("return wrong port number " + u.getPort(),
+ u.getPort() == 9999);
+ u = new URL("http://member12.c++.com:9999/");
+ assertEquals("return wrong port number", 9999, u.getPort());
}
/**
@@ -1104,16 +1044,11 @@
/**
* @tests java.net.URL#getProtocol()
*/
- public void test_getProtocol() {
+ public void test_getProtocol() throws Exception {
// Test for method java.lang.String java.net.URL.getProtocol()
- try {
- u = new URL("http://www.yahoo2.com:9999");
- assertTrue("u returns a wrong protocol: " + u.getProtocol(), u
- .getProtocol().equals("http"));
-
- } catch (Exception e) {
- fail("Threw exception : " + e.getMessage());
- }
+ u = new URL("http://www.yahoo2.com:9999");
+ assertTrue("u returns a wrong protocol: " + u.getProtocol(), u
+ .getProtocol().equals("http"));
}
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/UnknownHostExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/UnknownHostExceptionTest.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/UnknownHostExceptionTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/UnknownHostExceptionTest.java Wed Oct 31 01:42:07 2007
@@ -24,16 +24,12 @@
*/
public void test_Constructor() {
// Test for method java.net.UnknownHostException()
- try {
- try {
- java.net.InetAddress.getByName("a.b.c.x.y.z.com");
- } catch (java.net.UnknownHostException e) {
- return;
- }
- fail("Failed to generate Exception");
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
+ try {
+ java.net.InetAddress.getByName("a.b.c.x.y.z.com");
+ } catch (java.net.UnknownHostException e) {
+ return;
+ }
+ fail("Failed to generate Exception");
}
/**
@@ -41,16 +37,12 @@
*/
public void test_ConstructorLjava_lang_String() {
// Test for method java.net.UnknownHostException(java.lang.String)
- try {
- try {
- java.net.InetAddress.getByName("a.b.c.x.y.z.com");
- } catch (java.net.UnknownHostException e) {
- return;
- }
- fail("Failed to generate Exception");
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
+ try {
+ java.net.InetAddress.getByName("a.b.c.x.y.z.com");
+ } catch (java.net.UnknownHostException e) {
+ return;
+ }
+ fail("Failed to generate Exception");
}
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/UnknownServiceExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/UnknownServiceExceptionTest.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/UnknownServiceExceptionTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/UnknownServiceExceptionTest.java Wed Oct 31 01:42:07 2007
@@ -25,16 +25,15 @@
/**
* @tests java.net.UnknownServiceException#UnknownServiceException()
*/
- public void test_Constructor() {
+ public void test_Constructor() throws Exception {
// Test for method java.net.UnknownServiceException()
try {
new URL("file://moo.txt").openConnection().getOutputStream();
} catch (UnknownServiceException e) {
// correct
return;
- } catch (Exception e) {
- fail("Wrong exception during test : " + e.getMessage());
- }
+ }
+
fail("Exception not thrown");
}
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java Wed Oct 31 01:42:07 2007
@@ -288,20 +288,16 @@
}
al.add(i, testObject);
int location = al.indexOf(testObject);
- try {
- al.ensureCapacity(capacity);
- assertTrue("EnsureCapacity moved objects around in array1.",
- location == al.indexOf(testObject));
- al.remove(0);
- al.ensureCapacity(capacity);
- assertTrue("EnsureCapacity moved objects around in array2.",
- --location == al.indexOf(testObject));
- al.ensureCapacity(capacity + 2);
- assertTrue("EnsureCapacity did not change location.",
- location == al.indexOf(testObject));
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
+ al.ensureCapacity(capacity);
+ assertTrue("EnsureCapacity moved objects around in array1.",
+ location == al.indexOf(testObject));
+ al.remove(0);
+ al.ensureCapacity(capacity);
+ assertTrue("EnsureCapacity moved objects around in array2.",
+ --location == al.indexOf(testObject));
+ al.ensureCapacity(capacity + 2);
+ assertTrue("EnsureCapacity did not change location.",
+ location == al.indexOf(testObject));
}
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/LocaleTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/LocaleTest.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/LocaleTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/LocaleTest.java Wed Oct 31 01:42:07 2007
@@ -97,16 +97,12 @@
// Test for method java.util.Locale []
// java.util.Locale.getAvailableLocales()
// Assumes there will generally be about 100+ available locales...
- try {
- Locale[] locales = Locale.getAvailableLocales();
- assertTrue("Wrong number of locales: ", locales.length > 100);
- // regression test for HARMONY-1514
- // HashSet can filter duplicate locales
- Set<Locale> localesSet = new HashSet<Locale>(Arrays.asList(locales));
- assertEquals(localesSet.size(), locales.length);
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
+ Locale[] locales = Locale.getAvailableLocales();
+ assertTrue("Wrong number of locales: ", locales.length > 100);
+ // regression test for HARMONY-1514
+ // HashSet can filter duplicate locales
+ Set<Locale> localesSet = new HashSet<Locale>(Arrays.asList(locales));
+ assertEquals(localesSet.size(), locales.length);
}
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ObservableTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ObservableTest.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ObservableTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ObservableTest.java Wed Oct 31 01:42:07 2007
@@ -77,13 +77,9 @@
*/
public void test_Constructor() {
// Test for method java.util.Observable()
- try {
- Observable ov = new Observable();
- assertTrue("Wrong initial values.", !ov.hasChanged());
- assertEquals("Wrong initial values.", 0, ov.countObservers());
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
+ Observable ov = new Observable();
+ assertTrue("Wrong initial values.", !ov.hasChanged());
+ assertEquals("Wrong initial values.", 0, ov.countObservers());
}
/**
@@ -104,9 +100,6 @@
fail("Expected adding a null observer to throw a NPE.");
} catch (NullPointerException ex) {
// expected;
- } catch (Throwable ex) {
- fail("Did not expect adding a new observer to throw a "
- + ex.getClass().getName());
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/java/nio/channels/spi/AbstractSelectableChannel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/java/nio/channels/spi/AbstractSelectableChannel.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/java/nio/channels/spi/AbstractSelectableChannel.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/java/nio/channels/spi/AbstractSelectableChannel.java Wed Oct 31 01:42:07 2007
@@ -26,7 +26,6 @@
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
/**
@@ -35,7 +34,6 @@
* In this class, there are methods about registering/deregistering a channel,
* about channel closing. It realize the multi-thread safe.
* </p>
- *
*/
public abstract class AbstractSelectableChannel extends SelectableChannel {
@@ -71,6 +69,7 @@
* @see java.nio.channels.SelectableChannel#provider()
* @return The provider of this channel.
*/
+ @Override
public final SelectorProvider provider() {
return provider;
}
@@ -78,6 +77,7 @@
/**
* @see java.nio.channels.SelectableChannel#isRegistered()
*/
+ @Override
synchronized public final boolean isRegistered() {
return !keyList.isEmpty();
}
@@ -85,6 +85,7 @@
/**
* @see java.nio.channels.SelectableChannel#keyFor(java.nio.channels.Selector)
*/
+ @Override
synchronized public final SelectionKey keyFor(Selector selector) {
for (int i = 0; i < keyList.size(); i++) {
SelectionKey key = keyList.get(i);
@@ -109,6 +110,7 @@
* @see java.nio.channels.SelectableChannel#register(java.nio.channels.Selector,
* int, java.lang.Object)
*/
+ @Override
public final SelectionKey register(Selector selector, int interestSet,
Object attachment) throws ClosedChannelException {
if (!isOpen()) {
@@ -155,6 +157,7 @@
*
* @see java.nio.channels.spi.AbstractInterruptibleChannel#implCloseChannel()
*/
+ @Override
synchronized protected final void implCloseChannel() throws IOException {
implCloseSelectableChannel();
for (int i = 0; i < keyList.size(); i++) {
@@ -176,6 +179,7 @@
/**
* @see java.nio.channels.SelectableChannel#isBlocking()
*/
+ @Override
public final boolean isBlocking() {
synchronized (blockingLock) {
return isBlocking;
@@ -185,6 +189,7 @@
/**
* @see java.nio.channels.SelectableChannel#blockingLock()
*/
+ @Override
public final Object blockingLock() {
return blockingLock;
}
@@ -197,6 +202,7 @@
* <code>true</code> for blocking mode; <code>false</code>
* for non-blocking mode.
*/
+ @Override
public final SelectableChannel configureBlocking(boolean blockingMode)
throws IOException {
if (isOpen()) {
@@ -213,7 +219,6 @@
return this;
}
throw new ClosedChannelException();
-
}
/**
@@ -238,12 +243,12 @@
}
/**
- * Returns true if the keyList contains at least 1 valid key and false otherwise.
+ * Returns true if the keyList contains at least 1 valid key and false
+ * otherwise.
*/
private synchronized boolean containsValidKeys() {
- for (Iterator<SelectionKey> iter = keyList.iterator(); iter.hasNext();) {
- SelectionKey key = iter.next();
-
+ for (int i = 0; i < keyList.size(); i++) {
+ SelectionKey key = keyList.get(i);
if (key != null && key.isValid()) {
return true;
}
Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/native/nio/unix/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/native/nio/unix/makefile?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/native/nio/unix/makefile (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/native/nio/unix/makefile Wed Oct 31 01:42:07 2007
@@ -22,7 +22,10 @@
CFLAGS += -fpic
BUILDFILES = \
- ../shared/DirectBufferUtil.o ../shared/AddressUtil.o ../unix/EpollSelectorImpl.o
+ ../shared/DirectBufferUtil.o ../shared/AddressUtil.o
+ifeq ($(HY_OS),linux)
+BUILDFILES += ../unix/EpollSelectorImpl.o
+endif
ifneq ($(HY_ZIP_API),true)
MDLLIBFILES += $(LIBPATH)libhyzip.a
Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java Wed Oct 31 01:42:07 2007
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.apache.harmony.nio.tests.java.nio.channels;
import java.io.File;
Modified: harmony/enhanced/classlib/branches/java6/modules/nio_char/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio_char/META-INF/MANIFEST.MF?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio_char/META-INF/MANIFEST.MF (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio_char/META-INF/MANIFEST.MF Wed Oct 31 01:42:07 2007
@@ -11,7 +11,7 @@
Bundle-Version: 1.0.0
Bundle-ClassPath: .
Eclipse-JREBundle: true
-Import-Package: com.ibm.icu4jni.charset,
+Import-Package: com.ibm.icu.charset,
java.io,
java.lang,
java.lang.ref,
Modified: harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/org/apache/harmony/niochar/java.nio.charset.spi.CharsetProvider
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/org/apache/harmony/niochar/java.nio.charset.spi.CharsetProvider?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/org/apache/harmony/niochar/java.nio.charset.spi.CharsetProvider (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/org/apache/harmony/niochar/java.nio.charset.spi.CharsetProvider Wed Oct 31 01:42:07 2007
@@ -1,2 +1,2 @@
# NIO charset SPI extended charset provider
-com.ibm.icu4jni.charset.CharsetProviderICU
\ No newline at end of file
+com.ibm.icu.charset.CharsetProviderICU
Modified: harmony/enhanced/classlib/branches/java6/modules/nio_char/src/test/java/tests/api/java/nio/charset/AbstractCharsetTestCase.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio_char/src/test/java/tests/api/java/nio/charset/AbstractCharsetTestCase.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio_char/src/test/java/tests/api/java/nio/charset/AbstractCharsetTestCase.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio_char/src/test/java/tests/api/java/nio/charset/AbstractCharsetTestCase.java Wed Oct 31 01:42:07 2007
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package tests.api.java.nio.charset;
import java.nio.ByteBuffer;
Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java Wed Oct 31 01:42:07 2007
@@ -184,24 +184,37 @@
public long[][] parseFlags(String name, InputStream in, int counts[],
BHSDCodec hiCodec, BHSDCodec loCodec) throws IOException,
Pack200Exception {
- // TODO Move away from decoding into a parseBand type structure
int count = counts.length;
if (count == 0) {
return new long[][] { {} };
}
+ int sum = 0;
long[][] result = new long[count][];
- for (int j = 0; j < count; j++) {
- int[] hi;
- if(hiCodec != null) {
- hi = decodeBandInt(name, in, hiCodec, counts[j]);
- result[j] = decodeBandLong(name, in, loCodec, counts[j]);
- for (int i = 0; i < counts[j]; i++) {
- result[j][i] = (hi[i] << 32) |result[j][i];
+ for (int i = 0; i < count; i++) {
+ result[i] = new long[counts[i]];
+ sum += counts[i];
+ }
+ int[] hi = null;
+ int[] lo;
+ if(hiCodec != null) {
+ hi = decodeBandInt(name, in, hiCodec, sum);
+ lo = decodeBandInt(name, in, loCodec, sum);
+ } else {
+ lo = decodeBandInt(name, in, loCodec, sum);
+ }
+
+ int index = 0;
+ for (int i = 0; i < result.length; i++) {
+ for (int j = 0; j < result[i].length; j++) {
+ if(hi != null) {
+ result[i][j] = (hi[index] << 32) | lo[index];
+ } else {
+ result[i][j] = lo[index];
}
- } else {
- result[j] = decodeBandLong(name, in, loCodec, counts[j]);
+ index++;
}
}
+
// TODO Remove debugging code
debug("Parsed *" + name + " (" + result.length + ")");
return result;
@@ -280,7 +293,7 @@
}
// TODO Merge the decode and parsing of a multiple structure into one
String[] result1 = new String[sum];
- int[] indices = decodeBandInt(name, in, codec, sum);
+ int[] indices = decodeBandInt(name, in, codec, sum, reference.length - 1);
for (int i1 = 0; i1 < sum; i1++) {
int index = indices[i1];
if (index < 0 || index >= reference.length)
@@ -298,6 +311,60 @@
pos += num;
}
return result;
+ }
+
+ private int[] decodeBandInt(String name, InputStream in, BHSDCodec codec, int count, int maxValue) throws IOException, Pack200Exception {
+ long[] band;
+ Codec codecUsed = codec;
+ if (codec.getB() == 1 || count == 0) {
+ band = codec.decode(count, in);
+ } else {
+ long[] getFirst = codec.decode(1, in);
+ if (getFirst.length == 0) {
+ return new int[0];
+ }
+ long first = getFirst[0];
+ if (codec.isSigned() && first >= -256 && first <= -1) {
+ // Non-default codec should be used
+ codecUsed = CodecEncoding.getCodec((int) (-1 - first),
+ header.getBandHeadersInputStream(), codec);
+ band = codecUsed.decode(count, in);
+ } else if (!codec.isSigned() && first >= codec.getL()
+ && first <= codec.getL() + 255) {
+ // Non-default codec should be used
+ codecUsed = CodecEncoding.getCodec((int) first
+ - codec.getL(), header.getBandHeadersInputStream(), codec);
+ band = codecUsed.decode(count, in);
+ } else {
+ // First element should not be discarded
+ band = codec.decode(count - 1, in, first);
+ }
+ }
+
+ int[] returnBand = new int[band.length];
+ for (int i = 0; i < returnBand.length; i++) {
+ returnBand[i] = (int)band[i];
+ }
+
+ /*
+ * Note - this is not in the spec, but seems to be used as an
+ * optimization by the RI for bands where the minimum and maximum values
+ * are known (ie reference bands). It will not hurt any encoding that is
+ * following the spec because all the values decoded will be inside the
+ * range anyway.
+ */
+ if (codecUsed instanceof BHSDCodec) {
+ for (int i = 0; i < returnBand.length; i++) {
+ while (returnBand[i] < 0) {
+ returnBand[i] += ((BHSDCodec) codecUsed).cardinality();
+ }
+ while (returnBand[i] > maxValue) {
+ returnBand[i] -= ((BHSDCodec) codecUsed).cardinality();
+ }
+ }
+ }
+
+ return returnBand;
}
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java Wed Oct 31 01:42:07 2007
@@ -20,6 +20,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
+import java.util.Arrays;
import org.apache.harmony.pack200.bytecode.CPClass;
import org.apache.harmony.pack200.bytecode.ConstantValueAttribute;
@@ -233,7 +234,7 @@
if ((flag & (1 << 16)) != 0)
methodAttrCount++;
}
- }
+ }
int[] methodAttrCounts = decodeBandInt("method_attr_count", in, Codec.UNSIGNED5, methodAttrCount);
int[][] methodAttrIndexes = decodeBandInt("method_attr_indexes", in, Codec.UNSIGNED5, methodAttrCounts);
int callCount = 0;
@@ -424,7 +425,7 @@
sourceFileIndex++;
}
if(enclosingMethodLayout.matches(flag)) {
- // TODO
+ // TODO
}
if(signatureLayout.matches(flag)) {
// TODO
@@ -510,7 +511,6 @@
if ((flag & (1 << 16)) != 0)
codeAttrCount++;
}
- System.out.println("codeAttrCount = " + codeAttrCount);
int[] codeAttrCounts = decodeBandInt("code_attr_count", in, Codec.UNSIGNED5, codeAttrCount);
int[][] codeAttrIndexes = decodeBandInt("code_attr_indexes", in, Codec.UNSIGNED5, codeAttrCounts);
int callCount = 0;
@@ -521,11 +521,9 @@
callCount += layout.numBackwardsCallables();
}
}
- System.out.println("callCount = " + callCount);
int[] codeAttrCalls = decodeBandInt("code_attr_calls", in, Codec.UNSIGNED5, callCount);
int lineNumberTableCount = SegmentUtils.countMatches(codeFlags, attrMap.getAttributeLayout(AttributeLayout.ATTRIBUTE_LINE_NUMBER_TABLE, AttributeLayout.CONTEXT_CODE));
- System.out.println("lineNumberTables = " + lineNumberTableCount);
int[] lineNumberTableN = decodeBandInt("code_LineNumberTable_N", in, Codec.UNSIGNED5, lineNumberTableCount);
int[][] lineNumberTableBciP = decodeBandInt("code_LineNumberTable_bci_P", in, Codec.BCI5, lineNumberTableN);
int[][] lineNumberTableLine = decodeBandInt("code_LineNumberTable_line", in, Codec.UNSIGNED5, lineNumberTableN);
@@ -533,7 +531,6 @@
for (int i = 0; i < types.length; i++) {
String type = types[i];
int lengthNBand = SegmentUtils.countMatches(codeFlags, attrMap.getAttributeLayout(type, AttributeLayout.CONTEXT_CODE));
- System.out.println(type + " count = " + lengthNBand);
int[] nBand = decodeBandInt("code_" + type + "_N", in, Codec.UNSIGNED5, lengthNBand);
int[][] bciP = decodeBandInt("code_" + type + "_bci_P", in, Codec.BCI5, nBand);
Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java?rev=590591&r1=590590&r2=590591&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java Wed Oct 31 01:42:07 2007
@@ -95,7 +95,7 @@
* @throws IOException if there is a problem reading from the input stream (which
* in reality, is never, since the band_headers are likely stored in a byte array
* and accessed via a ByteArrayInputStream. However, an EOFException could occur
- * if things go titsup.com.
+ * if things go wrong)
* @throws Pack200Exception
*/
public static Codec getCodec(int value, InputStream in, Codec defaultCodec) throws IOException, Pack200Exception {
@@ -151,7 +151,7 @@
boolean fdef = (offset & 1) == 1;
boolean udef = (offset >> 1 & 1) == 1;
int tdefl = offset >> 2;
- boolean tdef = tdefl == 0;
+ boolean tdef = tdefl != 0;
// From section 6.7.3 of spec
final int[] tdefToL= {0,4,8,16,32,64,128,192,224,240,248,252 };
int l = tdefToL[tdefl];