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 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 


1411     static void eqHashComp() throws URISyntaxException {
1412 
1413         header("Equality, hashing, and comparison");
1414 
1415         URI o = new URI("mailto:foo@bar.com");
1416         URI r = new URI("reg://some%20registry/b/c/d?q#f");
1417         URI s = new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?q#f");
1418         eq(o, o);
1419         lt(o, r);
1420         lt(s, o);
1421         lt(s, r);
1422         eq(o, new URI("MaILto:foo@bar.com"));
1423         gt(o, new URI("mailto:foo@bar.COM"));
1424         eq(r, new URI("rEg://some%20registry/b/c/d?q#f"));
1425         gt(r, new URI("reg://Some%20Registry/b/c/d?q#f"));
1426         gt(r, new URI("reg://some%20registry/b/c/D?q#f"));
1427         eq(s, new URI("hTtP://jag:cafebabe@Java.Sun.COM:94/b/c/d?q#f"));
1428         gt(s, new URI("http://jag:CafeBabe@java.sun.com:94/b/c/d?q#f"));
1429         lt(s, new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?r#f"));
1430         lt(s, new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?q#g"));


1431 
1432         lt("p", "s:p");
1433         lt("s:p", "T:p");
1434         lt("S:p", "t:p");
1435         lt("s:/p", "s:p");
1436         lt("s:p", "s:q");
1437         lt("s:p#f", "s:p#g");
1438         lt("s://u@h:1", "s://v@h:1");
1439         lt("s://u@h:1", "s://u@i:1");
1440         lt("s://u@h:1", "s://v@h:2");
1441         lt("s://a%20b", "s://a%20c");
1442         lt("s://a%20b", "s://aab");
1443         lt("s://AA", "s://A_");
1444         lt("s:/p", "s:/q");
1445         lt("s:/p?q", "s:/p?r");
1446         lt("s:/p#f", "s:/p#g");
1447 
1448         lt("s://h", "s://h/p");
1449         lt("s://h/p", "s://h/p?q");
1450 




   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 7041800
  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 


1411     static void eqHashComp() throws URISyntaxException {
1412 
1413         header("Equality, hashing, and comparison");
1414 
1415         URI o = new URI("mailto:foo@bar.com");
1416         URI r = new URI("reg://some%20registry/b/c/d?q#f");
1417         URI s = new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?q#f");
1418         eq(o, o);
1419         lt(o, r);
1420         lt(s, o);
1421         lt(s, r);
1422         eq(o, new URI("MaILto:foo@bar.com"));
1423         gt(o, new URI("mailto:foo@bar.COM"));
1424         eq(r, new URI("rEg://some%20registry/b/c/d?q#f"));
1425         gt(r, new URI("reg://Some%20Registry/b/c/d?q#f"));
1426         gt(r, new URI("reg://some%20registry/b/c/D?q#f"));
1427         eq(s, new URI("hTtP://jag:cafebabe@Java.Sun.COM:94/b/c/d?q#f"));
1428         gt(s, new URI("http://jag:CafeBabe@java.sun.com:94/b/c/d?q#f"));
1429         lt(s, new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?r#f"));
1430         lt(s, new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?q#g"));
1431         eq(new URI("http://host/a%00bcd"), new URI("http://host/a%00bcd"));
1432         ne(new URI("http://host/a%00bcd"), new URI("http://host/aZ00bcd"));
1433 
1434         lt("p", "s:p");
1435         lt("s:p", "T:p");
1436         lt("S:p", "t:p");
1437         lt("s:/p", "s:p");
1438         lt("s:p", "s:q");
1439         lt("s:p#f", "s:p#g");
1440         lt("s://u@h:1", "s://v@h:1");
1441         lt("s://u@h:1", "s://u@i:1");
1442         lt("s://u@h:1", "s://v@h:2");
1443         lt("s://a%20b", "s://a%20c");
1444         lt("s://a%20b", "s://aab");
1445         lt("s://AA", "s://A_");
1446         lt("s:/p", "s:/q");
1447         lt("s:/p?q", "s:/p?r");
1448         lt("s:/p#f", "s:/p#g");
1449 
1450         lt("s://h", "s://h/p");
1451         lt("s://h/p", "s://h/p?q");
1452