jdk/test/java/net/URI/Test.java
author dsamersoff
Thu, 17 Oct 2013 16:08:01 +0400
changeset 21069 728330d2593a
parent 15272 b0055428d835
child 23010 6dadb192ad81
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
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8778
diff changeset
     2
 * Copyright (c) 2000, 2011, 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
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @summary Unit test for java.net.URI
10422
83581a2cf49d 7041800: URI.equals may incorrectly return true with escaped octets
chegar
parents: 9035
diff changeset
    26
 * @bug 4464135 4505046 4503239 4438319 4991359 4866303 7023363 7041800
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
    27
 *      7171415
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.net.URISyntaxException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class Test {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static PrintStream out = System.out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static int testCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    // Properties that we check
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static final int PARSEFAIL   = 1 << 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static final int SCHEME      = 1 << 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static final int SSP         = 1 << 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static final int SSP_D       = 1 << 3;      // Decoded form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static final int OPAQUEPART  = 1 << 4;      // SSP, and URI is opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static final int USERINFO    = 1 << 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static final int USERINFO_D  = 1 << 6;      // Decoded form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static final int HOST        = 1 << 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static final int PORT        = 1 << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static final int REGISTRY    = 1 << 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static final int REGISTRY_D  = 1 << 10;     // Decoded form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static final int PATH        = 1 << 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static final int PATH_D      = 1 << 12;     // Decoded form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static final int QUERY       = 1 << 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static final int QUERY_D     = 1 << 14;     // Decoded form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static final int FRAGMENT    = 1 << 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    static final int FRAGMENT_D  = 1 << 16;     // Decoded form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    static final int TOASCII     = 1 << 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static final int IDENT_STR   = 1 << 18;     // Identities
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    static final int IDENT_URI1  = 1 << 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    static final int IDENT_URI3  = 1 << 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    static final int IDENT_URI5  = 1 << 21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    static final int IDENT_URI7  = 1 << 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static final int TOSTRING    = 1 << 23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    String input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    URI uri = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    URI originalURI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    URI base = null;                    // Base for resolution/relativization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    String op = null;                   // Op performed if uri != originalURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    int checked = 0;                    // Mask for checked properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    int failed = 0;                     // Mask for failed properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    Exception exc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private Test(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        input = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            uri = new URI(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            exc = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        originalURI = uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    static Test test(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        return new Test(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private Test(String s, String u, String h, int n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                 String p, String q, String f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            uri = new URI(s, u, h, n, p, q, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            exc = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            input = x.getInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (uri != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            input = uri.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        originalURI = uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    static Test test(String s, String u, String h, int n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                     String p, String q, String f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return new Test(s, u, h, n, p, q, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private Test(String s, String a,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                 String p, String q, String f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            uri = new URI(s, a, p, q, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            exc = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            input = x.getInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (uri != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            input = uri.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        originalURI = uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    static Test test(String s, String a,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                     String p, String q, String f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return new Test(s, a, p, q, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private Test(String s, String h, String p, String f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            uri = new URI(s, h, p, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            exc = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            input = x.getInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (uri != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            input = uri.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        originalURI = uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    static Test test(String s, String h, String p, String f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return new Test(s, h, p, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private Test(String s, String ssp, String f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            uri = new URI(s, ssp, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            exc = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            input = x.getInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (uri != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            input = uri.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        originalURI = uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    static Test test(String s, String ssp, String f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return new Test(s, ssp, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private Test(String s, boolean xxx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            uri = URI.create(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        } catch (IllegalArgumentException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            exc = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (uri != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            input = uri.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        originalURI = uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    static Test testCreate(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return new Test(s, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    boolean parsed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return uri != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    boolean resolved() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return base != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    URI uri() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    // Operations on Test instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    // These are short so as to make test cases compact.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    //    s      Scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    //    sp     Scheme-specific part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    //    spd    Scheme-specific part, decoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    //    o      Opaque part (isOpaque() && ssp matches)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    //    g      reGistry (authority matches, and host is not defined)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    //    gd     reGistry, decoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    //    u      User info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    //    ud     User info, decoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    //    h      Host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    //    n      port Number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    //    p      Path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    //    pd     Path, decoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    //    q      Query
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    //    qd     Query, decoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    //    f      Fragment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    //    fd     Fragment, decoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    //    rslv   Resolve against given base
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    //    rtvz   Relativize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    //    psa    Parse server Authority
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    //    norm   Normalize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    //    ta     ASCII form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    //    x      Check that parse failed as expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    //    z      End -- ensure that unchecked components are null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private boolean check1(int prop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        checked |= prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (!parsed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            failed |= prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    private void check2(String s, String ans, int prop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if ((s == null) || !s.equals(ans))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            failed |= prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    Test s(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (check1(SCHEME)) check2(uri.getScheme(), s, SCHEME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    Test u(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (check1(USERINFO)) check2(uri.getRawUserInfo(), s, USERINFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    Test ud(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (check1(USERINFO_D)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            check2(uri.getUserInfo(), s, USERINFO_D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    Test h(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (check1(HOST)) check2(uri.getHost(), s, HOST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    Test g(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (check1(REGISTRY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            if (uri.getHost() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                failed |= REGISTRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                check2(uri.getRawAuthority(), s, REGISTRY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    Test gd(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (check1(REGISTRY_D)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if (uri.getHost() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                failed |= REGISTRY_D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                check2(uri.getAuthority(), s, REGISTRY_D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    Test n(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        checked |= PORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (!parsed() || (uri.getPort() != n))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            failed |= PORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    Test p(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (check1(PATH)) check2(uri.getRawPath(), s, PATH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    Test pd(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (check1(PATH_D)) check2(uri.getPath(), s, PATH_D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    Test o(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (check1(OPAQUEPART)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            if (!uri.isOpaque())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                failed |= OPAQUEPART;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                check2(uri.getSchemeSpecificPart(), s, OPAQUEPART);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    Test sp(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if (check1(SSP)) check2(uri.getRawSchemeSpecificPart(), s, SSP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    Test spd(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (check1(SSP_D)) check2(uri.getSchemeSpecificPart(), s, SSP_D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    Test q(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (check1(QUERY)) check2(uri.getRawQuery(), s, QUERY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    Test qd(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (check1(QUERY_D)) check2(uri.getQuery(), s, QUERY_D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    Test f(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (check1(FRAGMENT)) check2(uri.getRawFragment(), s, FRAGMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    Test fd(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if (check1(FRAGMENT_D)) check2(uri.getFragment(), s, FRAGMENT_D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    Test ta(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (check1(TOASCII))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            check2(uri.toASCIIString(), s, TOASCII);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    Test ts(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (check1(TOSTRING))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            check2(uri.toString(), s, TOSTRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    Test x() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        checked |= PARSEFAIL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (parsed())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            failed |= PARSEFAIL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    Test rslv(URI base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (!parsed())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        this.base = base;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        op = "rslv";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        URI u = uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        uri = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            this.uri = base.resolve(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        } catch (IllegalArgumentException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            exc = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        checked = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        failed = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    Test norm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (!parsed())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        op = "norm";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        uri = uri.normalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    Test rtvz(URI base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (!parsed())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        this.base = base;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        op = "rtvz";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        uri = base.relativize(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        checked = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        failed = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    Test psa() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            uri.parseServerAuthority();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            exc = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            uri = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        checked = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        failed = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    private void checkEmpty(String s, int prop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (((checked & prop) == 0) && (s != null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            failed |= prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    // Check identity for the seven-argument URI constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    void checkURI7() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        // Only works on hierarchical URIs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (uri.isOpaque())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        // Only works with server-based authorities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if ((uri.getAuthority() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            != ((uri.getUserInfo() == null) && (uri.getHost() == null)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        // Not true if non-US-ASCII chars are encoded unnecessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        if (uri.getPath().indexOf('\u20AC') >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            URI u2 = new URI(uri.getScheme(), uri.getUserInfo(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                             uri.getHost(), uri.getPort(), uri.getPath(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                             uri.getQuery(), uri.getFragment());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if (!uri.equals(u2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                failed |= IDENT_URI7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            failed |= IDENT_URI7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    // Check identity for the five-argument URI constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    void checkURI5() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        // Only works on hierarchical URIs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        if (uri.isOpaque())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            URI u2 = new URI(uri.getScheme(), uri.getAuthority(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                             uri.getPath(), uri.getQuery(), uri.getFragment());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            if (!uri.equals(u2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                failed |= IDENT_URI5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            failed |= IDENT_URI5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    // Check identity for the three-argument URI constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    void checkURI3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            URI u2 = new URI(uri.getScheme(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                             uri.getSchemeSpecificPart(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                             uri.getFragment());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            if (!uri.equals(u2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                failed |= IDENT_URI3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            failed |= IDENT_URI3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    // Check all identities mentioned in the URI class specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    void checkIdentities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (input != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            if (!uri.toString().equals(input))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                failed |= IDENT_STR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            if (!(new URI(uri.toString())).equals(uri))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                failed |= IDENT_URI1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            failed |= IDENT_URI1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        // Remaining identities fail if "//" given but authority is undefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        if ((uri.getAuthority() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            && (uri.getSchemeSpecificPart() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            && (uri.getSchemeSpecificPart().startsWith("///")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                || uri.getSchemeSpecificPart().startsWith("//?")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                || uri.getSchemeSpecificPart().equals("//")))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        // Remaining identities fail if ":" given but port is undefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if ((uri.getHost() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            && (uri.getAuthority() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            && (uri.getAuthority().equals(uri.getHost() + ":")))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        // Remaining identities fail if non-US-ASCII chars are encoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        // unnecessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        if ((uri.getPath() != null) && uri.getPath().indexOf('\u20AC') >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        checkURI3();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        checkURI5();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        checkURI7();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    // Check identities, check that unchecked component properties are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    // defined, and report any failures
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    Test z() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        if (!parsed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            report();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (op == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            checkIdentities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        // Check that unchecked components are undefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        checkEmpty(uri.getScheme(), SCHEME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        checkEmpty(uri.getUserInfo(), USERINFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        checkEmpty(uri.getHost(), HOST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        if (((checked & PORT) == 0) && (uri.getPort() != -1)) failed |= PORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        checkEmpty(uri.getPath(), PATH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        checkEmpty(uri.getQuery(), QUERY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        checkEmpty(uri.getFragment(), FRAGMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        // Report failures
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        report();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    // Summarization and reporting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    static void header(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        out.println("-- " + s + " --");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    static void show(String prefix, URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        out.println(uquote(x.getInput()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        if (x.getIndex() >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            for (int i = 0; i < x.getIndex(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                if (x.getInput().charAt(i) >= '\u0080')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    out.print("      ");        // Skip over \u1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    out.print(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            out.println("^");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        out.println(prefix + ": " + x.getReason());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    private void summarize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (input.length() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            sb.append("\"\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            sb.append(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if (base != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            sb.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            sb.append(base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        if (!parsed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            String s = (((checked & PARSEFAIL) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                        ? "Correct exception" : "UNEXPECTED EXCEPTION");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            if (exc instanceof URISyntaxException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                show(s, (URISyntaxException)exc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                out.println(uquote(sb.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                out.print(s + ": ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                exc.printStackTrace(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            if (uri != originalURI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                sb.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                sb.append(op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                sb.append(" --> ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                sb.append(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            out.println(uquote(sb.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    public static String uquote(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        if (str == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        int n = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            char c = str.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            if ((c >= ' ') && (c < 0x7f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                sb.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            sb.append("\\u");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            String s = Integer.toHexString(c).toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            while (s.length() < 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                s = "0" + s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            sb.append(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    static void show(String n, String v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        out.println("  " + n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    + "          = ".substring(n.length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    + uquote(v));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    static void show(String n, String v, String vd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        if ((v == null) || v.equals(vd))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            show(n, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            out.println("  " + n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                        + "          = ".substring(n.length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                        + uquote(v)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                        + " = " + uquote(vd));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public static void show(URI u) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        show("opaque", "" + u.isOpaque());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        show("scheme", u.getScheme());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        show("ssp", u.getRawSchemeSpecificPart(), u.getSchemeSpecificPart());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        show("authority", u.getRawAuthority(), u.getAuthority());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        show("userinfo", u.getRawUserInfo(), u.getUserInfo());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        show("host", u.getHost());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        show("port", "" + u.getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        show("path", u.getRawPath(), u.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        show("query", u.getRawQuery(), u.getQuery());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        show("fragment", u.getRawFragment(), u.getFragment());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        if (!u.toString().equals(u.toASCIIString()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            show("toascii", u.toASCIIString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    private void report() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        summarize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        if (failed == 0) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        sb.append("FAIL:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        if ((failed & PARSEFAIL) != 0) sb.append(" parsefail");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        if ((failed & SCHEME) != 0) sb.append(" scheme");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        if ((failed & SSP) != 0) sb.append(" ssp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        if ((failed & OPAQUEPART) != 0) sb.append(" opaquepart");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        if ((failed & USERINFO) != 0) sb.append(" userinfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        if ((failed & USERINFO_D) != 0) sb.append(" userinfod");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if ((failed & HOST) != 0) sb.append(" host");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        if ((failed & PORT) != 0) sb.append(" port");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        if ((failed & REGISTRY) != 0) sb.append(" registry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        if ((failed & PATH) != 0) sb.append(" path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        if ((failed & PATH_D) != 0) sb.append(" pathd");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        if ((failed & QUERY) != 0) sb.append(" query");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        if ((failed & QUERY_D) != 0) sb.append(" queryd");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        if ((failed & FRAGMENT) != 0) sb.append(" fragment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        if ((failed & FRAGMENT_D) != 0) sb.append(" fragmentd");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if ((failed & TOASCII) != 0) sb.append(" toascii");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        if ((failed & IDENT_STR) != 0) sb.append(" ident-str");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        if ((failed & IDENT_URI1) != 0) sb.append(" ident-uri1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        if ((failed & IDENT_URI3) != 0) sb.append(" ident-uri3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        if ((failed & IDENT_URI5) != 0) sb.append(" ident-uri5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        if ((failed & IDENT_URI7) != 0) sb.append(" ident-uri7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        if ((failed & TOSTRING) != 0) sb.append(" tostring");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        out.println(sb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        if (uri != null) show(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        throw new RuntimeException("Test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    // -- Tests --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    static void rfc2396() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        header("RFC2396: Basic examples");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        test("ftp://ftp.is.co.za/rfc/rfc1808.txt")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            .s("ftp").h("ftp.is.co.za").p("/rfc/rfc1808.txt").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        test("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            .s("gopher").h("spinaltap.micro.umn.edu")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            .p("/00/Weather/California/Los%20Angeles").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        test("http://www.math.uio.no/faq/compression-faq/part1.html")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            .s("http").h("www.math.uio.no").p("/faq/compression-faq/part1.html").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        test("mailto:mduerst@ifi.unizh.ch")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            .s("mailto").o("mduerst@ifi.unizh.ch").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        test("news:comp.infosystems.www.servers.unix")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            .s("news").o("comp.infosystems.www.servers.unix").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        test("telnet://melvyl.ucop.edu/")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            .s("telnet").h("melvyl.ucop.edu").p("/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        test("http://www.w3.org/Addressing/")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            .s("http").h("www.w3.org").p("/Addressing/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        test("ftp://ds.internic.net/rfc/")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            .s("ftp").h("ds.internic.net").p("/rfc/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        test("http://www.ics.uci.edu/pub/ietf/uri/historical.html#WARNING")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            .s("http").h("www.ics.uci.edu").p("/pub/ietf/uri/historical.html")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            .f("WARNING").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        test("http://www.ics.uci.edu/pub/ietf/uri/#Related")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            .s("http").h("www.ics.uci.edu").p("/pub/ietf/uri/")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            .f("Related").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        header("RFC2396: Normal relative-URI examples (appendix C)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        URI base = (test("http://a/b/c/d;p?q")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                    .s("http").h("a").p("/b/c/d;p").q("q").z().uri());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        // g:h       g:h
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        test("g:h")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            .s("g").o("h").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            .rslv(base).s("g").o("h").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        // g         http://a/b/c/g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        test("g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            .p("g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            .rslv(base).s("http").h("a").p("/b/c/g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        // ./g       http://a/b/c/g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        test("./g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            .p("./g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            .rslv(base).s("http").h("a").p("/b/c/g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        // g/        http://a/b/c/g/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        test("g/")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            .p("g/").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            .rslv(base).s("http").h("a").p("/b/c/g/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        // /g        http://a/g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        test("/g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            .p("/g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            .rslv(base).s("http").h("a").p("/g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        // //g       http://g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        test("//g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            .h("g").p("").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            .rslv(base).s("http").h("g").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        // ?y        http://a/b/c/?y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        test("?y")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            .p("").q("y").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            .rslv(base).s("http").h("a").p("/b/c/").q("y").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        // g?y       http://a/b/c/g?y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        test("g?y")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            .p("g").q("y").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            .rslv(base).s("http").h("a").p("/b/c/g").q("y").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        // #s        (current document)#s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        // DEVIATION: Lone fragment parses as relative URI with empty path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        test("#s")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            .p("").f("s").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            .rslv(base).s("http").h("a").p("/b/c/d;p").f("s").q("q").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        // g#s       http://a/b/c/g#s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        test("g#s")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            .p("g").f("s").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            .rslv(base).s("http").h("a").p("/b/c/g").f("s").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        // g?y#s     http://a/b/c/g?y#s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        test("g?y#s")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            .p("g").q("y").f("s").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            .rslv(base).s("http").h("a").p("/b/c/g").q("y").f("s").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        // ;x        http://a/b/c/;x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        test(";x")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            .p(";x").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            .rslv(base).s("http").h("a").p("/b/c/;x").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        // g;x       http://a/b/c/g;x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        test("g;x")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            .p("g;x").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            .rslv(base).s("http").h("a").p("/b/c/g;x").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        // g;x?y#s   http://a/b/c/g;x?y#s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        test("g;x?y#s")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            .p("g;x").q("y").f("s").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            .rslv(base).s("http").h("a").p("/b/c/g;x").q("y").f("s").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        // .         http://a/b/c/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        test(".")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            .p(".").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            .rslv(base).s("http").h("a").p("/b/c/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        // ./        http://a/b/c/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        test("./")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            .p("./").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            .rslv(base).s("http").h("a").p("/b/c/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        // ..        http://a/b/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        test("..")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            .p("..").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            .rslv(base).s("http").h("a").p("/b/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        // ../       http://a/b/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        test("../")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            .p("../").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            .rslv(base).s("http").h("a").p("/b/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        // ../g      http://a/b/g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        test("../g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            .p("../g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            .rslv(base).s("http").h("a").p("/b/g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        // ../..     http://a/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        test("../..")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            .p("../..").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            .rslv(base).s("http").h("a").p("/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        // ../../    http://a/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        test("../../")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            .p("../../").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            .rslv(base).s("http").h("a").p("/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        // ../../g   http://a/g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        test("../../g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            .p("../../g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            .rslv(base).s("http").h("a").p("/g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        header("RFC2396: Abnormal relative-URI examples (appendix C)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        // ../../../g    =  http://a/../g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        test("../../../g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            .p("../../../g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            .rslv(base).s("http").h("a").p("/../g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        // ../../../../g =  http://a/../../g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        test("../../../../g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            .p("../../../../g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            .rslv(base).s("http").h("a").p("/../../g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        // /./g          =  http://a/./g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        test("/./g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            .p("/./g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            .rslv(base).s("http").h("a").p("/./g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        // /../g         =  http://a/../g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        test("/../g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            .p("/../g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            .rslv(base).s("http").h("a").p("/../g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        // g.            =  http://a/b/c/g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        test("g.")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            .p("g.").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            .rslv(base).s("http").h("a").p("/b/c/g.").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        // .g            =  http://a/b/c/.g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        test(".g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            .p(".g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            .rslv(base).s("http").h("a").p("/b/c/.g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        // g..           =  http://a/b/c/g..
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        test("g..")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            .p("g..").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            .rslv(base).s("http").h("a").p("/b/c/g..").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        // ..g           =  http://a/b/c/..g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        test("..g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            .p("..g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            .rslv(base).s("http").h("a").p("/b/c/..g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        // ./../g        =  http://a/b/g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        test("./../g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            .p("./../g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            .rslv(base).s("http").h("a").p("/b/g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        // ./g/.         =  http://a/b/c/g/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        test("./g/.")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            .p("./g/.").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            .rslv(base).s("http").h("a").p("/b/c/g/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        // g/./h         =  http://a/b/c/g/h
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        test("g/./h")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            .p("g/./h").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            .rslv(base).s("http").h("a").p("/b/c/g/h").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        // g/../h        =  http://a/b/c/h
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        test("g/../h")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            .p("g/../h").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            .rslv(base).s("http").h("a").p("/b/c/h").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        // g;x=1/./y     =  http://a/b/c/g;x=1/y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        test("g;x=1/./y")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            .p("g;x=1/./y").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            .rslv(base).s("http").h("a").p("/b/c/g;x=1/y").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        // g;x=1/../y    =  http://a/b/c/y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        test("g;x=1/../y")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            .p("g;x=1/../y").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            .rslv(base).s("http").h("a").p("/b/c/y").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        // g?y/./x       =  http://a/b/c/g?y/./x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        test("g?y/./x")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            .p("g").q("y/./x").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            .rslv(base).s("http").h("a").p("/b/c/g").q("y/./x").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        // g?y/../x      =  http://a/b/c/g?y/../x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        test("g?y/../x")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            .p("g").q("y/../x").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            .rslv(base).s("http").h("a").p("/b/c/g").q("y/../x").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        // g#s/./x       =  http://a/b/c/g#s/./x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        test("g#s/./x")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            .p("g").f("s/./x").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            .rslv(base).s("http").h("a").p("/b/c/g").f("s/./x").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        // g#s/../x      =  http://a/b/c/g#s/../x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        test("g#s/../x")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            .p("g").f("s/../x").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            .rslv(base).s("http").h("a").p("/b/c/g").f("s/../x").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        // http:g        =  http:g
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        test("http:g")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            .s("http").o("g").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            .rslv(base).s("http").o("g").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    static void ip() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        header("IP addresses");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        test("http://1.2.3.4:5")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            .s("http").h("1.2.3.4").n(5).p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        // From RFC2732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        test("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            .s("http").h("[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            .n(80).p("/index.html").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        test("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:10%12]:80/index.html")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            .s("http").h("[FEDC:BA98:7654:3210:FEDC:BA98:7654:10%12]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            .n(80).p("/index.html").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        test("http://[1080:0:0:0:8:800:200C:417A]/index.html")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            .s("http").h("[1080:0:0:0:8:800:200C:417A]").p("/index.html").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        test("http://[1080:0:0:0:8:800:200C:417A%1]/index.html")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            .s("http").h("[1080:0:0:0:8:800:200C:417A%1]").p("/index.html").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        test("http://[3ffe:2a00:100:7031::1]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            .s("http").h("[3ffe:2a00:100:7031::1]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        test("http://[1080::8:800:200C:417A]/foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            .s("http").h("[1080::8:800:200C:417A]").p("/foo").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        test("http://[::192.9.5.5]/ipng")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            .s("http").h("[::192.9.5.5]").p("/ipng").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        test("http://[::192.9.5.5%interface]/ipng")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            .s("http").h("[::192.9.5.5%interface]").p("/ipng").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        test("http://[::FFFF:129.144.52.38]:80/index.html")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            .s("http").h("[::FFFF:129.144.52.38]").n(80).p("/index.html").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        test("http://[2010:836B:4179::836B:4179]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            .s("http").h("[2010:836B:4179::836B:4179]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        // From RFC2373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        test("http://[FF01::101]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            .s("http").h("[FF01::101]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        test("http://[::1]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            .s("http").h("[::1]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        test("http://[::]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            .s("http").h("[::]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        test("http://[::%hme0]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            .s("http").h("[::%hme0]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        test("http://[0:0:0:0:0:0:13.1.68.3]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            .s("http").h("[0:0:0:0:0:0:13.1.68.3]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        test("http://[0:0:0:0:0:FFFF:129.144.52.38]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            .s("http").h("[0:0:0:0:0:FFFF:129.144.52.38]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        test("http://[0:0:0:0:0:FFFF:129.144.52.38%33]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            .s("http").h("[0:0:0:0:0:FFFF:129.144.52.38%33]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        test("http://[0:0:0:0:0:ffff:1.2.3.4]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            .s("http").h("[0:0:0:0:0:ffff:1.2.3.4]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        test("http://[::13.1.68.3]")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            .s("http").h("[::13.1.68.3]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        // Optional IPv6 brackets in constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        test("s", null, "1:2:3:4:5:6:7:8", -1, null, null, null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            .s("s").h("[1:2:3:4:5:6:7:8]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        test("s", null, "[1:2:3:4:5:6:7:8]", -1, null, null, null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            .s("s").h("[1:2:3:4:5:6:7:8]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        test("s", null, "[1:2:3:4:5:6:7:8]", -1, null, null, null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            .s("s").h("[1:2:3:4:5:6:7:8]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        test("s", "1:2:3:4:5:6:7:8", null, null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            .s("s").h("[1:2:3:4:5:6:7:8]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        test("s", "1:2:3:4:5:6:7:8%hme0", null, null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            .s("s").h("[1:2:3:4:5:6:7:8%hme0]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        test("s", "1:2:3:4:5:6:7:8%1", null, null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            .s("s").h("[1:2:3:4:5:6:7:8%1]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        test("s", "[1:2:3:4:5:6:7:8]", null, null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            .s("s").h("[1:2:3:4:5:6:7:8]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        test("s", "[1:2:3:4:5:6:7:8]", null, null, null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            .s("s").h("[1:2:3:4:5:6:7:8]").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        test("s", "1:2:3:4:5:6:7:8", null, null, null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            .s("s").g("1:2:3:4:5:6:7:8").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        // Error cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        test("http://[ff01:234/foo").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        test("http://[ff01:234:zzz]/foo").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        test("http://[foo]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        test("http://[]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        test("http://[129.33.44.55]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        test("http://[ff:ee:dd:cc:bb::aa:9:8]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        test("http://[fffff::1]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        test("http://[ff::ee::8]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        test("http://[1:2:3:4::5:6:7:8]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        test("http://[1:2]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        test("http://[1:2:3:4:5:6:7:8:9]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        test("http://[1:2:3:4:5:6:7:8%]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        test("http://[1:2:3:4:5:6:7:8%!/]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        test("http://[::1.2.3.300]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        test("http://1.2.3").psa().x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        test("http://1.2.3.300").psa().x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        test("http://1.2.3.4.5").psa().x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        test("http://[1.2.3.4:5]").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        test("http://1:2:3:4:5:6:7:8").psa().x().z();
8778
f2ef7d12277f 7023363: URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag") should throw URISyntaxException
chegar
parents: 7668
diff changeset
  1054
        test("http://[1.2.3.4]/").x().z();
f2ef7d12277f 7023363: URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag") should throw URISyntaxException
chegar
parents: 7668
diff changeset
  1055
        test("http://[1.2.3.4/").x().z();
f2ef7d12277f 7023363: URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag") should throw URISyntaxException
chegar
parents: 7668
diff changeset
  1056
        test("http://[foo]/").x().z();
f2ef7d12277f 7023363: URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag") should throw URISyntaxException
chegar
parents: 7668
diff changeset
  1057
        test("http://[foo/").x().z();
f2ef7d12277f 7023363: URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag") should throw URISyntaxException
chegar
parents: 7668
diff changeset
  1058
        test("s", "[foo]", "/", null, null).x().z();
f2ef7d12277f 7023363: URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag") should throw URISyntaxException
chegar
parents: 7668
diff changeset
  1059
        test("s", "[foo", "/", null, null).x().z();
f2ef7d12277f 7023363: URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag") should throw URISyntaxException
chegar
parents: 7668
diff changeset
  1060
        test("s", "[::foo", "/", null, null).x().z();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        // Test hostnames that might initially look like IPv4 addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        test("s://1.2.3.com").psa().s("s").h("1.2.3.com").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        test("s://1.2.3.4me.com").psa().s("s").h("1.2.3.4me.com").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        test("s://7up.com").psa().s("s").h("7up.com").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        test("s://7up.com/p").psa().s("s").h("7up.com").p("/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        test("s://7up").psa().s("s").h("7up").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        test("s://7up/p").psa().s("s").h("7up").p("/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        test("s://7up.").psa().s("s").h("7up.").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        test("s://7up./p").psa().s("s").h("7up.").p("/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    static void misc() throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        URI base = new URI("s://h/a/b");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        URI rbase = new URI("a/b/c/d");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        header("Corner cases");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        // The empty URI parses as a relative URI with an empty path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        test("").p("").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            .rslv(base).s("s").h("h").p("/a/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        // Resolving solo queries and fragments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        test("#f").p("").f("f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            .rslv(base).s("s").h("h").p("/a/b").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        test("?q").p("").q("q").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            .rslv(base).s("s").h("h").p("/a/").q("q").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        // Fragment is not part of ssp
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        test("p#f").p("p").f("f").sp("p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        test("s:p#f").s("s").o("p").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        test("p#f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            .rslv(base).s("s").h("h").p("/a/p").f("f").sp("//h/a/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        test("").p("").sp("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
5612
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1102
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        header("Emptiness");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        // Components that may be empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        test("///p").p("/p").z();                 // Authority (w/ path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        test("//@h/p").u("").h("h").p("/p").z();  // User info
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        test("//h:/p").h("h").p("/p").z();        // Port
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        test("//h").h("h").p("").z();             // Path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        test("//h?q").h("h").p("").q("q").z();    // Path (w/query)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        test("//?q").p("").q("q").z();            // Authority (w/query)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        test("//#f").p("").f("f").z();            // Authority (w/fragment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        test("p?#").p("p").q("").f("").z();       // Query & fragment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        // Components that may not be empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        test(":").x().z();              // Scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        test("x:").x().z();             // Hier/opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        test("//").x().z();             // Authority (w/o path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        header("Resolution, normalization, and relativization");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        // Resolving relative paths
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        test("../e/f").p("../e/f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            .rslv(rbase).p("a/b/e/f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        test("../../../../d").p("../../../../d").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            .rslv(rbase).p("../d").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        test("../../../d:e").p("../../../d:e").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            .rslv(rbase).p("./d:e").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        test("../../../d:e/f").p("../../../d:e/f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            .rslv(rbase).p("./d:e/f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        // Normalization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        test("a/./c/../d/f").p("a/./c/../d/f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            .norm().p("a/d/f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        test("http://a/./b/c/../d?q#f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            .s("http").h("a").p("/./b/c/../d").q("q").f("f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            .norm().s("http").h("a").p("/b/d").q("q").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        test("a/../b").p("a/../b").z().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            norm().p("b");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        test("a/../b:c").p("a/../b:c").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            .norm().p("./b:c").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        // Normalization of already normalized URI should yield the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        // same URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        URI u1 = URI.create("s://h/../p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        URI u2 = u1.normalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        eq(u1, u2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        eqeq(u1, u2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        // Relativization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        test("/a/b").p("/a/b").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            .rtvz(new URI("/a")).p("b").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        test("/a/b").p("/a/b").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            .rtvz(new URI("/a/")).p("b").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        test("a/b").p("a/b").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            .rtvz(new URI("a")).p("b").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        test("/a/b").p("/a/b").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            .rtvz(new URI("/a/b")).p("").z();   // Result is empty path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        test("a/../b:c/d").p("a/../b:c/d").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            .rtvz(new URI("./b:c/")).p("d").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        test("http://a/b/d/e?q#f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            .s("http").h("a").p("/b/d/e").q("q").f("f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            .rtvz(new URI("http://a/b/?r#g"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            .p("d/e").q("q").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        // parseServerAuthority
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        test("/a/b").psa().p("/a/b").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        test("s://u@h:1/p")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            .psa().s("s").u("u").h("h").n(1).p("/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        test("s://u@h:-foo/p").s("s").g("u@h:-foo").p("/p").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            .psa().x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        test("s://h:999999999999999999999999").psa().x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        test("s://:/b").psa().x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        header("Constructors and factories");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        test("s", null, null, -1, "p", null, null).x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        test(null, null, null, -1, null, null, null).p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        test(null, null, null, -1, "p", null, null).p("p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        test(null, null, "foo%20bar", -1, null, null, null).x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        test(null, null, "foo", -100, null, null, null).x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        test("s", null, null, -1, "", null, null).x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        test("s", null, null, -1, "/p", null, null).s("s").p("/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        test("s", "u", "h", 10, "/p", "q", "f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            .s("s").u("u").h("h").n(10).p("/p").q("q").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        test("s", "a:b", "/p", "q", "f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            .s("s").g("a:b").p("/p").q("q").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        test("s", "h", "/p", "f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            .s("s").h("h").p("/p").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        test("s", "p", "f").s("s").o("p").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        test("s", "/p", "f").s("s").p("/p").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        testCreate("s://u@h/p?q#f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            .s("s").u("u").h("h").p("/p").q("q").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    static void npes() throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        header("NullPointerException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        URI base = URI.create("mailto:root@foobar.com");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            base.resolve((URI)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            throw new RuntimeException("NullPointerException not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            out.println("resolve((URI)null) -->");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            out.println("Correct exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            base.resolve((String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            throw new RuntimeException("NullPointerException not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            out.println("resolve((String)null) -->");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            out.println("Correct exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            base.relativize((URI)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            throw new RuntimeException("NullPointerException not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            out.println("relativize((String)null) -->");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            out.println("Correct exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        testCount += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    static void chars() throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        header("Escapes and non-US-ASCII characters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        URI uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        // Escape pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        test("%0a%0A%0f%0F%01%09zz")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            .p("%0a%0A%0f%0F%01%09zz").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        test("foo%1").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        test("foo%z").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        test("foo%9z").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        // Escapes not permitted in scheme, host
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        test("s%20t://a").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        test("//a%20b").g("a%20b").p("").z();         // Parses as registry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        // Escapes permitted in opaque part, userInfo, registry, path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        // query, and fragment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        test("//u%20v@a").u("u%20v").h("a").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        test("/p%20q").p("/p%20q").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        test("/p?q%20").p("/p").q("q%20").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        test("/p#%20f").p("/p").f("%20f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        // Non-US-ASCII chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        test("s\u00a7t://a").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        test("//\u00a7/b").g("\u00a7").p("/b").z();     // Parses as registry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        test("//u\u00a7v@a").u("u\u00a7v").h("a").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        test("/p\u00a7q").p("/p\u00a7q").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        test("/p?q\u00a7").p("/p").q("q\u00a7").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        test("/p#\u00a7f").p("/p").f("\u00a7f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        // 4648111 - Escapes quoted by toString after resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        uri = new URI("http://a/b/c/d;p?q");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        test("/p%20p")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            .rslv(uri).s("http").h("a").p("/p%20p").ts("http://a/p%20p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        // 4464135: Forbid unwise characters throughout opaque part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        test("foo:x{bar").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        test("foo:{bar").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        // 4438319: Single-argument constructor requires quotation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        //          preserves escapes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        test("//u%01@h/a/b/%02/c?q%03#f%04")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            .u("u%01").ud("u\1")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            .h("h")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            .p("/a/b/%02/c").pd("/a/b/\2/c")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            .q("q%03").qd("q\3")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            .f("f%04").fd("f\4")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            .z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        test("/a/b c").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        // 4438319: Multi-argument constructors quote illegal chars and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        //          preserve legal non-ASCII chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        // \uA001-\uA009 are visible characters, \u2000 is a space character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        test(null, "u\uA001\1", "h", -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
             "/p% \uA002\2\u2000",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
             "q% \uA003\3\u2000",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
             "f% \uA004\4\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            .u("u\uA001%01").h("h")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            .p("/p%25%20\uA002%02%E2%80%80").pd("/p% \uA002\2\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            .q("q%25%20\uA003%03%E2%80%80").qd("q% \uA003\3\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            .f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        test(null, "g\uA001\1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
             "/p% \uA002\2\u2000",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
             "q% \uA003\3\u2000",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
             "f% \uA004\4\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            .g("g\uA001%01")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            .p("/p%25%20\uA002%02%E2%80%80").pd("/p% \uA002\2\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            .q("q%25%20\uA003%03%E2%80%80").qd("q% \uA003\3\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            .f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        test(null, null, "/p% \uA002\2\u2000", "f% \uA004\4\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            .p("/p%25%20\uA002%02%E2%80%80").pd("/p% \uA002\2\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            .f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        test(null, "/sp% \uA001\1\u2000", "f% \uA004\4\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            .sp("/sp%25%20\uA001%01%E2%80%80").spd("/sp% \uA001\1\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            .p("/sp%25%20\uA001%01%E2%80%80").pd("/sp% \uA001\1\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            .f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        // 4438319: Non-raw accessors decode all escaped octets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        test("/%25%20%E2%82%AC%E2%80%80")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            .p("/%25%20%E2%82%AC%E2%80%80").pd("/% \u20Ac\u2000").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        // 4438319: toASCIIString
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        test("/\uCAFE\uBABE")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            .p("/\uCAFE\uBABE").ta("/%EC%AB%BE%EB%AA%BE").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        // 4991359 and 4866303: bad quoting by defineSchemeSpecificPart()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        URI base = new URI ("http://host/foo%20bar/a/b/c/d");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        test ("resolve")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            .rslv(base).spd("//host/foo bar/a/b/c/resolve")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            .sp("//host/foo%20bar/a/b/c/resolve").s("http")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            .pd("/foo bar/a/b/c/resolve").h("host")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            .p("/foo%20bar/a/b/c/resolve").z();
5612
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1333
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1334
        // 6773270: java.net.URI fails to escape u0000
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1335
        test("s", "a", "/\u0000", null)
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1336
            .s("s").p("/%00").h("a")
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1337
            .ta("s://a/%00").z();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1341
    static void eq0(URI u, URI v) throws URISyntaxException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        if (!u.equals(v))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            throw new RuntimeException("Not equal: " + u + " " + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        int uh = u.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        int vh = v.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        if (uh != vh)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            throw new RuntimeException("Hash codes not equal: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                                       + u + " " + Integer.toHexString(uh) + " "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                                       + v + " " + Integer.toHexString(vh));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        out.println(u + " == " + v
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                    + "  [" + Integer.toHexString(uh) + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1356
    static void cmp0(URI u, URI v, boolean same)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        throws URISyntaxException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        int c = u.compareTo(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        if ((c == 0) != same)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            throw new RuntimeException("Comparison inconsistent: " + u + " " + v
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                                       + " " + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1365
    static void eq(URI u, URI v) throws URISyntaxException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        eq0(u, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        cmp0(u, v, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1370
    static void eqeq(URI u, URI v) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        if (u != v)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            throw new RuntimeException("Not ==: " + u + " " + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1376
    static void ne0(URI u, URI v) throws URISyntaxException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        if (u.equals(v))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            throw new RuntimeException("Equal: " + u + " " + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        out.println(u + " != " + v
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                    + "  [" + Integer.toHexString(u.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                    + " " + Integer.toHexString(v.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                    + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1387
    static void ne(URI u, URI v) throws URISyntaxException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        ne0(u, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        cmp0(u, v, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1392
    static void lt(URI u, URI v) throws URISyntaxException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        ne0(u, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        int c = u.compareTo(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        if (c >= 0) {
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1396
            show(u);
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1397
            show(v);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            throw new RuntimeException("Not less than: " + u + " " + v
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                                       + " " + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        out.println(u + " < " + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    static void lt(String s, String t) throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        lt(new URI(s), new URI(t));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1408
   static void gt(URI u, URI v) throws URISyntaxException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        lt(v, u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    static void eqHashComp() throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        header("Equality, hashing, and comparison");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        URI o = new URI("mailto:foo@bar.com");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        URI r = new URI("reg://some%20registry/b/c/d?q#f");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        URI s = new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?q#f");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        eq(o, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        lt(o, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        lt(s, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        lt(s, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        eq(o, new URI("MaILto:foo@bar.com"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        gt(o, new URI("mailto:foo@bar.COM"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        eq(r, new URI("rEg://some%20registry/b/c/d?q#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        gt(r, new URI("reg://Some%20Registry/b/c/d?q#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        gt(r, new URI("reg://some%20registry/b/c/D?q#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        eq(s, new URI("hTtP://jag:cafebabe@Java.Sun.COM:94/b/c/d?q#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        gt(s, new URI("http://jag:CafeBabe@java.sun.com:94/b/c/d?q#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        lt(s, new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?r#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        lt(s, new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?q#g"));
10422
83581a2cf49d 7041800: URI.equals may incorrectly return true with escaped octets
chegar
parents: 9035
diff changeset
  1432
        eq(new URI("http://host/a%00bcd"), new URI("http://host/a%00bcd"));
83581a2cf49d 7041800: URI.equals may incorrectly return true with escaped octets
chegar
parents: 9035
diff changeset
  1433
        ne(new URI("http://host/a%00bcd"), new URI("http://host/aZ00bcd"));
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1434
        eq0(new URI("http://host/abc%e2def%C3ghi"),
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1435
            new URI("http://host/abc%E2def%c3ghi"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        lt("p", "s:p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        lt("s:p", "T:p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        lt("S:p", "t:p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        lt("s:/p", "s:p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        lt("s:p", "s:q");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        lt("s:p#f", "s:p#g");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        lt("s://u@h:1", "s://v@h:1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        lt("s://u@h:1", "s://u@i:1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        lt("s://u@h:1", "s://v@h:2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        lt("s://a%20b", "s://a%20c");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        lt("s://a%20b", "s://aab");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        lt("s://AA", "s://A_");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        lt("s:/p", "s:/q");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        lt("s:/p?q", "s:/p?r");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        lt("s:/p#f", "s:/p#g");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        lt("s://h", "s://h/p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        lt("s://h/p", "s://h/p?q");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    static void serial(URI u) throws IOException, URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        ObjectOutputStream oo = new ObjectOutputStream(bo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        oo.writeObject(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        oo.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        ObjectInputStream oi = new ObjectInputStream(bi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            Object o = oi.readObject();
15272
b0055428d835 7171415: java.net.URI.equals/hashCode not consistent for some URIs
khazra
parents: 10422
diff changeset
  1471
            eq(u, (URI)o);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        } catch (ClassNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            x.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
            throw new RuntimeException(x.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
    static void serial() throws IOException, URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        header("Serialization");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        serial(URI.create("http://java.sun.com/jdk/1.4?release#beta"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        serial(URI.create("s://h/p").resolve("/long%20path/"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    static void urls() throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        header("URLs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        URI uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        URL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        boolean caught = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        uri = new URI("http://a/p?q#f");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            url = uri.toURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        } catch (MalformedURLException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            throw new RuntimeException(x.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        if (!url.toString().equals("http://a/p?q#f"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            throw new RuntimeException("Incorrect URL: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        out.println(uri + " url --> " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        uri = new URI("a/b");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            out.println(uri + " url --> ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            url = uri.toURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        } catch (IllegalArgumentException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            caught = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            out.println("Correct exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        } catch (MalformedURLException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            caught = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
            throw new RuntimeException("Incorrect exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        if (!caught)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            throw new RuntimeException("Incorrect URL: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        uri = new URI("foo://bar/baz");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        caught = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
            out.println(uri + " url --> ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
            url = uri.toURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        } catch (MalformedURLException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            caught = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
            out.println("Correct exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        } catch (IllegalArgumentException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            caught = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            throw new RuntimeException("Incorrect exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        if (!caught)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
            throw new RuntimeException("Incorrect URL: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        testCount += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
    static void tests() throws IOException, URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        rfc2396();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        ip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        misc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        chars();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        eqHashComp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        serial();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        urls();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        npes();
6307
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1551
        bugs();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    // -- Command-line invocation --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    static void usage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        out.println("Usage:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        out.println("  java Test               --  Runs all tests in this file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        out.println("  java Test <uri>         --  Parses uri, shows components");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
        out.println("  java Test <base> <uri>  --  Parses uri and base, then resolves");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        out.println("                              uri against base");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    static void clargs(String base, String uri) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        URI b = null, u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
            if (base != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                b = new URI(base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                out.println(base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                show(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            u = new URI(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            out.println(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            show(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            if (base != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                URI r = b.resolve(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                out.println(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                show(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            show("ERROR", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
            x.printStackTrace(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
6307
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1588
    // miscellaneous bugs/rfes that don't fit in with the test framework
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1589
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1590
    static void bugs() {
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1591
        // 6339649 - include detail message from nested exception
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1592
        try {
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1593
            URI uri = URI.create("http://nowhere.net/should not be permitted");
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1594
        } catch (IllegalArgumentException e) {
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1595
            if ("".equals(e.getMessage()) || e.getMessage() == null) {
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1596
                throw new RuntimeException ("No detail message");
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1597
            }
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1598
        }
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1599
    }
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1600
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
        switch (args.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
            tests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
            out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            out.println("Test cases: " + testCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
            if (args[0].equals("-help")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            clargs(null, args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            clargs(args[0], args[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
}