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 org.openjdk.tests.shapegen.ClassCase.Kind; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import java.util.Collection; |
aoqi@0 | 31 | import java.util.Set; |
aoqi@0 | 32 | import java.util.HashSet; |
aoqi@0 | 33 | import java.util.Collections; |
aoqi@0 | 34 | import java.util.ArrayList; |
aoqi@0 | 35 | import java.util.List; |
aoqi@0 | 36 | |
aoqi@0 | 37 | import static org.openjdk.tests.shapegen.ClassCase.Kind.*; |
aoqi@0 | 38 | |
aoqi@0 | 39 | import static java.lang.Math.pow; |
aoqi@0 | 40 | |
aoqi@0 | 41 | /** |
aoqi@0 | 42 | * |
aoqi@0 | 43 | * @author Robert Field |
aoqi@0 | 44 | */ |
aoqi@0 | 45 | public final class HierarchyGenerator { |
aoqi@0 | 46 | |
aoqi@0 | 47 | private int okcnt = 0; |
aoqi@0 | 48 | private int errcnt = 0; |
aoqi@0 | 49 | private Set<Hierarchy> uniqueOK = new HashSet<>(); |
aoqi@0 | 50 | private Set<Hierarchy> uniqueErr = new HashSet<>(); |
aoqi@0 | 51 | |
aoqi@0 | 52 | /** |
aoqi@0 | 53 | * @param args the command line arguments |
aoqi@0 | 54 | */ |
aoqi@0 | 55 | public HierarchyGenerator() { |
aoqi@0 | 56 | organize("exhaustive interface", iExhaustive(2)); |
aoqi@0 | 57 | organize("exhaustive class", cExhaustive()); |
aoqi@0 | 58 | organize("shapes interface", iShapes()); |
aoqi@0 | 59 | organize("shapes class/interface", ciShapes()); |
aoqi@0 | 60 | |
aoqi@0 | 61 | System.out.printf("\nExpect OK: %d -- unique %d", okcnt, uniqueOK.size()); |
aoqi@0 | 62 | System.out.printf("\nExpect Error: %d -- unique %d\n", errcnt, uniqueErr.size()); |
aoqi@0 | 63 | } |
aoqi@0 | 64 | |
aoqi@0 | 65 | public Collection<Hierarchy> getOK() { |
aoqi@0 | 66 | return uniqueOK; |
aoqi@0 | 67 | } |
aoqi@0 | 68 | |
aoqi@0 | 69 | public Collection<Hierarchy> getErr() { |
aoqi@0 | 70 | return uniqueErr; |
aoqi@0 | 71 | } |
aoqi@0 | 72 | |
aoqi@0 | 73 | private void organize(String tname, List<Hierarchy> totest) { |
aoqi@0 | 74 | System.out.printf("\nGenerating %s....\n", tname); |
aoqi@0 | 75 | int nodefault = 0; |
aoqi@0 | 76 | List<Hierarchy> ok = new ArrayList<>(); |
aoqi@0 | 77 | List<Hierarchy> err = new ArrayList<>(); |
aoqi@0 | 78 | for (Hierarchy cc : totest) { |
aoqi@0 | 79 | if (cc.anyDefaults()) { |
aoqi@0 | 80 | //System.out.printf(" %s\n", cc); |
aoqi@0 | 81 | if (cc.get_OK()) { |
aoqi@0 | 82 | ok.add(cc); |
aoqi@0 | 83 | } else { |
aoqi@0 | 84 | err.add(cc); |
aoqi@0 | 85 | } |
aoqi@0 | 86 | } else { |
aoqi@0 | 87 | ++nodefault; |
aoqi@0 | 88 | } |
aoqi@0 | 89 | } |
aoqi@0 | 90 | |
aoqi@0 | 91 | errcnt += err.size(); |
aoqi@0 | 92 | okcnt += ok.size(); |
aoqi@0 | 93 | uniqueErr.addAll(err); |
aoqi@0 | 94 | uniqueOK.addAll(ok); |
aoqi@0 | 95 | |
aoqi@0 | 96 | System.out.printf(" %5d No default\n %5d Error\n %5d OK\n %5d Total\n", |
aoqi@0 | 97 | nodefault, err.size(), ok.size(), totest.size()); |
aoqi@0 | 98 | } |
aoqi@0 | 99 | |
aoqi@0 | 100 | public List<Hierarchy> iExhaustive(int idepth) { |
aoqi@0 | 101 | List<ClassCase> current = new ArrayList<>(); |
aoqi@0 | 102 | for (int i = 0; i < idepth; ++i) { |
aoqi@0 | 103 | current = ilayer(current); |
aoqi@0 | 104 | } |
aoqi@0 | 105 | return wrapInClassAndHierarchy(current); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | private List<ClassCase> ilayer(List<ClassCase> srcLayer) { |
aoqi@0 | 109 | List<ClassCase> lay = new ArrayList<>(); |
aoqi@0 | 110 | for (int i = (int) pow(2, srcLayer.size()) - 1; i >= 0; --i) { |
aoqi@0 | 111 | List<ClassCase> itfs = new ArrayList<>(); |
aoqi@0 | 112 | for (int b = srcLayer.size() - 1; b >= 0; --b) { |
aoqi@0 | 113 | if ((i & (1<<b)) != 0) { |
aoqi@0 | 114 | itfs.add(srcLayer.get(b)); |
aoqi@0 | 115 | } |
aoqi@0 | 116 | } |
aoqi@0 | 117 | lay.add(new ClassCase(IVAC, null, itfs)); |
aoqi@0 | 118 | lay.add(new ClassCase(IPRESENT, null, itfs)); |
aoqi@0 | 119 | lay.add(new ClassCase(IDEFAULT, null, itfs)); |
aoqi@0 | 120 | lay.add(new ClassCase(IDEFAULT, null, itfs)); |
aoqi@0 | 121 | } |
aoqi@0 | 122 | return lay; |
aoqi@0 | 123 | } |
aoqi@0 | 124 | |
aoqi@0 | 125 | public List<Hierarchy> cExhaustive() { |
aoqi@0 | 126 | final Kind[] iKinds = new Kind[]{IDEFAULT, IVAC, IPRESENT, null}; |
aoqi@0 | 127 | final Kind[] cKinds = new Kind[]{CNONE, CABSTRACT, CCONCRETE}; |
aoqi@0 | 128 | List<Hierarchy> totest = new ArrayList<>(); |
aoqi@0 | 129 | for (int i1 = 0; i1 < iKinds.length; ++i1) { |
aoqi@0 | 130 | for (int i2 = 0; i2 < iKinds.length; ++i2) { |
aoqi@0 | 131 | for (int i3 = 0; i3 < iKinds.length; ++i3) { |
aoqi@0 | 132 | for (int c1 = 0; c1 < cKinds.length; ++c1) { |
aoqi@0 | 133 | for (int c2 = 0; c2 < cKinds.length; ++c2) { |
aoqi@0 | 134 | for (int c3 = 0; c3 < cKinds.length; ++c3) { |
aoqi@0 | 135 | totest.add( new Hierarchy( |
aoqi@0 | 136 | new ClassCase(cKinds[c1], |
aoqi@0 | 137 | new ClassCase(cKinds[c2], |
aoqi@0 | 138 | new ClassCase(cKinds[c3], |
aoqi@0 | 139 | null, |
aoqi@0 | 140 | iList(iKinds[i1]) |
aoqi@0 | 141 | ), |
aoqi@0 | 142 | iList(iKinds[i2]) |
aoqi@0 | 143 | ), |
aoqi@0 | 144 | iList(iKinds[i3]) |
aoqi@0 | 145 | ))); |
aoqi@0 | 146 | } |
aoqi@0 | 147 | } |
aoqi@0 | 148 | } |
aoqi@0 | 149 | } |
aoqi@0 | 150 | } |
aoqi@0 | 151 | } |
aoqi@0 | 152 | return totest; |
aoqi@0 | 153 | } |
aoqi@0 | 154 | |
aoqi@0 | 155 | public static final List<ClassCase> EMPTY_LIST = new ArrayList<>(); |
aoqi@0 | 156 | |
aoqi@0 | 157 | private List<ClassCase> iList(Kind kind) { |
aoqi@0 | 158 | if (kind == null) { |
aoqi@0 | 159 | return EMPTY_LIST; |
aoqi@0 | 160 | } else { |
aoqi@0 | 161 | List<ClassCase> itfs = new ArrayList<>(); |
aoqi@0 | 162 | itfs.add(new ClassCase(kind, null, EMPTY_LIST)); |
aoqi@0 | 163 | return itfs; |
aoqi@0 | 164 | } |
aoqi@0 | 165 | } |
aoqi@0 | 166 | |
aoqi@0 | 167 | public List<Hierarchy> ciShapes() { |
aoqi@0 | 168 | return wrapInHierarchy(TTShape.allCases(true)); |
aoqi@0 | 169 | } |
aoqi@0 | 170 | |
aoqi@0 | 171 | public List<Hierarchy> iShapes() { |
aoqi@0 | 172 | return wrapInClassAndHierarchy(TTShape.allCases(false)); |
aoqi@0 | 173 | } |
aoqi@0 | 174 | |
aoqi@0 | 175 | public List<Hierarchy> wrapInClassAndHierarchy(List<ClassCase> ihs) { |
aoqi@0 | 176 | List<Hierarchy> totest = new ArrayList<>(); |
aoqi@0 | 177 | for (ClassCase cc : ihs) { |
aoqi@0 | 178 | List<ClassCase> interfaces = new ArrayList<>(); |
aoqi@0 | 179 | interfaces.add(cc); |
aoqi@0 | 180 | totest.add(new Hierarchy(new ClassCase(CNONE, null, interfaces))); |
aoqi@0 | 181 | } |
aoqi@0 | 182 | return totest; |
aoqi@0 | 183 | } |
aoqi@0 | 184 | |
aoqi@0 | 185 | public List<Hierarchy> wrapInHierarchy(List<ClassCase> ihs) { |
aoqi@0 | 186 | List<Hierarchy> totest = new ArrayList<>(); |
aoqi@0 | 187 | for (ClassCase cc : ihs) { |
aoqi@0 | 188 | totest.add(new Hierarchy(cc)); |
aoqi@0 | 189 | } |
aoqi@0 | 190 | return totest; |
aoqi@0 | 191 | } |
aoqi@0 | 192 | } |