test/java/net/URI/Test.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @summary Unit test for java.net.URI
  26  * @bug 4464135 4505046 4503239 4438319 4991359 4866303
  27  * @author Mark Reinhold
  28  */
  29 
  30 import java.io.ByteArrayInputStream;
  31 import java.io.ByteArrayOutputStream;
  32 import java.io.IOException;
  33 import java.io.ObjectInputStream;
  34 import java.io.ObjectOutputStream;
  35 import java.io.PrintStream;
  36 import java.net.URI;
  37 import java.net.URISyntaxException;
  38 import java.net.URL;
  39 import java.net.MalformedURLException;
  40 
  41 
  42 public class Test {
  43 
  44     static PrintStream out = System.out;
  45     static int testCount = 0;
  46 


1033 
1034         test("http://[ff01:234/foo").x().z();
1035         test("http://[ff01:234:zzz]/foo").x().z();
1036         test("http://[foo]").x().z();
1037         test("http://[]").x().z();
1038         test("http://[129.33.44.55]").x().z();
1039         test("http://[ff:ee:dd:cc:bb::aa:9:8]").x().z();
1040         test("http://[fffff::1]").x().z();
1041         test("http://[ff::ee::8]").x().z();
1042         test("http://[1:2:3:4::5:6:7:8]").x().z();
1043         test("http://[1:2]").x().z();
1044         test("http://[1:2:3:4:5:6:7:8:9]").x().z();
1045         test("http://[1:2:3:4:5:6:7:8%]").x().z();
1046         test("http://[1:2:3:4:5:6:7:8%!/]").x().z();
1047         test("http://[::1.2.3.300]").x().z();
1048         test("http://1.2.3").psa().x().z();
1049         test("http://1.2.3.300").psa().x().z();
1050         test("http://1.2.3.4.5").psa().x().z();
1051         test("http://[1.2.3.4:5]").x().z();
1052         test("http://1:2:3:4:5:6:7:8").psa().x().z();







1053 
1054         // Test hostnames that might initially look like IPv4 addresses
1055 
1056         test("s://1.2.3.com").psa().s("s").h("1.2.3.com").p("").z();
1057         test("s://1.2.3.4me.com").psa().s("s").h("1.2.3.4me.com").p("").z();
1058 
1059         test("s://7up.com").psa().s("s").h("7up.com").p("").z();
1060         test("s://7up.com/p").psa().s("s").h("7up.com").p("/p").z();
1061         test("s://7up").psa().s("s").h("7up").p("").z();
1062         test("s://7up/p").psa().s("s").h("7up").p("/p").z();
1063         test("s://7up.").psa().s("s").h("7up.").p("").z();
1064         test("s://7up./p").psa().s("s").h("7up.").p("/p").z();
1065     }
1066 
1067 
1068     static void misc() throws URISyntaxException {
1069 
1070         URI base = new URI("s://h/a/b");
1071         URI rbase = new URI("a/b/c/d");
1072 




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @summary Unit test for java.net.URI
  26  * @bug 4464135 4505046 4503239 4438319 4991359 4866303 7023363
  27  * @author Mark Reinhold
  28  */
  29 
  30 import java.io.ByteArrayInputStream;
  31 import java.io.ByteArrayOutputStream;
  32 import java.io.IOException;
  33 import java.io.ObjectInputStream;
  34 import java.io.ObjectOutputStream;
  35 import java.io.PrintStream;
  36 import java.net.URI;
  37 import java.net.URISyntaxException;
  38 import java.net.URL;
  39 import java.net.MalformedURLException;
  40 
  41 
  42 public class Test {
  43 
  44     static PrintStream out = System.out;
  45     static int testCount = 0;
  46 


1033 
1034         test("http://[ff01:234/foo").x().z();
1035         test("http://[ff01:234:zzz]/foo").x().z();
1036         test("http://[foo]").x().z();
1037         test("http://[]").x().z();
1038         test("http://[129.33.44.55]").x().z();
1039         test("http://[ff:ee:dd:cc:bb::aa:9:8]").x().z();
1040         test("http://[fffff::1]").x().z();
1041         test("http://[ff::ee::8]").x().z();
1042         test("http://[1:2:3:4::5:6:7:8]").x().z();
1043         test("http://[1:2]").x().z();
1044         test("http://[1:2:3:4:5:6:7:8:9]").x().z();
1045         test("http://[1:2:3:4:5:6:7:8%]").x().z();
1046         test("http://[1:2:3:4:5:6:7:8%!/]").x().z();
1047         test("http://[::1.2.3.300]").x().z();
1048         test("http://1.2.3").psa().x().z();
1049         test("http://1.2.3.300").psa().x().z();
1050         test("http://1.2.3.4.5").psa().x().z();
1051         test("http://[1.2.3.4:5]").x().z();
1052         test("http://1:2:3:4:5:6:7:8").psa().x().z();
1053         test("http://[1.2.3.4]/").x().z();
1054         test("http://[1.2.3.4/").x().z();
1055         test("http://[foo]/").x().z();
1056         test("http://[foo/").x().z();
1057         test("s", "[foo]", "/", null, null).x().z();
1058         test("s", "[foo", "/", null, null).x().z();
1059         test("s", "[::foo", "/", null, null).x().z();
1060 
1061         // Test hostnames that might initially look like IPv4 addresses
1062 
1063         test("s://1.2.3.com").psa().s("s").h("1.2.3.com").p("").z();
1064         test("s://1.2.3.4me.com").psa().s("s").h("1.2.3.4me.com").p("").z();
1065 
1066         test("s://7up.com").psa().s("s").h("7up.com").p("").z();
1067         test("s://7up.com/p").psa().s("s").h("7up.com").p("/p").z();
1068         test("s://7up").psa().s("s").h("7up").p("").z();
1069         test("s://7up/p").psa().s("s").h("7up").p("/p").z();
1070         test("s://7up.").psa().s("s").h("7up.").p("").z();
1071         test("s://7up./p").psa().s("s").h("7up.").p("/p").z();
1072     }
1073 
1074 
1075     static void misc() throws URISyntaxException {
1076 
1077         URI base = new URI("s://h/a/b");
1078         URI rbase = new URI("a/b/c/d");
1079