test/tools/javac/api/T6501502.java

Tue, 08 Sep 2009 11:12:13 -0700

author
jjg
date
Tue, 08 Sep 2009 11:12:13 -0700
changeset 400
35e29f51a7c3
child 554
9d9f26857129
permissions
-rw-r--r--

6419701: DefaultFileManager clean up: URI.create
6483788: DefaultFileManager.ZipFileObject.toUri() fails to escape space characters
6501502: JSR 199: FileObject.toUri should return file:///c:/ or file:/c:/ not file://c:/
6877206: JavaFileObject.toUri returns bogus URI (win)
6877223: tests @ignored because of issues with File.toURI on Windows
Reviewed-by: mcimadamore, alanb

jjg@400 1 /*
jjg@400 2 * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
jjg@400 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@400 4 *
jjg@400 5 * This code is free software; you can redistribute it and/or modify it
jjg@400 6 * under the terms of the GNU General Public License version 2 only, as
jjg@400 7 * published by the Free Software Foundation.
jjg@400 8 *
jjg@400 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@400 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@400 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@400 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@400 13 * accompanied this code).
jjg@400 14 *
jjg@400 15 * You should have received a copy of the GNU General Public License version
jjg@400 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@400 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@400 18 *
jjg@400 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@400 20 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@400 21 * have any questions.
jjg@400 22 */
jjg@400 23
jjg@400 24 /*
jjg@400 25 * @test
jjg@400 26 * @bug 6501502 6877206 6483788
jjg@400 27 * @summary JSR 199: FileObject.toUri should return file:///c:/ or file:/c:/ not file://c:/
jjg@400 28 */
jjg@400 29
jjg@400 30 import java.io.*;
jjg@400 31 import java.net.URI;
jjg@400 32 import javax.tools.*;
jjg@400 33
jjg@400 34 public class T6501502 {
jjg@400 35 public static void main(String... args) throws Exception {
jjg@400 36 new T6501502().run();
jjg@400 37 }
jjg@400 38
jjg@400 39 // The spec for java.io.File includes the following:
jjg@400 40 // For a given abstract pathname f it is guaranteed that
jjg@400 41 // new File( f.toURI()).equals( f.getAbsoluteFile())
jjg@400 42 // For JavaFileObject we test as follows:
jjg@400 43 // new File( CONVERT_TO_FILEOBJECT(f).toURI()).equals( f.getAbsoluteFile())
jjg@400 44 // to verify that we get reasonable URIs returned from toURI.
jjg@400 45 // To make this a general test, and not just a Windows test,
jjg@400 46 // we test a number of platform-independent paths.
jjg@400 47 void run() throws Exception {
jjg@400 48 JavaCompiler c = ToolProvider.getSystemJavaCompiler();
jjg@400 49 fm = c.getStandardFileManager(null, null, null);
jjg@400 50 System.err.println(System.getProperties());
jjg@400 51 File tmpDir = new File(System.getProperty("java.io.tmpdir"));
jjg@400 52 File testSrcDir = new File(System.getProperty("test.src"));
jjg@400 53 File testClassesDir = new File(System.getProperty("test.classes"));
jjg@400 54 test(new File("abc.tmp"));
jjg@400 55 test(new File(tmpDir, "bad.file"));
jjg@400 56 test(new File(testSrcDir, "T6501501.java"));
jjg@400 57 test(new File(testClassesDir, "T6501501.class"));
jjg@400 58 test(new File("a b"));
jjg@400 59 }
jjg@400 60
jjg@400 61 void test(File f) throws Exception {
jjg@400 62 System.err.println("test " + f);
jjg@400 63 FileObject fo = fm.getJavaFileObjects(f).iterator().next();
jjg@400 64 URI uri = fo.toUri();
jjg@400 65 System.err.println("FileObject uri: " + uri);
jjg@400 66 if (!new File(uri).equals(f.getAbsoluteFile()))
jjg@400 67 throw new Exception("unexpected URI returned");
jjg@400 68 }
jjg@400 69
jjg@400 70 StandardJavaFileManager fm;
jjg@400 71 }
jjg@400 72

mercurial