Mon, 18 Feb 2013 14:29:40 -0800
8008339: Test TargetAnnoCombo.java is broken
Reviewed-by: jjh
jjg@1401 | 1 | /* |
jjg@1492 | 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
jjg@1401 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@1401 | 4 | * |
jjg@1401 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@1401 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@1401 | 7 | * published by the Free Software Foundation. |
jjg@1401 | 8 | * |
jjg@1401 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@1401 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@1401 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@1401 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@1401 | 13 | * accompanied this code). |
jjg@1401 | 14 | * |
jjg@1401 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@1401 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@1401 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@1401 | 18 | * |
jjg@1401 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@1401 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@1401 | 21 | * questions. |
jjg@1401 | 22 | */ |
jjg@1401 | 23 | |
jjg@1401 | 24 | /** |
jjg@1401 | 25 | * @test |
jjg@1401 | 26 | * @bug 8002157 |
jjg@1401 | 27 | * @author sogoel |
jjg@1401 | 28 | * @summary Positive combo test for use of Inherited on baseAnno/containerAnno |
jjg@1401 | 29 | * @build Helper |
jjg@1401 | 30 | * @compile InheritedAnnoCombo.java |
jjg@1401 | 31 | * @run main InheritedAnnoCombo |
jjg@1401 | 32 | */ |
jjg@1401 | 33 | |
jjg@1401 | 34 | import javax.tools.DiagnosticCollector; |
jjg@1401 | 35 | import javax.tools.JavaFileObject; |
jjg@1401 | 36 | |
jjg@1401 | 37 | /* |
jjg@1401 | 38 | * Generate valid test src for the use of @Inherited on container anno |
jjg@1401 | 39 | * or on both base anno and container anno. Both test src should compile. |
jjg@1401 | 40 | * Repeating annotations used only on class for these generated test src. |
jjg@1401 | 41 | */ |
jjg@1401 | 42 | |
jjg@1401 | 43 | public class InheritedAnnoCombo extends Helper { |
jjg@1401 | 44 | static int errors = 0; |
jjg@1401 | 45 | enum TestCases { |
jjg@1401 | 46 | InheritedonBothAnno(true), |
jjg@1401 | 47 | InheritedonBase(true); |
jjg@1401 | 48 | |
jjg@1401 | 49 | TestCases(boolean compile) { |
jjg@1401 | 50 | this.compile = compile; |
jjg@1401 | 51 | } |
jjg@1401 | 52 | |
jjg@1401 | 53 | boolean compile; |
jjg@1401 | 54 | boolean shouldCompile() { |
jjg@1401 | 55 | return compile; |
jjg@1401 | 56 | } |
jjg@1401 | 57 | } |
jjg@1401 | 58 | |
jjg@1401 | 59 | public static void main(String[] args) throws Exception { |
jjg@1401 | 60 | new InheritedAnnoCombo().runTest(); |
jjg@1401 | 61 | } |
jjg@1401 | 62 | |
jjg@1401 | 63 | public void runTest() throws Exception { |
jjg@1401 | 64 | int testCtr = 0; |
jjg@1401 | 65 | boolean ok = false; |
jjg@1401 | 66 | |
jjg@1401 | 67 | // Create test source content |
jjg@1401 | 68 | for (TestCases className : TestCases.values()) { |
jjg@1401 | 69 | testCtr++; |
jjg@1401 | 70 | String contents = getContent(className.toString()); |
jjg@1401 | 71 | |
jjg@1401 | 72 | // Compile the generated code |
jjg@1401 | 73 | DiagnosticCollector<JavaFileObject> diagnostics = |
jjg@1401 | 74 | new DiagnosticCollector<JavaFileObject>(); |
jjg@1401 | 75 | ok = compileCode(className.toString(), contents, diagnostics); |
jjg@1401 | 76 | |
jjg@1401 | 77 | if (!ok) { |
jjg@1401 | 78 | error("Class="+ className +" did not compile as expected", contents); |
jjg@1401 | 79 | } else { |
jjg@1401 | 80 | System.out.println("Test passed for className: " + className); |
jjg@1401 | 81 | } |
jjg@1401 | 82 | } |
jjg@1401 | 83 | |
jjg@1401 | 84 | System.out.println("Total number of tests run: " + testCtr); |
jjg@1401 | 85 | System.out.println("Total number of errors: " + errors); |
jjg@1401 | 86 | |
jjg@1401 | 87 | if (errors > 0) |
jjg@1401 | 88 | throw new Exception(errors + " errors found"); |
jjg@1401 | 89 | } |
jjg@1401 | 90 | |
jjg@1401 | 91 | private String getContent(String className) { |
jjg@1401 | 92 | |
jjg@1401 | 93 | StringBuilder annoData = new StringBuilder(); |
jjg@1401 | 94 | switch(className) { |
jjg@1401 | 95 | case "InheritedonBothAnno": |
jjg@1401 | 96 | annoData.append(Helper.ContentVars.INHERITED.getVal()) |
jjg@1401 | 97 | .append(Helper.ContentVars.CONTAINER.getVal()) |
jjg@1401 | 98 | .append(Helper.ContentVars.INHERITED.getVal()) |
jjg@1492 | 99 | .append(Helper.ContentVars.REPEATABLE.getVal()) |
jjg@1401 | 100 | .append(Helper.ContentVars.BASE.getVal()); |
jjg@1401 | 101 | break; |
jjg@1401 | 102 | case "InheritedonBase": |
jjg@1401 | 103 | annoData.append(Helper.ContentVars.INHERITED.getVal()) |
jjg@1401 | 104 | .append(Helper.ContentVars.CONTAINER.getVal()) |
jjg@1492 | 105 | .append(Helper.ContentVars.REPEATABLE.getVal()) |
jjg@1401 | 106 | .append(Helper.ContentVars.BASE.getVal()); |
jjg@1401 | 107 | break; |
jjg@1401 | 108 | } |
jjg@1401 | 109 | |
jjg@1401 | 110 | String contents = Helper.ContentVars.IMPORTCONTAINERSTMTS.getVal() |
jjg@1401 | 111 | + Helper.ContentVars.IMPORTINHERITED.getVal() |
jjg@1401 | 112 | + annoData |
jjg@1401 | 113 | + Helper.ContentVars.REPEATABLEANNO.getVal() |
jjg@1401 | 114 | + "\nclass "+ className + "{}"; |
jjg@1401 | 115 | return contents; |
jjg@1401 | 116 | } |
jjg@1401 | 117 | |
jjg@1401 | 118 | private void error(String msg, String... contents) { |
jjg@1401 | 119 | System.out.println("error: " + msg); |
jjg@1401 | 120 | errors++; |
jjg@1401 | 121 | if (contents.length == 1) { |
jjg@1401 | 122 | System.out.println("Contents = " + contents[0]); |
jjg@1401 | 123 | } |
jjg@1401 | 124 | } |
jjg@1401 | 125 | } |
jjg@1401 | 126 |