jdk/test/java/net/URI/URItoURLTest.java
author dsamersoff
Thu, 17 Oct 2013 16:08:01 +0400
changeset 21069 728330d2593a
parent 5506 202f599c92aa
child 35393 12d55e1947f7
permissions -rw-r--r--
8025812: tmtools/jmap/heap_config tests fail on Linux-ia32 because it Cant attach to the core file Summary: Coredump store memsz elf field rounded up to page Reviewed-by: dholmes, sla
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug  4768755 4677045
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary URL.equal(URL) is inconsistant for opaque URI.toURL()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *                      and new URL(URI.toString)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *          URI.toURL() does not always work as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
public class URItoURLTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        URItoURLTest testClass = new URItoURLTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        URL classUrl = testClass.getClass().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                                    getResource("/java/lang/Object.class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        String[] uris = { "mailto:xyz@abc.de",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
                        "file:xyz#ab",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                        "http:abc/xyz/pqr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                        "file:/C:/v700/dev/unitTesting/tests/apiUtil/uri",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                        "http:///p",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                        classUrl.toExternalForm(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        boolean isTestFailed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        boolean isURLFailed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        for (int i = 0; i < uris.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            URI uri = URI.create(uris[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            URL url1 = new URL(uri.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            URL url2 = uri.toURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            System.out.println("Testing URI " + uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            if (!url1.equals(url2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                System.out.println("equals() FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                isURLFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            if (url1.hashCode() != url2.hashCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                System.out.println("hashCode() DIDN'T MATCH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                isURLFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            if (!url1.sameFile(url2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                System.out.println("sameFile() FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                isURLFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            if (!equalsComponents("getPath()", url1.getPath(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                            url2.getPath())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                isURLFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            if (!equalsComponents("getFile()", url1.getFile(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                            url2.getFile())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                isURLFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (!equalsComponents("getHost()", url1.getHost(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                            url2.getHost())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                isURLFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            if (!equalsComponents("getAuthority()",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                url1.getAuthority(), url2.getAuthority())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                isURLFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            if (!equalsComponents("getRef()", url1.getRef(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                            url2.getRef())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                isURLFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (!equalsComponents("getUserInfo()", url1.getUserInfo(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                            url2.getUserInfo())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                isURLFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (!equalsComponents("toString()", url1.toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                                            url2.toString())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                isURLFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            if (isURLFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                isTestFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                System.out.println("PASSED ..");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            isURLFailed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (isTestFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            throw new Exception("URI.toURL() test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    static boolean equalsComponents(String method, String comp1, String comp2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if ((comp1 != null) && (!comp1.equals(comp2))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            System.out.println(method + " DIDN'T MATCH" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                        "  ===>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                System.out.println("    URL(URI.toString()) returns:" + comp1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                System.out.println("    URI.toURL() returns:" + comp2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
}