Tue, 20 Nov 2012 09:58:55 -0800
8003639: convert lambda testng tests to jtreg and add them
Reviewed-by: mcimadamore
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package org.openjdk.tests.shapegen; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.util.ArrayList; |
aoqi@0 | 29 | import java.util.List; |
aoqi@0 | 30 | import java.util.HashMap; |
aoqi@0 | 31 | import java.util.HashSet; |
aoqi@0 | 32 | import java.util.Map; |
aoqi@0 | 33 | import java.util.Set; |
aoqi@0 | 34 | |
aoqi@0 | 35 | import static org.openjdk.tests.shapegen.ClassCase.Kind.*; |
aoqi@0 | 36 | |
aoqi@0 | 37 | /** |
aoqi@0 | 38 | * |
aoqi@0 | 39 | * @author Robert Field |
aoqi@0 | 40 | */ |
aoqi@0 | 41 | public class Hierarchy { |
aoqi@0 | 42 | |
aoqi@0 | 43 | public final ClassCase root; |
aoqi@0 | 44 | public final Set<ClassCase> all; |
aoqi@0 | 45 | |
aoqi@0 | 46 | public Hierarchy(ClassCase root) { |
aoqi@0 | 47 | this.root = root; |
aoqi@0 | 48 | root.init(new HashMap<String,Integer>()); |
aoqi@0 | 49 | Set<ClassCase> allClasses = new HashSet<>(); |
aoqi@0 | 50 | root.collectClasses(allClasses); |
aoqi@0 | 51 | this.all = allClasses; |
aoqi@0 | 52 | } |
aoqi@0 | 53 | |
aoqi@0 | 54 | public boolean anyDefaults() { |
aoqi@0 | 55 | for (ClassCase cc : all) { |
aoqi@0 | 56 | if (cc.kind == IDEFAULT) { |
aoqi@0 | 57 | return true; |
aoqi@0 | 58 | } |
aoqi@0 | 59 | } |
aoqi@0 | 60 | return false; |
aoqi@0 | 61 | } |
aoqi@0 | 62 | |
aoqi@0 | 63 | public boolean get_OK() { |
aoqi@0 | 64 | return root.get_OK(); |
aoqi@0 | 65 | } |
aoqi@0 | 66 | |
aoqi@0 | 67 | public String testName() { |
aoqi@0 | 68 | return root + "Test"; |
aoqi@0 | 69 | } |
aoqi@0 | 70 | |
aoqi@0 | 71 | private static void genInterfaceList(StringBuilder buf, String prefix, List<ClassCase> interfaces) { |
aoqi@0 | 72 | if (!interfaces.isEmpty()) { |
aoqi@0 | 73 | buf.append(" "); |
aoqi@0 | 74 | buf.append(prefix); |
aoqi@0 | 75 | buf.append(" "); |
aoqi@0 | 76 | buf.append(interfaces.get(0)); |
aoqi@0 | 77 | for (int i = 1; i < interfaces.size(); ++i) { |
aoqi@0 | 78 | buf.append(", " + interfaces.get(i)); |
aoqi@0 | 79 | } |
aoqi@0 | 80 | } |
aoqi@0 | 81 | } |
aoqi@0 | 82 | |
aoqi@0 | 83 | public static void genClassDef(StringBuilder buf, ClassCase cc, String implClass, List<ClassCase> defaultRef) { |
aoqi@0 | 84 | if (cc.isInterface()) { |
aoqi@0 | 85 | buf.append("interface "); |
aoqi@0 | 86 | buf.append(cc.getName() + " "); |
aoqi@0 | 87 | genInterfaceList(buf, "extends", cc.getInterfaces()); |
aoqi@0 | 88 | buf.append(" {\n"); |
aoqi@0 | 89 | |
aoqi@0 | 90 | switch (cc.kind) { |
aoqi@0 | 91 | case IDEFAULT: |
aoqi@0 | 92 | buf.append(" default String m() { return \"\"; }\n"); |
aoqi@0 | 93 | defaultRef.add(cc); |
aoqi@0 | 94 | break; |
aoqi@0 | 95 | case IPRESENT: |
aoqi@0 | 96 | buf.append(" String m();\n"); |
aoqi@0 | 97 | break; |
aoqi@0 | 98 | case IVAC: |
aoqi@0 | 99 | break; |
aoqi@0 | 100 | default: |
aoqi@0 | 101 | throw new AssertionError("Unexpected kind"); |
aoqi@0 | 102 | } |
aoqi@0 | 103 | buf.append("}\n\n"); |
aoqi@0 | 104 | } else { |
aoqi@0 | 105 | buf.append((cc.isAbstract()? "abstract " : "")); |
aoqi@0 | 106 | buf.append(" class " + cc.getName()); |
aoqi@0 | 107 | if (cc.getSuperclass() != null) { |
aoqi@0 | 108 | buf.append(" extends " + cc.getSuperclass()); |
aoqi@0 | 109 | } |
aoqi@0 | 110 | |
aoqi@0 | 111 | genInterfaceList(buf, "implements", cc.getInterfaces()); |
aoqi@0 | 112 | buf.append(" {\n"); |
aoqi@0 | 113 | |
aoqi@0 | 114 | switch (cc.kind) { |
aoqi@0 | 115 | case CCONCRETE: |
aoqi@0 | 116 | buf.append(" public String m() { return \"\"; }\n"); |
aoqi@0 | 117 | break; |
aoqi@0 | 118 | case CABSTRACT: |
aoqi@0 | 119 | buf.append(" public abstract String m();\n"); |
aoqi@0 | 120 | break; |
aoqi@0 | 121 | case CNONE: |
aoqi@0 | 122 | break; |
aoqi@0 | 123 | default: |
aoqi@0 | 124 | throw new AssertionError("Unexpected kind"); |
aoqi@0 | 125 | } |
aoqi@0 | 126 | buf.append("}\n\n"); |
aoqi@0 | 127 | } |
aoqi@0 | 128 | } |
aoqi@0 | 129 | |
aoqi@0 | 130 | @Override |
aoqi@0 | 131 | public boolean equals(Object obj) { |
aoqi@0 | 132 | return obj instanceof Hierarchy && root.getID().equals(((Hierarchy)obj).root.getID()); |
aoqi@0 | 133 | } |
aoqi@0 | 134 | |
aoqi@0 | 135 | @Override |
aoqi@0 | 136 | public int hashCode() { |
aoqi@0 | 137 | return root.getID().hashCode(); |
aoqi@0 | 138 | } |
aoqi@0 | 139 | |
aoqi@0 | 140 | @Override |
aoqi@0 | 141 | public String toString() { |
aoqi@0 | 142 | return root.getName(); |
aoqi@0 | 143 | } |
aoqi@0 | 144 | |
aoqi@0 | 145 | private static String classNames[] = { |
aoqi@0 | 146 | "C", "D", "E", "F", "G", "H", "S", "T", "U", "V" |
aoqi@0 | 147 | }; |
aoqi@0 | 148 | |
aoqi@0 | 149 | private static String interfaceNames[] = { |
aoqi@0 | 150 | "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R" |
aoqi@0 | 151 | }; |
aoqi@0 | 152 | |
aoqi@0 | 153 | private static int CLASS_INDEX = 0; |
aoqi@0 | 154 | private static int INTERFACE_INDEX = 1; |
aoqi@0 | 155 | private static int NUM_INDICIES = 2; |
aoqi@0 | 156 | |
aoqi@0 | 157 | public List<String> getDescription() { |
aoqi@0 | 158 | Map<ClassCase,String> nameMap = new HashMap<>(); |
aoqi@0 | 159 | assignNames(root, new int[NUM_INDICIES], nameMap); |
aoqi@0 | 160 | |
aoqi@0 | 161 | ArrayList<String> res = new ArrayList<>(); |
aoqi@0 | 162 | if (root.getSupertypes().size() == 0) { |
aoqi@0 | 163 | res.add(nameMap.get(root) + root.kind.getPrefix() + "()"); |
aoqi@0 | 164 | } else { |
aoqi@0 | 165 | genCaseDescription(root, res, new HashSet<ClassCase>(), nameMap); |
aoqi@0 | 166 | } |
aoqi@0 | 167 | return res; |
aoqi@0 | 168 | } |
aoqi@0 | 169 | |
aoqi@0 | 170 | private static void assignNames( |
aoqi@0 | 171 | ClassCase cc, int indices[], Map<ClassCase,String> names) { |
aoqi@0 | 172 | String name = names.get(cc); |
aoqi@0 | 173 | if (name == null) { |
aoqi@0 | 174 | if (cc.isInterface()) { |
aoqi@0 | 175 | names.put(cc, interfaceNames[indices[INTERFACE_INDEX]++]); |
aoqi@0 | 176 | } else { |
aoqi@0 | 177 | names.put(cc, classNames[indices[CLASS_INDEX]++]); |
aoqi@0 | 178 | } |
aoqi@0 | 179 | for (int i = 0; i < cc.getSupertypes().size(); ++i) { |
aoqi@0 | 180 | assignNames(cc.getSupertypes().get(i), indices, names); |
aoqi@0 | 181 | } |
aoqi@0 | 182 | } |
aoqi@0 | 183 | } |
aoqi@0 | 184 | |
aoqi@0 | 185 | private static void genCaseDescription( |
aoqi@0 | 186 | ClassCase cc, List<String> res, Set<ClassCase> alreadyDone, |
aoqi@0 | 187 | Map<ClassCase,String> nameMap) { |
aoqi@0 | 188 | if (!alreadyDone.contains(cc)) { |
aoqi@0 | 189 | if (cc.getSupertypes().size() > 0) { |
aoqi@0 | 190 | StringBuilder sb = new StringBuilder(); |
aoqi@0 | 191 | sb.append(nameMap.get(cc)); |
aoqi@0 | 192 | sb.append(cc.kind.getPrefix()); |
aoqi@0 | 193 | sb.append("("); |
aoqi@0 | 194 | for (int i = 0; i < cc.getSupertypes().size(); ++i) { |
aoqi@0 | 195 | ClassCase supertype = cc.getSupertypes().get(i); |
aoqi@0 | 196 | if (i != 0) { |
aoqi@0 | 197 | sb.append(","); |
aoqi@0 | 198 | } |
aoqi@0 | 199 | genCaseDescription(supertype, res, alreadyDone, nameMap); |
aoqi@0 | 200 | sb.append(nameMap.get(supertype)); |
aoqi@0 | 201 | sb.append(supertype.kind.getPrefix()); |
aoqi@0 | 202 | } |
aoqi@0 | 203 | sb.append(")"); |
aoqi@0 | 204 | res.add(sb.toString()); |
aoqi@0 | 205 | } |
aoqi@0 | 206 | } |
aoqi@0 | 207 | alreadyDone.add(cc); |
aoqi@0 | 208 | } |
aoqi@0 | 209 | } |