T6411333.java revision 2689:f839b50088bc
167468Snon/*
267468Snon * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
367468Snon * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
467468Snon *
567468Snon * This code is free software; you can redistribute it and/or modify it
667468Snon * under the terms of the GNU General Public License version 2 only, as
767468Snon * published by the Free Software Foundation.
867468Snon *
967468Snon * This code is distributed in the hope that it will be useful, but WITHOUT
1067468Snon * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1167468Snon * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1267468Snon * version 2 for more details (a copy is included in the LICENSE file that
1367468Snon * accompanied this code).
1467468Snon *
1567468Snon * You should have received a copy of the GNU General Public License version
1667468Snon * 2 along with this work; if not, write to the Free Software Foundation,
1767468Snon * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1867468Snon *
1967468Snon * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2067468Snon * or visit www.oracle.com if you need additional information or have any
2167468Snon * questions.
2267468Snon */
2367468Snon
2467468Snon/*
2567468Snon * @test
2667468Snon * @bug     6411333 6400208 6400225 6400267
2767468Snon * @summary Ensure 6400208, 6400225, and 6400267 are tested
2867468Snon * @author  Peter von der Ah\u00e9
2967468Snon * @library ../lib
3067468Snon * @build ToolTester
3167468Snon * @compile T6411333.java
3267468Snon * @run main T6411333
3367468Snon */
3467468Snon
3567468Snonimport java.io.IOException;
3667468Snonimport javax.tools.*;
3767468Snonimport static javax.tools.StandardLocation.*;
3867468Snonimport static javax.tools.JavaFileObject.Kind.*;
3967468Snon
4067468Snon// Note: 6400225 (getEffectiveLocation) was dropped eventually.
4167468Snon
4267468Snonpublic class T6411333 extends ToolTester {
4367468Snon
4467468Snon    // 6400208: JSR 199: failure mode for inferBinaryName
4567468Snon    void testInferBinaryName(String binaryName, boolean fail) {
4667468Snon        try {
4767468Snon            JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH,
4867468Snon                                                         binaryName,
4967468Snon                                                         CLASS);
5067468Snon            String inferred = fm.inferBinaryName(fail ? CLASS_PATH : PLATFORM_CLASS_PATH,
5167468Snon                                                 file);
5267468Snon            if (inferred == null && fail)
5367468Snon                return;
5467468Snon            if (!inferred.equals(binaryName))
5567468Snon                throw new AssertionError(String.format("binaryName (%s) != inferred (%s)",
5667468Snon                                                       binaryName,
5767468Snon                                                       inferred));
5867468Snon        } catch (IOException ex) {
5967468Snon            throw new AssertionError(ex);
6067468Snon        }
6167468Snon    }
6267468Snon
6367468Snon    // 6400267: JSR 199: specify the exact requirements for relative URIs
6467468Snon    void testRelativeUri(String name, boolean fail) {
6567468Snon        try {
6667468Snon            fm.getFileForInput(SOURCE_OUTPUT, "java.lang", name);
6767468Snon        } catch (IllegalArgumentException ex) {
6867468Snon            if (fail)
6967468Snon                return;
7067468Snon        } catch (IOException ex) {
7167468Snon            throw new AssertionError(ex);
7267468Snon        }
7367468Snon        if (fail)
7467468Snon            throw new AssertionError("Expected failure on " + name);
7567468Snon    }
7667468Snon
7767468Snon    void test(String... args) {
7867468Snon        testInferBinaryName("java.lang.Object", false);
7967468Snon        testInferBinaryName("java.lang.Object", true);
8067468Snon
8167468Snon        testRelativeUri("../util/List.java", true);
8267468Snon        testRelativeUri("util/List.java", false);
8367468Snon        testRelativeUri("/util/List.java", true);
8467468Snon    }
8567468Snon
8670834Swollman    public static void main(String... args) throws IOException {
8767468Snon        try (T6411333 t = new T6411333()) {
8870834Swollman            t.test(args);
8967468Snon        }
9067468Snon    }
9167468Snon}
9267848Snon