test/jdk/sun/net/www/protocol/jar/CanonicalizationTest.java
author prr
Fri, 25 May 2018 12:12:24 -0700
changeset 50347 b2f046ae8eb6
parent 48897 3f19b5965355
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48897
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
     1
/*
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
     4
 *
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
     8
 *
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    13
 * accompanied this code).
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    14
 *
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    18
 *
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    21
 * questions.
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    22
 */
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    23
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    24
/**
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    25
 * @test
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    26
 * @bug 8197849
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    27
 * @summary Sanity test the special canonicalization logic for jar resources
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    28
 */
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    29
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    30
import java.net.URL;
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    31
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    32
public class CanonicalizationTest {
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    33
    public static void main(String args[]) throws Exception {
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    34
        URL base = new URL("jar:file:/foo!/");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    35
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    36
        check(new URL(base, ""), "jar:file:/foo!/");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    37
        check(new URL(base, "."), "jar:file:/foo!/");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    38
        check(new URL(base, ".."), "jar:file:/foo!");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    39
        check(new URL(base, ".x"), "jar:file:/foo!/.x");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    40
        check(new URL(base, "..x"), "jar:file:/foo!/..x");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    41
        check(new URL(base, "..."), "jar:file:/foo!/...");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    42
        check(new URL(base, "foo/."), "jar:file:/foo!/foo/");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    43
        check(new URL(base, "foo/.."), "jar:file:/foo!/");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    44
        check(new URL(base, "foo/.x"), "jar:file:/foo!/foo/.x");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    45
        check(new URL(base, "foo/..x"), "jar:file:/foo!/foo/..x");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    46
        check(new URL(base, "foo/..."), "jar:file:/foo!/foo/...");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    47
        check(new URL(base, "foo/./"), "jar:file:/foo!/foo/");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    48
        check(new URL(base, "foo/../"), "jar:file:/foo!/");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    49
        check(new URL(base, "foo/.../"), "jar:file:/foo!/foo/.../");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    50
        check(new URL(base, "foo/../../"), "jar:file:/foo!/");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    51
        check(new URL(base, "foo/../,,/.."), "jar:file:/foo!/");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    52
        check(new URL(base, "foo/../."), "jar:file:/foo!/");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    53
        check(new URL(base, "foo/../.x"), "jar:file:/foo!/.x");
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    54
    }
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    55
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    56
    private static void check(URL url, String expected) {
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    57
        if (!url.toString().equals(expected)) {
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    58
            throw new AssertionError("Expected " + url + " to equal " + expected);
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    59
        }
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    60
    }
3f19b5965355 8197849: Misc improvements to jar resource handling
redestad
parents:
diff changeset
    61
}