jdk/test/java/net/URI/Test.java
author michaelm
Tue, 17 Aug 2010 14:49:01 +0100
changeset 6307 613f5033f5f2
parent 5627 e636ac7a63a4
child 7668 d4a77089c587
permissions -rw-r--r--
6339649: URI.create should include a detail message when throwing IllegalArgumentException Summary: create enclosing exception with message of enclosed Reviewed-by: alanb, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2006, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4464135 4505046 4503239 4438319 4991359 4866303
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();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        // Test hostnames that might initially look like IPv4 addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        test("s://1.2.3.com").psa().s("s").h("1.2.3.com").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        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
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        test("s://7up.com").psa().s("s").h("7up.com").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        test("s://7up.com/p").psa().s("s").h("7up.com").p("/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        test("s://7up").psa().s("s").h("7up").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        test("s://7up/p").psa().s("s").h("7up").p("/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        test("s://7up.").psa().s("s").h("7up.").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        test("s://7up./p").psa().s("s").h("7up.").p("/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    static void misc() throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        URI base = new URI("s://h/a/b");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        URI rbase = new URI("a/b/c/d");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        header("Corner cases");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        // The empty URI parses as a relative URI with an empty path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        test("").p("").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            .rslv(base).s("s").h("h").p("/a/").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        // Resolving solo queries and fragments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        test("#f").p("").f("f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            .rslv(base).s("s").h("h").p("/a/b").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        test("?q").p("").q("q").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            .rslv(base).s("s").h("h").p("/a/").q("q").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        // Fragment is not part of ssp
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        test("p#f").p("p").f("f").sp("p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        test("s:p#f").s("s").o("p").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        test("p#f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            .rslv(base).s("s").h("h").p("/a/p").f("f").sp("//h/a/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        test("").p("").sp("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
5612
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1094
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        header("Emptiness");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        // Components that may be empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        test("///p").p("/p").z();                 // Authority (w/ path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        test("//@h/p").u("").h("h").p("/p").z();  // User info
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        test("//h:/p").h("h").p("/p").z();        // Port
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        test("//h").h("h").p("").z();             // Path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        test("//h?q").h("h").p("").q("q").z();    // Path (w/query)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        test("//?q").p("").q("q").z();            // Authority (w/query)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        test("//#f").p("").f("f").z();            // Authority (w/fragment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        test("p?#").p("p").q("").f("").z();       // Query & fragment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        // Components that may not be empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        test(":").x().z();              // Scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        test("x:").x().z();             // Hier/opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        test("//").x().z();             // Authority (w/o path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        header("Resolution, normalization, and relativization");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        // Resolving relative paths
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        test("../e/f").p("../e/f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            .rslv(rbase).p("a/b/e/f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        test("../../../../d").p("../../../../d").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            .rslv(rbase).p("../d").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        test("../../../d:e").p("../../../d:e").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            .rslv(rbase).p("./d:e").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        test("../../../d:e/f").p("../../../d:e/f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            .rslv(rbase).p("./d:e/f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        // Normalization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        test("a/./c/../d/f").p("a/./c/../d/f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            .norm().p("a/d/f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        test("http://a/./b/c/../d?q#f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            .s("http").h("a").p("/./b/c/../d").q("q").f("f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            .norm().s("http").h("a").p("/b/d").q("q").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        test("a/../b").p("a/../b").z().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            norm().p("b");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        test("a/../b:c").p("a/../b:c").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            .norm().p("./b:c").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        // Normalization of already normalized URI should yield the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        // same URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        URI u1 = URI.create("s://h/../p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        URI u2 = u1.normalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        eq(u1, u2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        eqeq(u1, u2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        // Relativization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        test("/a/b").p("/a/b").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            .rtvz(new URI("/a")).p("b").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        test("/a/b").p("/a/b").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            .rtvz(new URI("/a/")).p("b").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        test("a/b").p("a/b").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            .rtvz(new URI("a")).p("b").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        test("/a/b").p("/a/b").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            .rtvz(new URI("/a/b")).p("").z();   // Result is empty path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        test("a/../b:c/d").p("a/../b:c/d").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            .rtvz(new URI("./b:c/")).p("d").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        test("http://a/b/d/e?q#f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            .s("http").h("a").p("/b/d/e").q("q").f("f").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            .rtvz(new URI("http://a/b/?r#g"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            .p("d/e").q("q").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        // parseServerAuthority
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        test("/a/b").psa().p("/a/b").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        test("s://u@h:1/p")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            .psa().s("s").u("u").h("h").n(1).p("/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        test("s://u@h:-foo/p").s("s").g("u@h:-foo").p("/p").z()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            .psa().x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        test("s://h:999999999999999999999999").psa().x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        test("s://:/b").psa().x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        header("Constructors and factories");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        test("s", null, null, -1, "p", null, null).x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        test(null, null, null, -1, null, null, null).p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        test(null, null, null, -1, "p", null, null).p("p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        test(null, null, "foo%20bar", -1, null, null, null).x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        test(null, null, "foo", -100, null, null, null).x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        test("s", null, null, -1, "", null, null).x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        test("s", null, null, -1, "/p", null, null).s("s").p("/p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        test("s", "u", "h", 10, "/p", "q", "f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            .s("s").u("u").h("h").n(10).p("/p").q("q").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        test("s", "a:b", "/p", "q", "f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            .s("s").g("a:b").p("/p").q("q").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        test("s", "h", "/p", "f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            .s("s").h("h").p("/p").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        test("s", "p", "f").s("s").o("p").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        test("s", "/p", "f").s("s").p("/p").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        testCreate("s://u@h/p?q#f")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            .s("s").u("u").h("h").p("/p").q("q").f("f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    static void npes() throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        header("NullPointerException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        URI base = URI.create("mailto:root@foobar.com");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            base.resolve((URI)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            throw new RuntimeException("NullPointerException not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            out.println("resolve((URI)null) -->");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            out.println("Correct exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            base.resolve((String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            throw new RuntimeException("NullPointerException not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            out.println("resolve((String)null) -->");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            out.println("Correct exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            base.relativize((URI)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            throw new RuntimeException("NullPointerException not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            out.println("relativize((String)null) -->");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            out.println("Correct exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        testCount += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    static void chars() throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        header("Escapes and non-US-ASCII characters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        URI uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        // Escape pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        test("%0a%0A%0f%0F%01%09zz")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            .p("%0a%0A%0f%0F%01%09zz").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        test("foo%1").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        test("foo%z").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        test("foo%9z").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        // Escapes not permitted in scheme, host
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        test("s%20t://a").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        test("//a%20b").g("a%20b").p("").z();         // Parses as registry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        // Escapes permitted in opaque part, userInfo, registry, path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        // query, and fragment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        test("//u%20v@a").u("u%20v").h("a").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        test("/p%20q").p("/p%20q").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        test("/p?q%20").p("/p").q("q%20").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        test("/p#%20f").p("/p").f("%20f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        // Non-US-ASCII chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        test("s\u00a7t://a").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        test("//\u00a7/b").g("\u00a7").p("/b").z();     // Parses as registry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        test("//u\u00a7v@a").u("u\u00a7v").h("a").p("").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        test("/p\u00a7q").p("/p\u00a7q").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        test("/p?q\u00a7").p("/p").q("q\u00a7").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        test("/p#\u00a7f").p("/p").f("\u00a7f").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        // 4648111 - Escapes quoted by toString after resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        uri = new URI("http://a/b/c/d;p?q");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        test("/p%20p")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            .rslv(uri).s("http").h("a").p("/p%20p").ts("http://a/p%20p").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        // 4464135: Forbid unwise characters throughout opaque part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        test("foo:x{bar").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        test("foo:{bar").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        // 4438319: Single-argument constructor requires quotation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        //          preserves escapes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        test("//u%01@h/a/b/%02/c?q%03#f%04")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            .u("u%01").ud("u\1")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            .h("h")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            .p("/a/b/%02/c").pd("/a/b/\2/c")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            .q("q%03").qd("q\3")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            .f("f%04").fd("f\4")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            .z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        test("/a/b c").x().z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        // 4438319: Multi-argument constructors quote illegal chars and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        //          preserve legal non-ASCII chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        // \uA001-\uA009 are visible characters, \u2000 is a space character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        test(null, "u\uA001\1", "h", -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
             "/p% \uA002\2\u2000",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
             "q% \uA003\3\u2000",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
             "f% \uA004\4\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            .u("u\uA001%01").h("h")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            .p("/p%25%20\uA002%02%E2%80%80").pd("/p% \uA002\2\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            .q("q%25%20\uA003%03%E2%80%80").qd("q% \uA003\3\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            .f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        test(null, "g\uA001\1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
             "/p% \uA002\2\u2000",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
             "q% \uA003\3\u2000",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
             "f% \uA004\4\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            .g("g\uA001%01")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            .p("/p%25%20\uA002%02%E2%80%80").pd("/p% \uA002\2\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            .q("q%25%20\uA003%03%E2%80%80").qd("q% \uA003\3\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            .f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        test(null, null, "/p% \uA002\2\u2000", "f% \uA004\4\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            .p("/p%25%20\uA002%02%E2%80%80").pd("/p% \uA002\2\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            .f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        test(null, "/sp% \uA001\1\u2000", "f% \uA004\4\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            .sp("/sp%25%20\uA001%01%E2%80%80").spd("/sp% \uA001\1\u2000")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            .p("/sp%25%20\uA001%01%E2%80%80").pd("/sp% \uA001\1\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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        // 4438319: Non-raw accessors decode all escaped octets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        test("/%25%20%E2%82%AC%E2%80%80")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            .p("/%25%20%E2%82%AC%E2%80%80").pd("/% \u20Ac\u2000").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        // 4438319: toASCIIString
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        test("/\uCAFE\uBABE")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            .p("/\uCAFE\uBABE").ta("/%EC%AB%BE%EB%AA%BE").z();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        // 4991359 and 4866303: bad quoting by defineSchemeSpecificPart()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        URI base = new URI ("http://host/foo%20bar/a/b/c/d");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        test ("resolve")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            .rslv(base).spd("//host/foo bar/a/b/c/resolve")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            .sp("//host/foo%20bar/a/b/c/resolve").s("http")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            .pd("/foo bar/a/b/c/resolve").h("host")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            .p("/foo%20bar/a/b/c/resolve").z();
5612
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1325
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1326
        // 6773270: java.net.URI fails to escape u0000
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1327
        test("s", "a", "/\u0000", null)
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1328
            .s("s").p("/%00").h("a")
c0d1673e1ca6 6773270: java.net.URI fails to escape \u0000
michaelm
parents: 2
diff changeset
  1329
            .ta("s://a/%00").z();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    static void eq0(Comparable u, Comparable v) throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        if (!u.equals(v))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            throw new RuntimeException("Not equal: " + u + " " + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        int uh = u.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        int vh = v.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        if (uh != vh)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            throw new RuntimeException("Hash codes not equal: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                                       + u + " " + Integer.toHexString(uh) + " "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                                       + v + " " + Integer.toHexString(vh));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        out.println(u + " == " + v
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                    + "  [" + Integer.toHexString(uh) + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    static void cmp0(Comparable u, Comparable v, boolean same)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        throws URISyntaxException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        int c = u.compareTo(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        if ((c == 0) != same)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            throw new RuntimeException("Comparison inconsistent: " + u + " " + v
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                                       + " " + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    static void eq(Comparable u, Comparable v) throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        eq0(u, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        cmp0(u, v, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
    static void eqeq(Comparable u, Comparable v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        if (u != v)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            throw new RuntimeException("Not ==: " + u + " " + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    static void ne0(Comparable u, Comparable v) throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        if (u.equals(v))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            throw new RuntimeException("Equal: " + u + " " + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        out.println(u + " != " + v
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                    + "  [" + Integer.toHexString(u.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                    + " " + Integer.toHexString(v.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                    + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    static void ne(Comparable u, Comparable v) throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        ne0(u, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        cmp0(u, v, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    static void lt(Comparable u, Comparable v) throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        ne0(u, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        int c = u.compareTo(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        if (c >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            show((URI)u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            show((URI)v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            throw new RuntimeException("Not less than: " + u + " " + v
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                                       + " " + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        out.println(u + " < " + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
    static void lt(String s, String t) throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        lt(new URI(s), new URI(t));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    static void gt(Comparable u, Comparable v) throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        lt(v, u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    static void eqHashComp() throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        header("Equality, hashing, and comparison");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
        URI o = new URI("mailto:foo@bar.com");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        URI r = new URI("reg://some%20registry/b/c/d?q#f");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        URI s = new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?q#f");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        eq(o, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        lt(o, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        lt(s, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        lt(s, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        eq(o, new URI("MaILto:foo@bar.com"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        gt(o, new URI("mailto:foo@bar.COM"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        eq(r, new URI("rEg://some%20registry/b/c/d?q#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        gt(r, new URI("reg://Some%20Registry/b/c/d?q#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        gt(r, new URI("reg://some%20registry/b/c/D?q#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        eq(s, new URI("hTtP://jag:cafebabe@Java.Sun.COM:94/b/c/d?q#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        gt(s, new URI("http://jag:CafeBabe@java.sun.com:94/b/c/d?q#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        lt(s, new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?r#f"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        lt(s, new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?q#g"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        lt("p", "s:p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        lt("s:p", "T:p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        lt("S:p", "t:p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        lt("s:/p", "s:p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        lt("s:p", "s:q");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        lt("s:p#f", "s:p#g");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        lt("s://u@h:1", "s://v@h:1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        lt("s://u@h:1", "s://u@i:1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        lt("s://u@h:1", "s://v@h:2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        lt("s://a%20b", "s://a%20c");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        lt("s://a%20b", "s://aab");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        lt("s://AA", "s://A_");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        lt("s:/p", "s:/q");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        lt("s:/p?q", "s:/p?r");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        lt("s:/p#f", "s:/p#g");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        lt("s://h", "s://h/p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        lt("s://h/p", "s://h/p?q");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    static void serial(URI u) throws IOException, URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        ObjectOutputStream oo = new ObjectOutputStream(bo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        oo.writeObject(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        oo.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        ObjectInputStream oi = new ObjectInputStream(bi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            Object o = oi.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            eq(u, (Comparable)o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        } catch (ClassNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            x.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            throw new RuntimeException(x.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    static void serial() throws IOException, URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        header("Serialization");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        serial(URI.create("http://java.sun.com/jdk/1.4?release#beta"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        serial(URI.create("s://h/p").resolve("/long%20path/"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
    static void urls() throws URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        header("URLs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        URI uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        URL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        boolean caught = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        uri = new URI("http://a/p?q#f");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            url = uri.toURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        } catch (MalformedURLException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            throw new RuntimeException(x.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        if (!url.toString().equals("http://a/p?q#f"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            throw new RuntimeException("Incorrect URL: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        out.println(uri + " url --> " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        uri = new URI("a/b");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            out.println(uri + " url --> ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            url = uri.toURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        } catch (IllegalArgumentException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            caught = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            out.println("Correct exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        } catch (MalformedURLException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            caught = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            throw new RuntimeException("Incorrect exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        if (!caught)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            throw new RuntimeException("Incorrect URL: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
        uri = new URI("foo://bar/baz");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        caught = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            out.println(uri + " url --> ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            url = uri.toURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        } catch (MalformedURLException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
            caught = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            out.println("Correct exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        } catch (IllegalArgumentException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            caught = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            throw new RuntimeException("Incorrect exception: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        if (!caught)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            throw new RuntimeException("Incorrect URL: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        testCount += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    static void tests() throws IOException, URISyntaxException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        rfc2396();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        ip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        misc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        chars();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        eqHashComp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        serial();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        urls();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        npes();
6307
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1539
        bugs();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    // -- Command-line invocation --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
    static void usage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        out.println("Usage:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        out.println("  java Test               --  Runs all tests in this file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        out.println("  java Test <uri>         --  Parses uri, shows components");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        out.println("  java Test <base> <uri>  --  Parses uri and base, then resolves");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        out.println("                              uri against base");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    static void clargs(String base, String uri) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        URI b = null, u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
            if (base != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                b = new URI(base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                out.println(base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                show(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            u = new URI(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            out.println(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            show(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            if (base != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                URI r = b.resolve(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                out.println(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                show(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
        } catch (URISyntaxException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
            show("ERROR", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
            x.printStackTrace(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
6307
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1576
    // 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
  1577
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1578
    static void bugs() {
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1579
        // 6339649 - include detail message from nested exception
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1580
        try {
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1581
            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
  1582
        } catch (IllegalArgumentException e) {
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1583
            if ("".equals(e.getMessage()) || e.getMessage() == null) {
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1584
                throw new RuntimeException ("No detail message");
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1585
            }
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
    }
613f5033f5f2 6339649: URI.create should include a detail message when throwing IllegalArgumentException
michaelm
parents: 5627
diff changeset
  1588
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
        switch (args.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
            tests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
            out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
            out.println("Test cases: " + testCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
            if (args[0].equals("-help")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
            clargs(null, args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            clargs(args[0], args[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
}