1/*
2 * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/* @test
25   @bug 4468322
26   @summary Unit test for File.toURI()/File(URI)
27 */
28
29import java.io.*;
30import java.net.URI;
31
32
33public class ToURI {
34
35    static PrintStream log = System.err;
36    static int failures = 0;
37
38    static void go(String fn) throws Exception {
39        File f = new File(fn);
40        log.println();
41        log.println(f);
42        URI u = f.toURI();
43        log.println("  --> " + u);
44        File g = new File(u);
45        log.println("  --> " + g);
46        if (!f.getAbsoluteFile().equals(g)) {
47            log.println("ERROR: Expected " + f + ", got " + g);
48            failures++;
49        }
50    }
51
52    public static void main(String[] args) throws Exception {
53        go("foo");
54        go("foo/bar/baz");
55        go("/cdrom/#2");
56        go("My Computer");
57        go("/tmp");
58        go("/");
59        go("");
60        go("!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`"
61           + "abcdefghijklmnopqrstuvwxyz{|}~\u00D0");
62
63        if (File.separatorChar == '\\') {
64            go("c:");
65            go("c:\\");
66            go("c:\\a\\b");
67            go("\\\\foo");
68            go("\\\\foo\\bar");
69        }
70
71        if (failures > 0)
72            throw new Exception("Tests failed: " + failures);
73
74    }
75
76}
77