test/tools/javac/lambdaShapes/org/openjdk/tests/vm/FDSeparateCompilationTest.java

Mon, 21 Jan 2013 20:15:16 +0000

author
mcimadamore
date
Mon, 21 Jan 2013 20:15:16 +0000
changeset 1512
b12ffdfa1341
parent 1448
7d34e91f66bb
child 1520
5c956be64b9e
permissions
-rw-r--r--

8005851: Remove support for synchronized interface methods
Summary: Synchronized default methods are no longer supported
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 2012, 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.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package org.openjdk.tests.vm;
    28 import java.util.*;
    30 import org.testng.ITestResult;
    31 import org.testng.annotations.Test;
    32 import org.testng.annotations.DataProvider;
    33 import org.testng.annotations.AfterMethod;
    34 import org.testng.annotations.AfterSuite;
    36 import org.openjdk.tests.separate.*;
    37 import org.openjdk.tests.separate.Compiler;
    39 import org.openjdk.tests.shapegen.Hierarchy;
    40 import org.openjdk.tests.shapegen.HierarchyGenerator;
    41 import org.openjdk.tests.shapegen.ClassCase;
    43 import static org.testng.Assert.*;
    44 import static org.openjdk.tests.separate.SourceModel.*;
    45 import static org.openjdk.tests.separate.SourceModel.Class;
    46 import static org.openjdk.tests.separate.SourceModel.Method;
    47 import static org.openjdk.tests.separate.SourceModel.Type;
    49 public class FDSeparateCompilationTest extends TestHarness {
    51     private static String EMPTY = "\"\"";
    53     public FDSeparateCompilationTest() {
    54         super(false, true);
    55     }
    57     @DataProvider(name = "allShapes", parallel = true)
    58     public Object[][] hierarchyGenerator() {
    59         ArrayList<Object[]> allCases = new ArrayList<>();
    61         HierarchyGenerator hg = new HierarchyGenerator();
    62         for (Object x : hg.getOK()) {
    63             allCases.add(new Object[]{x});
    64         }
    65         for (Object x : hg.getErr()) {
    66             allCases.add(new Object[]{x});
    67         }
    68         return allCases.toArray(new Object[0][]);
    69     }
    71     // The expected value obtained when invoking the method from the specified
    72     // class.  If returns null, then an AbstractMethodError is expected.
    73     private static String getExpectedResult(ClassCase cc) {
    74         Set<ClassCase> provs = cc.get_mprov();
    75         if (cc.get_mres() != null) {
    76             return cc.get_mres().getName();
    77         } else if (provs != null && provs.size() == 1) {
    78             ClassCase cand = provs.iterator().next();
    79             switch (cand.kind) {
    80                 case CCONCRETE:
    81                 case IDEFAULT:
    82                     return cand.getName();
    83                 case CNONE:
    84                 case IVAC:
    85                     return getExpectedResult(cand);
    86             }
    87         }
    88         return null;
    89     }
    91     private static final ConcreteMethod canonicalMethod = new ConcreteMethod(
    92             "String", "m", "returns " + EMPTY + ";", AccessFlag.PUBLIC);
    94     @Test(groups = "vm", dataProvider = "allShapes")
    95     public void separateCompilationTest(Hierarchy hs) {
    96         ClassCase cc = hs.root;
    97         Type type = sourceTypeFrom(hs.root);
    99         Class specimen = null;
   100         if (type instanceof Class) {
   101             Class ctype = (Class)type;
   102             if (ctype.isAbstract()) {
   103                 specimen = new Class("Test" + ctype.getName(), ctype);
   104             } else {
   105                 specimen = ctype;
   106             }
   107         } else {
   108             specimen = new Class("Test" + type.getName(), (Interface)type);
   109         }
   111         String value = getExpectedResult(cc);
   112         if (value != null) {
   113             assertInvokeVirtualEquals(value, specimen, canonicalMethod, EMPTY);
   114         } else {
   115             assertThrows(AbstractMethodError.class, specimen,
   116                 canonicalMethod, EMPTY);
   117         }
   118     }
   120     @AfterMethod
   121     public void printCaseError(ITestResult result) {
   122         if (result.getStatus() == ITestResult.FAILURE) {
   123             Hierarchy hs = (Hierarchy)result.getParameters()[0];
   124             System.out.println("Separate compilation case " + hs);
   125             printCaseDetails(hs);
   126         }
   127     }
   129     @AfterSuite
   130     public void cleanupCompilerCache() {
   131         Compiler.purgeCache();
   132     }
   134     private void printCaseDetails(Hierarchy hs) {
   135         String exp = getExpectedResult(hs.root);
   136         for (String s : hs.getDescription()) {
   137              System.out.println("    " + s);
   138         }
   139         if (exp != null) {
   140             System.out.println("    Expected \"" + exp + "\"");
   141         } else {
   142             System.out.println("    Expected AbstractMethodError");
   143         }
   144     }
   146     private Type sourceTypeFrom(ClassCase cc) {
   147         Type type = null;
   149         if (cc.isInterface()) {
   150             Interface iface = new Interface(cc.getName());
   151             for (ClassCase scc : cc.getInterfaces()) {
   152                 Interface supertype = (Interface)sourceTypeFrom(scc);
   153                 iface.addSuperType(supertype);
   154             }
   155             type = iface;
   156         } else {
   157             Class cls = new Class(cc.getName());
   158             if (cc.hasSuperclass()) {
   159                 Class superc = (Class)sourceTypeFrom(cc.getSuperclass());
   160                 cls.setSuperClass(superc);
   161             }
   162             for (ClassCase scc : cc.getInterfaces()) {
   163                 Interface supertype = (Interface)sourceTypeFrom(scc);
   164                 cls.addSuperType(supertype);
   165             }
   166             if (cc.isAbstract()) {
   167                 cls.getAccessFlags().add(AccessFlag.ABSTRACT);
   168             }
   169             type = cls;
   170         }
   171         Method method = methodFrom(cc);
   172         if (method != null) {
   173             type.addMethod(method);
   174         }
   175         return type;
   176     }
   178     private Method methodFrom(ClassCase cc) {
   179         switch (cc.kind) {
   180             case IVAC:
   181             case CNONE: return null;
   182             case IPRESENT:
   183             case CABSTRACT:
   184                 return new AbstractMethod("String", "m", AccessFlag.PUBLIC);
   185             case IDEFAULT:
   186                 return new DefaultMethod(
   187                     "String", "m", "return \"" + cc.getName() + "\";");
   188             case CCONCRETE:
   189                 return new ConcreteMethod(
   190                     "String", "m", "return \"" + cc.getName() + "\";",
   191                     AccessFlag.PUBLIC);
   192             default:
   193                 fail("Unknown method type in class");
   194                 return null;
   195         }
   196     }
   197 }

mercurial