T6411333.java revision 2689:f839b50088bc
1/* 2 * Copyright (c) 2006, 2014, 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/* 25 * @test 26 * @bug 6411333 6400208 6400225 6400267 27 * @summary Ensure 6400208, 6400225, and 6400267 are tested 28 * @author Peter von der Ah\u00e9 29 * @library ../lib 30 * @build ToolTester 31 * @compile T6411333.java 32 * @run main T6411333 33 */ 34 35import java.io.IOException; 36import javax.tools.*; 37import static javax.tools.StandardLocation.*; 38import static javax.tools.JavaFileObject.Kind.*; 39 40// Note: 6400225 (getEffectiveLocation) was dropped eventually. 41 42public class T6411333 extends ToolTester { 43 44 // 6400208: JSR 199: failure mode for inferBinaryName 45 void testInferBinaryName(String binaryName, boolean fail) { 46 try { 47 JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH, 48 binaryName, 49 CLASS); 50 String inferred = fm.inferBinaryName(fail ? CLASS_PATH : PLATFORM_CLASS_PATH, 51 file); 52 if (inferred == null && fail) 53 return; 54 if (!inferred.equals(binaryName)) 55 throw new AssertionError(String.format("binaryName (%s) != inferred (%s)", 56 binaryName, 57 inferred)); 58 } catch (IOException ex) { 59 throw new AssertionError(ex); 60 } 61 } 62 63 // 6400267: JSR 199: specify the exact requirements for relative URIs 64 void testRelativeUri(String name, boolean fail) { 65 try { 66 fm.getFileForInput(SOURCE_OUTPUT, "java.lang", name); 67 } catch (IllegalArgumentException ex) { 68 if (fail) 69 return; 70 } catch (IOException ex) { 71 throw new AssertionError(ex); 72 } 73 if (fail) 74 throw new AssertionError("Expected failure on " + name); 75 } 76 77 void test(String... args) { 78 testInferBinaryName("java.lang.Object", false); 79 testInferBinaryName("java.lang.Object", true); 80 81 testRelativeUri("../util/List.java", true); 82 testRelativeUri("util/List.java", false); 83 testRelativeUri("/util/List.java", true); 84 } 85 86 public static void main(String... args) throws IOException { 87 try (T6411333 t = new T6411333()) { 88 t.test(args); 89 } 90 } 91} 92