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