test/jdk/java/io/File/Cons.java
author dholmes
Wed, 06 Nov 2019 21:18:42 -0500
changeset 58956 9a0a5e70eeb2
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233454: Test fails with assert(!is_init_completed(), "should only happen during init") after JDK-8229516 Reviewed-by: jiefu, dcubed
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) 1998, 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
   @bug 4131169 4168988
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
   @summary Basic File constructor tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 */
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.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
public class Cons {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private static boolean old = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private static boolean win32 = (File.separatorChar == '\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static String cvt(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        if (s == null) return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        if (win32) return s.replace('/', '\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static String[] slashPerms(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        if (!win32) return new String[] { s };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        if (s == null) return new String[] { s };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        int i = s.indexOf('/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        if (i < 0) return new String[] { s };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        ArrayList a = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        String p1 = s.substring(0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        String[] p2 = slashPerms(s.substring(i + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        for (int j = 0; j < p2.length; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            a.add(p1 + '/' + p2[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        for (int j = 0; j < p2.length; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            a.add(p1 + '\\' + p2[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return (String[])(a.toArray(new String[a.size()]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static class F extends File {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        String exp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        public F(String path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            super(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            this.exp = cons(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        public F(String parent, String child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            super(parent, child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            this.exp = cons(parent, child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        public F(F parent, String child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            super(parent, child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            if (parent == null) this.exp = cons((String)null, child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            else this.exp = cons(parent, child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static String nos(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (s == null) return "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        else return "\"" + s + "\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static void ok(String ans, String exp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        System.err.println(nos(ans) + " <== " + exp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static void err(String ans, String exp, String got) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        System.err.println(nos(ans) + " <-- " + exp + " ==> " + nos(got));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (!debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            throw new Exception("Mismatch: " + exp + " ==> " + nos(got)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                                + ", should be " + nos(ans));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static void ck(String ans, String exp, String got)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if ((got == ans) || ((got != null) && got.equals(ans))) ok(ans, exp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        else err(ans, exp, got);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private static String cons(String arg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return "new File(" + nos(arg) + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private static String cons(String arg1, String arg2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return "new File(" + nos(arg1) + ", " + nos(arg2) + ")";
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 static String cons(F arg1, String arg2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return "new File(" + arg1.exp + ", " + nos(arg2) + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static String op(String exp, String opname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return exp + "." + opname + "()";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private static void ckpnp(F f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                              String parent, String name, String path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        ck(cvt(path), op(f.exp, "getPath"), f.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        ck(cvt(parent), op(f.exp, "getParent"), f.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        ck(cvt(name), op(f.exp, "getName"), f.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private static void ck1(String arg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                            String parent, String name, String path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        String[] parg = slashPerms(arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        for (int i = 0; i < parg.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            ckpnp(new F(parg[i]), parent, name, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private static void ck2(String arg1, String arg2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                            String parent, String name, String path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        String[] parg1 = slashPerms(arg1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        String[] parg2 = slashPerms(arg2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        for (int i = 0; i < parg1.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            for (int j = 0; j < parg2.length; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                ckpnp(new F(parg1[i], parg2[j]), parent, name, path);
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 static void ck2f(String arg1, String arg2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                             String parent, String name, String path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        String[] parg1 = slashPerms(arg1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        String[] parg2 = slashPerms(arg2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        for (int i = 0; i < parg1.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            for (int j = 0; j < parg2.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                F p = (parg1[i] == null) ? null : new F(parg1[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                ckpnp(new F(p, parg2[j]), parent, name, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    static void testBoth() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        /* Null/empty constructor cases */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        ck1("", null, "", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        ck2(null, "", null, "", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        ck2("", "", null, "", "/"); /* ugh */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        ck2f("", "", null, "", "/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (!old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            /* throws NullPointerException */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            ck2f(null, "", null, "", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        /* Separators-in-pathnames cases */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        ck1("/", null, "", "/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        ck2f("/", "", null, "", "/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        /* One-arg constructor cases */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        ck1("foo", null, "foo", "foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        ck1("/foo", "/", "foo", "/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        ck1("/foo/bar", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        ck1("foo/bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (!old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            ck1("foo/", null, "foo", "foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            ck1("/foo/", "/", "foo", "/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            ck1("/foo//", "/", "foo", "/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            ck1("/foo///", "/", "foo", "/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            ck1("/foo//bar", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            ck1("/foo/bar//", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            ck1("foo//bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            ck1("foo/bar/", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            ck1("foo/bar//", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        /* Two-arg constructor cases, string parent */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        ck2("foo", "bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        ck2("foo/", "bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        ck2("/foo", "bar", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        ck2("/foo/", "bar", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (!old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            ck2("foo//", "bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            ck2("foo", "bar/", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            ck2("foo", "bar//", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            ck2("/foo//", "bar", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            ck2("/foo", "bar/", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            ck2("/foo", "bar//", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            ck2("foo", "/bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            ck2("foo", "//bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            ck2("/", "bar", "/", "bar", "/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            ck2("/", "/bar", "/", "bar", "/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        /* Two-arg constructor cases, File parent */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        ck2f("foo", "bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        ck2f("foo/", "bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        ck2f("/foo", "bar", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        ck2f("/foo/", "bar", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (!old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            ck2f("foo//", "bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            ck2f("foo", "bar/", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            ck2f("foo", "bar//", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            ck2f("/foo//", "bar", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            ck2f("/foo", "bar/", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            ck2f("/foo", "bar//", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            ck2f("foo", "/bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            ck2f("foo", "//bar", "foo", "bar", "foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    static void testUnix() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        /* Separators-in-pathnames cases */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (!old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            ck1("//", null, "", "/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        /* One-arg constructor cases */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (!old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            ck1("//foo", "/", "foo", "/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            ck1("///foo", "/", "foo", "/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            ck1("//foo/bar", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        /* Two-arg constructors cases, string parent */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (!old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            ck2("//foo", "bar", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        /* Two-arg constructor cases, File parent */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (!old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            ck2f("//foo", "bar", "/foo", "bar", "/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        File f = new File("/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (! f.isAbsolute()) throw new Exception(f + " should be absolute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        f = new File("foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (f.isAbsolute()) throw new Exception(f + " should not be absolute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    static void testWin32() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (!old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            /* Separators-in-pathnames cases */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            ck1("//", null, "", "//");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            /* One-arg constructor cases */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            ck1("//foo", "//", "foo", "//foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            ck1("///foo", "//", "foo", "//foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            ck1("//foo/bar", "//foo", "bar", "//foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            ck1("z:", null, "", "z:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            ck1("z:/", null, "", "z:/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            ck1("z://", null, "", "z:/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            ck1("z:/foo", "z:/", "foo", "z:/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            ck1("z:/foo/", "z:/", "foo", "z:/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            ck1("/z:/foo", "z:/", "foo", "z:/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            ck1("//z:/foo", "z:/", "foo", "z:/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            ck1("z:/foo/bar", "z:/foo", "bar", "z:/foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            ck1("z:foo", "z:", "foo", "z:foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            /* Two-arg constructors cases, string parent */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            ck2("z:", "/", null, "", "z:/");    /* ## ? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            ck2("z:", "/foo", "z:/", "foo", "z:/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            ck2("z:/", "foo", "z:/", "foo", "z:/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            ck2("z://", "foo", "z:/", "foo", "z:/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            ck2("z:/", "/foo", "z:/", "foo", "z:/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            ck2("z:/", "//foo", "z:/", "foo", "z:/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            ck2("z:/", "foo/", "z:/", "foo", "z:/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            ck2("//foo", "bar", "//foo", "bar", "//foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            /* Two-arg constructor cases, File parent */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            ck2f("//foo", "bar", "//foo", "bar", "//foo/bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        old = new File("foo/").getPath().equals("foo/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (old) System.err.println("** Testing old java.io.File class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        testBoth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (win32) testWin32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        else testUnix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}