0001: package soot.toolkits.exceptions;
0002:
0003: import soot.*;
0004: import java.util.*;
0005: import junit.framework.Test;
0006: import junit.framework.TestCase;
0007: import junit.framework.TestSuite;
0008: import junit.extensions.TestSetup;
0009:
0010: import soot.toolkits.exceptions.ExceptionTestUtility.*;
0011:
0012: public class ThrowableSetTest extends TestCase {
0013:
0014: static {
0015: Scene.v().loadBasicClasses();
0016: }
0017:
0018: final static boolean DUMP_INTERNALS = false;
0019: final ThrowableSet.Manager mgr = ThrowableSet.Manager.v();
0020:
0021: // A class for verifying that the sizeToSetsMap
0022: // follows our expectations.
0023: static class ExpectedSizeToSets {
0024: private Map expectedMap = new HashMap(); // from Integer to Set.
0025:
0026: private static class SetPair {
0027: Set included;
0028: Set excluded;
0029:
0030: SetPair(Set included, Set excluded) {
0031: this .included = included;
0032: this .excluded = excluded;
0033: }
0034:
0035: public boolean equals(Object o) {
0036: if (o == this ) {
0037: return true;
0038: }
0039: if (!(o instanceof SetPair)) {
0040: return false;
0041: }
0042: SetPair sp = (SetPair) o;
0043: return (this .included.equals(sp.included) && this .excluded
0044: .equals(sp.excluded));
0045: }
0046:
0047: public int hashCode() {
0048: int result = 31;
0049: result = 37 * result + included.hashCode();
0050: result = 37 * result + excluded.hashCode();
0051: return result;
0052: }
0053:
0054: public String toString() {
0055: return (super .toString()
0056: + System.getProperty("line.separator") + "+["
0057: + included.toString() + ']' + "-["
0058: + excluded.toString() + ']');
0059: }
0060: }
0061:
0062: ExpectedSizeToSets() {
0063: // The empty set.
0064: this .add(Collections.EMPTY_SET, Collections.EMPTY_SET);
0065:
0066: // All Throwables set.
0067: Set temp = new ExceptionHashSet();
0068: temp.add(AnySubType.v(Scene.v().getRefType(
0069: "java.lang.Throwable")));
0070: this .add(temp, Collections.EMPTY_SET);
0071:
0072: // VM errors set.
0073: temp = new ExceptionHashSet();
0074: temp.add(Scene.v().getRefType("java.lang.InternalError"));
0075: temp
0076: .add(Scene.v().getRefType(
0077: "java.lang.OutOfMemoryError"));
0078: temp.add(Scene.v().getRefType(
0079: "java.lang.StackOverflowError"));
0080: temp.add(Scene.v().getRefType("java.lang.UnknownError"));
0081: temp.add(Scene.v().getRefType("java.lang.ThreadDeath"));
0082: this .add(temp, Collections.EMPTY_SET);
0083:
0084: // Resolve Class errors set.
0085: Set classErrors = new ExceptionHashSet();
0086: classErrors.add(Scene.v().getRefType(
0087: "java.lang.ClassCircularityError"));
0088: classErrors.add(AnySubType.v(Scene.v().getRefType(
0089: "java.lang.ClassFormatError")));
0090: classErrors.add(Scene.v().getRefType(
0091: "java.lang.IllegalAccessError"));
0092: classErrors.add(Scene.v().getRefType(
0093: "java.lang.IncompatibleClassChangeError"));
0094: classErrors.add(Scene.v().getRefType(
0095: "java.lang.LinkageError"));
0096: classErrors.add(Scene.v().getRefType(
0097: "java.lang.NoClassDefFoundError"));
0098: classErrors.add(Scene.v().getRefType(
0099: "java.lang.VerifyError"));
0100: this .add(classErrors, Collections.EMPTY_SET);
0101:
0102: // Resolve Field errors set.
0103: temp = new ExceptionHashSet(classErrors);
0104: temp
0105: .add(Scene.v().getRefType(
0106: "java.lang.NoSuchFieldError"));
0107: this .add(temp, Collections.EMPTY_SET);
0108:
0109: // Resolve method errors set.
0110: temp = new ExceptionHashSet(classErrors);
0111: temp.add(Scene.v().getRefType(
0112: "java.lang.AbstractMethodError"));
0113: temp.add(Scene.v()
0114: .getRefType("java.lang.NoSuchMethodError"));
0115: temp.add(Scene.v().getRefType(
0116: "java.lang.UnsatisfiedLinkError"));
0117: this .add(temp, Collections.EMPTY_SET);
0118:
0119: // Initialization errors set.
0120: temp = new ExceptionHashSet();
0121: temp.add(AnySubType.v(Scene.v().getRefType(
0122: "java.lang.Error")));
0123: this .add(temp, Collections.EMPTY_SET);
0124: }
0125:
0126: void add(Set inclusions, Set exclusions) {
0127: Integer sz = new Integer(inclusions.size()
0128: + exclusions.size());
0129: Set values = (Set) expectedMap.get(sz);
0130: if (values == null) {
0131: values = new HashSet();
0132: expectedMap.put(sz, values);
0133: }
0134: // Make sure we have our own copies of the sets.
0135: values.add(new SetPair(new ExceptionHashSet(inclusions),
0136: new ExceptionHashSet(exclusions)));
0137: }
0138:
0139: void addAndCheck(Set inclusions, Set exclusions) {
0140: this .add(inclusions, exclusions);
0141: assertTrue(this .match());
0142: }
0143:
0144: boolean match() {
0145: boolean result = true;
0146: Map actualMap = ThrowableSet.Manager.v().getSizeToSets();
0147: if (expectedMap.size() != actualMap.size()) {
0148: result = false;
0149: } else {
0150: setloop: for (Iterator i = expectedMap.keySet()
0151: .iterator(); i.hasNext();) {
0152: Integer key = (Integer) i.next();
0153: Set expectedValues = (Set) expectedMap.get(key);
0154:
0155: // To minimize restrictions on the contents of
0156: // sizeToSets, use only the Collection interface
0157: // to access its values:
0158: Collection actualValues = (Collection) actualMap
0159: .get(key);
0160:
0161: if (expectedValues.size() != actualValues.size()) {
0162: result = false;
0163: break setloop;
0164: }
0165: for (Iterator j = actualValues.iterator(); j
0166: .hasNext();) {
0167: ThrowableSet actual = (ThrowableSet) j.next();
0168: SetPair actualPair = new SetPair(
0169: new ExceptionHashSet(actual
0170: .typesIncluded()),
0171: new ExceptionHashSet(actual
0172: .typesExcluded()));
0173: if (!expectedValues.contains(actualPair)) {
0174: result = false;
0175: break setloop;
0176: }
0177: }
0178: }
0179: }
0180: if (DUMP_INTERNALS) {
0181: if (!result)
0182: System.err
0183: .println("!!!ExpectedSizeToSets.match() FAILED!!!");
0184: System.err.println("expectedMap:");
0185: System.err.println(expectedMap.toString());
0186: System.err.println("actualMap:");
0187: System.err.println(actualMap.toString());
0188: System.err.flush();
0189: }
0190: return result;
0191: }
0192: }
0193:
0194: private static ExpectedSizeToSets expectedSizeToSets;
0195:
0196: // A class to check that memoized results match what we expect.
0197: // Admittedly, this amounts to a reimplementation of the memoized
0198: // structures within ThrowableSet -- I'm hoping that the two
0199: // implementations will have different bugs!
0200: static class ExpectedMemoizations {
0201: Map throwableSetToMemoized = new HashMap();
0202:
0203: void checkAdd(ThrowableSet lhs, Object rhs, ThrowableSet result) {
0204: // rhs should be either a ThrowableSet or a RefType.
0205: Map actualMemoized = lhs.getMemoizedAdds();
0206: assertTrue(actualMemoized.get(rhs) == result);
0207:
0208: Map expectedMemoized = (Map) throwableSetToMemoized
0209: .get(lhs);
0210: if (expectedMemoized == null) {
0211: expectedMemoized = new HashMap();
0212: throwableSetToMemoized.put(lhs, expectedMemoized);
0213: }
0214: expectedMemoized.put(rhs, result);
0215: assertEquals(expectedMemoized, actualMemoized);
0216: }
0217: }
0218:
0219: private static ExpectedMemoizations expectedMemoizations;
0220:
0221: private static String jdkLocation // Can be changed by main().
0222: = "/usr/local/pkgs/jdk1.4.2_04/jre/lib/rt.jar";
0223: private static ExceptionTestUtility util;
0224:
0225: /**
0226: * <code>ThrowableSetTestSetup</code> initializes the data structures
0227: * that need to maintain their state throughout the test suite.
0228: */
0229: static class ThrowableSetTestSetup extends TestSetup {
0230:
0231: public ThrowableSetTestSetup(Test test) {
0232: super (test);
0233: }
0234:
0235: public void setUp() {
0236: expectedSizeToSets = new ExpectedSizeToSets();
0237: expectedMemoizations = new ExpectedMemoizations();
0238: util = new ExceptionTestUtility(jdkLocation);
0239: }
0240: }
0241:
0242: /**
0243: * Asserts that the membership in the component sets of a
0244: * ThrowableSet correspond to expectations.
0245: *
0246: * @param s The set to be checked.
0247: *
0248: * @param included the {@link Set} of RefLikeTypes
0249: * expected to be in included in <code>s</code>.
0250: *
0251: * @param excluded an {@link Set} of RefLikeTypes
0252: * expected to be excluded from <code>s</code>.
0253: *
0254: * @throws AssertionFailedError if <code>s</code> does not
0255: * contain the types in <code>included</code> except for those
0256: * in <code>excluded</code>.
0257: */
0258: public static void assertSameMembers(ThrowableSet s, Set included,
0259: Set excluded) {
0260: assertTrue(ExceptionTestUtility.sameMembers(included, excluded,
0261: s));
0262: }
0263:
0264: /**
0265: * Asserts that the membership in the component sets of a
0266: * ThrowableSet correspond to expectations.
0267: *
0268: * @param s The set to be checked.
0269: *
0270: * @param included an array containing the RefLikeTypes
0271: * expected to be in included in <code>s</code>.
0272: *
0273: * @param excluded an array containing the RefLikeTypes
0274: * expected to be excluded from <code>s</code>.
0275: *
0276: * @throws AssertionFailedError if <code>s</code> does not
0277: * contain the types in <code>included</code> except for those
0278: * in <code>excluded</code>.
0279: */
0280: public static void assertSameMembers(ThrowableSet s,
0281: RefLikeType[] included, RefLikeType[] excluded) {
0282: assertTrue(ExceptionTestUtility.sameMembers(
0283: new ExceptionHashSet(Arrays.asList(included)),
0284: new ExceptionHashSet(Arrays.asList(excluded)), s));
0285: }
0286:
0287: /**
0288: * Asserts that the membership in the component sets of a
0289: * ThrowableSet.Pair correspond to expectations.
0290: *
0291: * @param p The pair to be checked.
0292: *
0293: * @param caughtIncluded the set of {@link RefLikeType}s
0294: * expected to be in included in <code>p.getCaught()</code>.
0295: *
0296: * @param caughtExcluded the set of <code>RefLikeType</code>s
0297: * expected to be excluded from <code>p.getCaught()</code>.
0298: *
0299: * @param uncaughtIncluded the set of <code>RefLikeType</code>s
0300: * expected to be in included in <code>p.getUncaught()</code>.
0301: *
0302: * @param uncaughtExcluded the set of <code>RefLikeType</code>s
0303: * expected to be excluded from <code>p.getUncaught()</code>.
0304: *
0305: * @throws AssertionFailedError if <code>s</code> does not
0306: * contain the types in <code>included</code> except for those
0307: * in <code>excluded</code>.
0308: */
0309: public static void assertSameMembers(ThrowableSet.Pair p,
0310: Set caughtIncluded, Set caughtExcluded,
0311: Set uncaughtIncluded, Set uncaughtExcluded) {
0312: assertSameMembers(p.getCaught(), caughtIncluded, caughtExcluded);
0313: assertSameMembers(p.getUncaught(), uncaughtIncluded,
0314: uncaughtExcluded);
0315: }
0316:
0317: /**
0318: * Asserts that the membership in the component sets of a
0319: * ThrowableSet.Pair correspond to expectations.
0320: *
0321: * @param p The pair to be checked.
0322: *
0323: * @param caughtIncluded an array containing the {@link RefLikeType}s
0324: * expected to be in included in <code>p.getCaught()</code>.
0325: *
0326: * @param caughtExcluded an array containing the <code>RefLikeType</code>s
0327: * expected to be excluded from <code>p.getCaught()</code>.
0328: *
0329: * @param uncaughtIncluded an array containing the <code>RefLikeType</code>s
0330: * expected to be in included in <code>p.getUncaught()</code>.
0331: *
0332: * @param uncaughtExcluded an array containing the <code>RefLikeType</code>s
0333: * expected to be excluded from <code>p.getUncaught()</code>.
0334: *
0335: * @throws AssertionFailedError if <code>s</code> does not
0336: * contain the types in <code>included</code> except for those
0337: * in <code>excluded</code>.
0338: */
0339: public static void assertSameMembers(ThrowableSet.Pair p,
0340: RefLikeType[] caughtIncluded, RefLikeType[] caughtExcluded,
0341: RefLikeType[] uncaughtIncluded,
0342: RefLikeType[] uncaughtExcluded) {
0343: assertSameMembers(p.getCaught(), caughtIncluded, caughtExcluded);
0344: assertSameMembers(p.getUncaught(), uncaughtIncluded,
0345: uncaughtExcluded);
0346: }
0347:
0348: private ThrowableSet checkAdd(ThrowableSet lhs, Object rhs,
0349: Set expectedIncluded, Set expectedExcluded,
0350: ThrowableSet actualResult) {
0351: // Utility routine used by the next three add()s.
0352:
0353: assertSameMembers(actualResult, expectedIncluded,
0354: expectedExcluded);
0355: expectedSizeToSets.addAndCheck(expectedIncluded,
0356: expectedExcluded);
0357: expectedMemoizations.checkAdd(lhs, rhs, actualResult);
0358: return actualResult;
0359: }
0360:
0361: private ThrowableSet checkAdd(ThrowableSet lhs, Object rhs,
0362: Set expectedResult, ThrowableSet actualResult) {
0363: // Utility routine used by the next three add()s.
0364: return checkAdd(lhs, rhs, expectedResult,
0365: Collections.EMPTY_SET, actualResult);
0366: }
0367:
0368: private ThrowableSet add(ThrowableSet lhs, ThrowableSet rhs,
0369: Set expectedIncluded, Set expectedExcluded) {
0370: // Add rhs to lhs, checking the results.
0371:
0372: ThrowableSet actualResult = lhs.add(rhs);
0373: return checkAdd(lhs, rhs, expectedIncluded, expectedExcluded,
0374: actualResult);
0375: }
0376:
0377: private ThrowableSet add(ThrowableSet lhs, ThrowableSet rhs,
0378: Set expectedResult) {
0379: // Add rhs to lhs, checking the results.
0380: return add(lhs, rhs, expectedResult, Collections.EMPTY_SET);
0381: }
0382:
0383: private ThrowableSet add(ThrowableSet lhs, RefType rhs,
0384: Set expectedResult) {
0385: // Add rhs to lhs, checking the results.
0386:
0387: ThrowableSet actualResult = lhs.add(rhs);
0388: return checkAdd(lhs, rhs, expectedResult, actualResult);
0389: }
0390:
0391: private ThrowableSet add(ThrowableSet lhs, AnySubType rhs,
0392: Set expectedResult) {
0393: // Add rhs to lhs, checking the results.
0394:
0395: ThrowableSet actualResult = lhs.add(rhs);
0396: return checkAdd(lhs, rhs, expectedResult, actualResult);
0397: }
0398:
0399: public ThrowableSetTest(String name) {
0400: super (name);
0401: }
0402:
0403: public void testInitialState() {
0404: if (DUMP_INTERNALS) {
0405: System.err.println("\n\ntestInitialState()");
0406: }
0407: assertTrue(expectedSizeToSets.match());
0408: if (DUMP_INTERNALS) {
0409: printAllSets();
0410: }
0411: }
0412:
0413: public void testSingleInstance0() {
0414: if (DUMP_INTERNALS) {
0415: System.err.println("\n\ntestSingleInstance0()");
0416: }
0417: Set expected = new ExceptionHashSet(
0418: Arrays
0419: .asList(new RefType[] { util.UNDECLARED_THROWABLE_EXCEPTION, }));
0420:
0421: ThrowableSet set0 = add(mgr.EMPTY,
0422: util.UNDECLARED_THROWABLE_EXCEPTION, expected);
0423: ThrowableSet set1 = add(mgr.EMPTY,
0424: util.UNDECLARED_THROWABLE_EXCEPTION, expected);
0425: assertTrue(
0426: "The same ThrowableSet object should represent two sets containing the same single class.",
0427: set0 == set1);
0428:
0429: Set catchable = new ExceptionHashSet(Arrays
0430: .asList(new RefType[] {
0431: util.UNDECLARED_THROWABLE_EXCEPTION,
0432: util.RUNTIME_EXCEPTION, util.EXCEPTION,
0433: util.THROWABLE, }));
0434: assertEquals(
0435: "Should be catchable only as UndeclaredThrowableException and its superclasses",
0436: catchable, util.catchableSubset(set0));
0437:
0438: ThrowableSet.Pair catchableAs = set0
0439: .whichCatchableAs(util.LINKAGE_ERROR);
0440: assertEquals(mgr.EMPTY, catchableAs.getCaught());
0441: assertEquals(set0, catchableAs.getUncaught());
0442: catchableAs = set0
0443: .whichCatchableAs(util.UNDECLARED_THROWABLE_EXCEPTION);
0444: assertEquals(catchableAs.getCaught(), set0);
0445: assertEquals(catchableAs.getUncaught(), mgr.EMPTY);
0446: catchableAs = set0.whichCatchableAs(util.RUNTIME_EXCEPTION);
0447: assertEquals(catchableAs.getCaught(), set0);
0448: assertEquals(catchableAs.getUncaught(), mgr.EMPTY);
0449: if (DUMP_INTERNALS) {
0450: printAllSets();
0451: }
0452: }
0453:
0454: public void testSingleInstance1() {
0455: if (DUMP_INTERNALS) {
0456: System.err.println("\n\ntestSingleInstance1()");
0457: }
0458: Set expected0 = new ExceptionHashSet(
0459: Arrays
0460: .asList(new RefType[] { util.UNDECLARED_THROWABLE_EXCEPTION, }));
0461: Set expected1 = new ExceptionHashSet(
0462: Arrays
0463: .asList(new RefType[] { util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION, }));
0464: Set expectedResult = new ExceptionHashSet(Arrays
0465: .asList(new RefType[] {
0466: util.UNDECLARED_THROWABLE_EXCEPTION,
0467: util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION, }));
0468:
0469: ThrowableSet set0 = add(mgr.EMPTY,
0470: util.UNDECLARED_THROWABLE_EXCEPTION, expected0);
0471: ThrowableSet set0a = add(set0,
0472: util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION,
0473: expectedResult);
0474: ThrowableSet set1 = add(mgr.EMPTY,
0475: util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION, expected1);
0476: ThrowableSet set1a = add(set1,
0477: util.UNDECLARED_THROWABLE_EXCEPTION, expectedResult);
0478:
0479: assertTrue(
0480: "The same ThrowableSet object should represent two sets containing the same two exceptions, even if added in different orders.",
0481: set0a == set1a);
0482:
0483: Set catchable = new ExceptionHashSet(expectedResult);
0484: catchable.add(util.RUNTIME_EXCEPTION);
0485: catchable.add(util.EXCEPTION);
0486: catchable.add(util.THROWABLE);
0487: assertEquals(
0488: "Should be catchable only as UndeclaredThrowableException "
0489: + "UnsupportedLookAndFeelException and superclasses",
0490: catchable, util.catchableSubset(set0a));
0491:
0492: if (DUMP_INTERNALS) {
0493: printAllSets();
0494: }
0495: }
0496:
0497: public void testAddingSubclasses() {
0498: if (DUMP_INTERNALS) {
0499: System.err.println("\n\ntestAddingSubclasses()");
0500: }
0501: Set expected = new ExceptionHashSet();
0502: expected.add(util.INDEX_OUT_OF_BOUNDS_EXCEPTION);
0503: ThrowableSet set0 = add(mgr.EMPTY,
0504: util.INDEX_OUT_OF_BOUNDS_EXCEPTION, expected);
0505:
0506: expected.clear();
0507: expected.add(AnySubType.v(util.INDEX_OUT_OF_BOUNDS_EXCEPTION));
0508: ThrowableSet set1 = add(mgr.EMPTY, AnySubType
0509: .v(util.INDEX_OUT_OF_BOUNDS_EXCEPTION), expected);
0510: assertTrue(
0511: "ThrowableSet should distinguish the case where a single exception includes subclasses from that where it does not.",
0512: set0 != set1);
0513:
0514: Set catchable = new ExceptionHashSet(Arrays
0515: .asList(new RefType[] {
0516: util.INDEX_OUT_OF_BOUNDS_EXCEPTION,
0517: util.RUNTIME_EXCEPTION, util.EXCEPTION,
0518: util.THROWABLE, }));
0519: assertEquals(catchable, util.catchableSubset(set0));
0520:
0521: catchable.add(util.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
0522: catchable.add(util.STRING_INDEX_OUT_OF_BOUNDS_EXCEPTION);
0523: assertEquals(catchable, util.catchableSubset(set1));
0524:
0525: if (DUMP_INTERNALS) {
0526: printAllSets();
0527: }
0528: }
0529:
0530: public void testAddingSets0() {
0531: if (DUMP_INTERNALS) {
0532: System.err.println("\n\ntestAddingSets0()");
0533: }
0534: Set expected = new ExceptionHashSet(
0535: Arrays
0536: .asList(new RefType[] { util.INDEX_OUT_OF_BOUNDS_EXCEPTION, }));
0537: ThrowableSet set0 = add(mgr.EMPTY,
0538: util.INDEX_OUT_OF_BOUNDS_EXCEPTION, expected);
0539:
0540: expected.clear();
0541: expected.add(AnySubType.v(util.INDEX_OUT_OF_BOUNDS_EXCEPTION));
0542: ThrowableSet set1 = add(mgr.EMPTY, AnySubType
0543: .v(util.INDEX_OUT_OF_BOUNDS_EXCEPTION), expected);
0544:
0545: ThrowableSet result = add(set1, set0, expected);
0546: assertTrue(
0547: "{AnySubType(E)} union {E} should equal {AnySubType(E)}",
0548: result == set1);
0549:
0550: result = add(set1, set0, expected);
0551: assertTrue(
0552: "{E} union {AnySubType(E)} should equal {AnySubType(E)}",
0553: result == set1);
0554:
0555: if (DUMP_INTERNALS) {
0556: System.err.println("testAddingSets0()");
0557: printAllSets();
0558: }
0559: }
0560:
0561: public void testAddingSets1() {
0562: Set expected = new ExceptionHashSet(util.VM_ERRORS);
0563: expected.add(util.UNDECLARED_THROWABLE_EXCEPTION);
0564: ThrowableSet set0 = add(mgr.VM_ERRORS,
0565: util.UNDECLARED_THROWABLE_EXCEPTION, expected);
0566: expected.add(util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION);
0567: set0 = add(set0, util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION,
0568: expected);
0569:
0570: ThrowableSet set1 = mgr.INITIALIZATION_ERRORS;
0571: expected = new ExceptionHashSet();
0572: expected.add(AnySubType.v(util.ERROR));
0573: assertSameMembers(set1, expected, Collections.EMPTY_SET);
0574:
0575: expected.add(util.UNDECLARED_THROWABLE_EXCEPTION);
0576: expected.add(util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION);
0577: ThrowableSet result0 = add(set0, set1, expected);
0578: ThrowableSet result1 = add(set1, set0, expected);
0579: assertTrue("Adding sets should be commutative.",
0580: result0 == result1);
0581:
0582: Set catchable = new ExceptionHashSet(util.ALL_TEST_ERRORS);
0583: catchable.add(util.UNDECLARED_THROWABLE_EXCEPTION);
0584: catchable.add(util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION);
0585: catchable.add(util.RUNTIME_EXCEPTION);// Superclasses of
0586: catchable.add(util.EXCEPTION); // others.
0587: catchable.add(util.ERROR);
0588: catchable.add(util.THROWABLE);
0589: assertEquals(catchable, util.catchableSubset(result0));
0590:
0591: if (DUMP_INTERNALS) {
0592: printAllSets();
0593: }
0594: }
0595:
0596: public void testAddingSets2() {
0597: Set expected = new ExceptionHashSet(util.VM_ERRORS);
0598: expected.add(util.UNDECLARED_THROWABLE_EXCEPTION);
0599: ThrowableSet set0 = add(mgr.VM_ERRORS,
0600: util.UNDECLARED_THROWABLE_EXCEPTION, expected);
0601: expected.add(util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION);
0602: set0 = add(set0, util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION,
0603: expected);
0604:
0605: ThrowableSet set1 = mgr.INITIALIZATION_ERRORS;
0606: expected = new ExceptionHashSet();
0607: expected.add(AnySubType.v(util.ERROR));
0608: assertSameMembers(set1, expected, Collections.EMPTY_SET);
0609:
0610: expected.add(util.UNDECLARED_THROWABLE_EXCEPTION);
0611: expected.add(util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION);
0612: ThrowableSet result0 = add(set0, set1, expected);
0613: ThrowableSet result1 = add(set1, set0, expected);
0614: assertTrue("Adding sets should be commutative.",
0615: result0 == result1);
0616:
0617: Set catchable = new ExceptionHashSet(util.ALL_TEST_ERRORS);
0618: catchable.add(util.UNDECLARED_THROWABLE_EXCEPTION);
0619: catchable.add(util.UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION);
0620: catchable.add(util.RUNTIME_EXCEPTION);// Superclasses of
0621: catchable.add(util.EXCEPTION); // others.
0622: catchable.add(util.ERROR);
0623: catchable.add(util.THROWABLE);
0624: assertEquals(catchable, util.catchableSubset(result0));
0625:
0626: if (DUMP_INTERNALS) {
0627: printAllSets();
0628: }
0629: }
0630:
0631: public void testWhichCatchable0() {
0632: if (DUMP_INTERNALS) {
0633: System.err.println("\n\ntestWhichCatchable0()");
0634: }
0635: Set expected = new ExceptionHashSet(
0636: Arrays
0637: .asList(new RefType[] { util.UNDECLARED_THROWABLE_EXCEPTION, }));
0638:
0639: ThrowableSet set0 = add(mgr.EMPTY,
0640: util.UNDECLARED_THROWABLE_EXCEPTION, expected);
0641: Set catchable = new ExceptionHashSet(Arrays
0642: .asList(new RefType[] {
0643: util.UNDECLARED_THROWABLE_EXCEPTION,
0644: util.RUNTIME_EXCEPTION, util.EXCEPTION,
0645: util.THROWABLE, }));
0646:
0647: ThrowableSet.Pair catchableAs = set0
0648: .whichCatchableAs(util.LINKAGE_ERROR);
0649: assertEquals(mgr.EMPTY, catchableAs.getCaught());
0650: assertEquals(set0, catchableAs.getUncaught());
0651: assertEquals(Collections.EMPTY_SET, util
0652: .catchableSubset(catchableAs.getCaught()));
0653: assertEquals(catchable, util.catchableSubset(catchableAs
0654: .getUncaught()));
0655:
0656: assertTrue(set0
0657: .catchableAs(util.UNDECLARED_THROWABLE_EXCEPTION));
0658: catchableAs = set0
0659: .whichCatchableAs(util.UNDECLARED_THROWABLE_EXCEPTION);
0660: assertEquals(catchableAs.getCaught(), set0);
0661: assertEquals(catchableAs.getUncaught(), mgr.EMPTY);
0662: assertEquals(catchable, util.catchableSubset(catchableAs
0663: .getCaught()));
0664: assertEquals(Collections.EMPTY_SET, util
0665: .catchableSubset(catchableAs.getUncaught()));
0666:
0667: assertTrue(set0.catchableAs(util.RUNTIME_EXCEPTION));
0668: catchableAs = set0.whichCatchableAs(util.RUNTIME_EXCEPTION);
0669: assertEquals(catchableAs.getCaught(), set0);
0670: assertEquals(catchableAs.getUncaught(), mgr.EMPTY);
0671: assertEquals(catchable, util.catchableSubset(catchableAs
0672: .getCaught()));
0673: assertEquals(Collections.EMPTY_SET, util
0674: .catchableSubset(catchableAs.getUncaught()));
0675:
0676: assertTrue(set0.catchableAs(util.EXCEPTION));
0677: catchableAs = set0.whichCatchableAs(util.EXCEPTION);
0678: assertEquals(catchableAs.getCaught(), set0);
0679: assertEquals(catchableAs.getUncaught(), mgr.EMPTY);
0680: assertEquals(catchable, util.catchableSubset(catchableAs
0681: .getCaught()));
0682: assertEquals(Collections.EMPTY_SET, util
0683: .catchableSubset(catchableAs.getUncaught()));
0684:
0685: assertTrue(set0.catchableAs(util.THROWABLE));
0686: catchableAs = set0.whichCatchableAs(util.THROWABLE);
0687: assertEquals(catchableAs.getCaught(), set0);
0688: assertEquals(catchableAs.getUncaught(), mgr.EMPTY);
0689: assertEquals(catchable, util.catchableSubset(catchableAs
0690: .getCaught()));
0691: assertEquals(Collections.EMPTY_SET, util
0692: .catchableSubset(catchableAs.getUncaught()));
0693:
0694: assertTrue(!set0.catchableAs(util.ERROR));
0695: catchableAs = set0.whichCatchableAs(util.ERROR);
0696: assertEquals(catchableAs.getCaught(), mgr.EMPTY);
0697: assertEquals(catchableAs.getUncaught(), set0);
0698: assertEquals(Collections.EMPTY_SET, util
0699: .catchableSubset(catchableAs.getCaught()));
0700: assertEquals(catchable, util.catchableSubset(catchableAs
0701: .getUncaught()));
0702:
0703: if (DUMP_INTERNALS) {
0704: printAllSets();
0705: }
0706: }
0707:
0708: public void testWhichCatchable1() {
0709: if (DUMP_INTERNALS) {
0710: System.err.println("\n\ntestWhichCatchable1()");
0711: }
0712: ThrowableSet set0 = mgr.EMPTY.add(util.LINKAGE_ERROR);
0713: Set catcherTypes = new ExceptionHashSet(Arrays
0714: .asList(new RefType[] { util.LINKAGE_ERROR, util.ERROR,
0715: util.THROWABLE, }));
0716:
0717: assertTrue(set0.catchableAs(util.ERROR));
0718: ThrowableSet.Pair catchableAs = set0
0719: .whichCatchableAs(util.ERROR);
0720: assertEquals(set0, catchableAs.getCaught());
0721: assertEquals(mgr.EMPTY, catchableAs.getUncaught());
0722: assertEquals(catcherTypes, util.catchableSubset(catchableAs
0723: .getCaught()));
0724: assertEquals(Collections.EMPTY_SET, util
0725: .catchableSubset(catchableAs.getUncaught()));
0726:
0727: assertTrue(set0.catchableAs(util.LINKAGE_ERROR));
0728: catchableAs = set0.whichCatchableAs(util.LINKAGE_ERROR);
0729: assertEquals(set0, catchableAs.getCaught());
0730: assertEquals(mgr.EMPTY, catchableAs.getUncaught());
0731: assertEquals(catcherTypes, util.catchableSubset(catchableAs
0732: .getCaught()));
0733: assertEquals(Collections.EMPTY_SET, util
0734: .catchableSubset(catchableAs.getUncaught()));
0735:
0736: assertTrue(!set0
0737: .catchableAs(util.INCOMPATIBLE_CLASS_CHANGE_ERROR));
0738: catchableAs = set0
0739: .whichCatchableAs(util.INCOMPATIBLE_CLASS_CHANGE_ERROR);
0740: assertEquals(mgr.EMPTY, catchableAs.getCaught());
0741: assertEquals(set0, catchableAs.getUncaught());
0742: assertEquals(Collections.EMPTY_SET, util
0743: .catchableSubset(catchableAs.getCaught()));
0744: assertEquals(catcherTypes, util.catchableSubset(catchableAs
0745: .getUncaught()));
0746:
0747: assertTrue(!set0.catchableAs(util.INSTANTIATION_ERROR));
0748: catchableAs = set0.whichCatchableAs(util.INSTANTIATION_ERROR);
0749: assertEquals(mgr.EMPTY, catchableAs.getCaught());
0750: assertEquals(set0, catchableAs.getUncaught());
0751: assertEquals(Collections.EMPTY_SET, util
0752: .catchableSubset(catchableAs.getCaught()));
0753: assertEquals(catcherTypes, util.catchableSubset(catchableAs
0754: .getUncaught()));
0755:
0756: assertTrue(!set0.catchableAs(util.INTERNAL_ERROR));
0757: catchableAs = set0.whichCatchableAs(util.INTERNAL_ERROR);
0758: assertEquals(mgr.EMPTY, catchableAs.getCaught());
0759: assertEquals(set0, catchableAs.getUncaught());
0760: assertEquals(Collections.EMPTY_SET, util
0761: .catchableSubset(catchableAs.getCaught()));
0762: assertEquals(catcherTypes, util.catchableSubset(catchableAs
0763: .getUncaught()));
0764:
0765: if (DUMP_INTERNALS) {
0766: printAllSets();
0767: }
0768: }
0769:
0770: public void testWhichCatchable2() {
0771: if (DUMP_INTERNALS) {
0772: System.err.println("\n\ntestWhichCatchable2()");
0773: }
0774:
0775: ThrowableSet set0 = mgr.EMPTY.add(AnySubType
0776: .v(util.LINKAGE_ERROR));
0777: Set catcherTypes = new ExceptionHashSet(
0778: Arrays
0779: .asList(new RefType[] {
0780: util.CLASS_CIRCULARITY_ERROR,
0781: util.CLASS_FORMAT_ERROR,
0782: util.UNSUPPORTED_CLASS_VERSION_ERROR,
0783: util.EXCEPTION_IN_INITIALIZER_ERROR,
0784: util.INCOMPATIBLE_CLASS_CHANGE_ERROR,
0785: util.ABSTRACT_METHOD_ERROR,
0786: util.ILLEGAL_ACCESS_ERROR,
0787: util.INSTANTIATION_ERROR,
0788: util.NO_SUCH_FIELD_ERROR,
0789: util.NO_SUCH_METHOD_ERROR,
0790: util.NO_CLASS_DEF_FOUND_ERROR,
0791: util.UNSATISFIED_LINK_ERROR,
0792: util.VERIFY_ERROR, util.LINKAGE_ERROR,
0793: util.ERROR, util.THROWABLE, }));
0794:
0795: assertTrue(set0.catchableAs(util.ERROR));
0796: ThrowableSet.Pair catchableAs = set0
0797: .whichCatchableAs(util.ERROR);
0798: assertEquals(set0, catchableAs.getCaught());
0799: assertEquals(mgr.EMPTY, catchableAs.getUncaught());
0800: assertEquals(catcherTypes, util.catchableSubset(catchableAs
0801: .getCaught()));
0802: assertEquals(Collections.EMPTY_SET, util
0803: .catchableSubset(catchableAs.getUncaught()));
0804:
0805: assertTrue(set0.catchableAs(util.LINKAGE_ERROR));
0806: catchableAs = set0.whichCatchableAs(util.LINKAGE_ERROR);
0807: assertEquals(set0, catchableAs.getCaught());
0808: assertEquals(mgr.EMPTY, catchableAs.getUncaught());
0809: assertEquals(catcherTypes, util.catchableSubset(catchableAs
0810: .getCaught()));
0811: assertEquals(Collections.EMPTY_SET, util
0812: .catchableSubset(catchableAs.getUncaught()));
0813:
0814: assertTrue(set0
0815: .catchableAs(util.INCOMPATIBLE_CLASS_CHANGE_ERROR));
0816: catchableAs = set0
0817: .whichCatchableAs(util.INCOMPATIBLE_CLASS_CHANGE_ERROR);
0818: Set expectedCaughtIncluded = new ExceptionHashSet(Arrays
0819: .asList(new RefLikeType[] { AnySubType
0820: .v(util.INCOMPATIBLE_CLASS_CHANGE_ERROR) }));
0821: Set expectedCaughtExcluded = Collections.EMPTY_SET;
0822: Set expectedUncaughtIncluded = new ExceptionHashSet(Arrays
0823: .asList(new RefLikeType[] { AnySubType
0824: .v(util.LINKAGE_ERROR) }));
0825: Set expectedUncaughtExcluded = expectedCaughtIncluded;
0826: assertSameMembers(catchableAs, expectedCaughtIncluded,
0827: expectedCaughtExcluded, expectedUncaughtIncluded,
0828: expectedUncaughtExcluded);
0829: catcherTypes = new ExceptionHashSet(Arrays
0830: .asList(new RefType[] {
0831: util.INCOMPATIBLE_CLASS_CHANGE_ERROR,
0832: util.ABSTRACT_METHOD_ERROR,
0833: util.ILLEGAL_ACCESS_ERROR,
0834: util.INSTANTIATION_ERROR,
0835: util.NO_SUCH_FIELD_ERROR,
0836: util.NO_SUCH_METHOD_ERROR, util.LINKAGE_ERROR,
0837: util.ERROR, util.THROWABLE, }));
0838: Set noncatcherTypes = new ExceptionHashSet(
0839: Arrays
0840: .asList(new RefType[] {
0841: util.CLASS_CIRCULARITY_ERROR,
0842: util.CLASS_FORMAT_ERROR,
0843: util.UNSUPPORTED_CLASS_VERSION_ERROR,
0844: util.EXCEPTION_IN_INITIALIZER_ERROR,
0845: util.NO_CLASS_DEF_FOUND_ERROR,
0846: util.UNSATISFIED_LINK_ERROR,
0847: util.VERIFY_ERROR, util.LINKAGE_ERROR,
0848: util.ERROR, util.THROWABLE, }));
0849: assertEquals(catcherTypes, util.catchableSubset(catchableAs
0850: .getCaught()));
0851: assertEquals(noncatcherTypes, util.catchableSubset(catchableAs
0852: .getUncaught()));
0853:
0854: assertTrue(set0.catchableAs(util.INSTANTIATION_ERROR));
0855: catchableAs = set0.whichCatchableAs(util.INSTANTIATION_ERROR);
0856: expectedCaughtIncluded = new ExceptionHashSet(Arrays
0857: .asList(new RefLikeType[] { AnySubType
0858: .v(util.INSTANTIATION_ERROR) }));
0859: expectedCaughtExcluded = Collections.EMPTY_SET;
0860: expectedUncaughtExcluded = expectedCaughtIncluded;
0861: assertSameMembers(catchableAs, expectedCaughtIncluded,
0862: expectedCaughtExcluded, expectedUncaughtIncluded,
0863: expectedUncaughtExcluded);
0864: catcherTypes = new ExceptionHashSet(
0865: Arrays
0866: .asList(new RefType[] {
0867: util.INSTANTIATION_ERROR,
0868: util.INCOMPATIBLE_CLASS_CHANGE_ERROR,
0869: util.LINKAGE_ERROR, util.ERROR,
0870: util.THROWABLE, }));
0871: noncatcherTypes = new ExceptionHashSet(
0872: Arrays
0873: .asList(new RefType[] {
0874: util.CLASS_CIRCULARITY_ERROR,
0875: util.CLASS_FORMAT_ERROR,
0876: util.UNSUPPORTED_CLASS_VERSION_ERROR,
0877: util.EXCEPTION_IN_INITIALIZER_ERROR,
0878: util.ABSTRACT_METHOD_ERROR,
0879: util.ILLEGAL_ACCESS_ERROR,
0880: util.NO_SUCH_FIELD_ERROR,
0881: util.NO_SUCH_METHOD_ERROR,
0882: util.NO_CLASS_DEF_FOUND_ERROR,
0883: util.UNSATISFIED_LINK_ERROR,
0884: util.VERIFY_ERROR,
0885: util.INCOMPATIBLE_CLASS_CHANGE_ERROR,
0886: util.LINKAGE_ERROR, util.ERROR,
0887: util.THROWABLE, }));
0888: assertEquals(catcherTypes, util.catchableSubset(catchableAs
0889: .getCaught()));
0890: assertEquals(noncatcherTypes, util.catchableSubset(catchableAs
0891: .getUncaught()));
0892:
0893: assertTrue(!set0.catchableAs(util.INTERNAL_ERROR));
0894: catchableAs = set0.whichCatchableAs(util.INTERNAL_ERROR);
0895: assertEquals(mgr.EMPTY, catchableAs.getCaught());
0896: assertEquals(set0, catchableAs.getUncaught());
0897: noncatcherTypes = new ExceptionHashSet(
0898: Arrays
0899: .asList(new RefType[] {
0900: util.CLASS_CIRCULARITY_ERROR,
0901: util.CLASS_FORMAT_ERROR,
0902: util.UNSUPPORTED_CLASS_VERSION_ERROR,
0903: util.EXCEPTION_IN_INITIALIZER_ERROR,
0904: util.ABSTRACT_METHOD_ERROR,
0905: util.ILLEGAL_ACCESS_ERROR,
0906: util.INCOMPATIBLE_CLASS_CHANGE_ERROR,
0907: util.NO_SUCH_FIELD_ERROR,
0908: util.NO_SUCH_METHOD_ERROR,
0909: util.INSTANTIATION_ERROR,
0910: util.NO_CLASS_DEF_FOUND_ERROR,
0911: util.UNSATISFIED_LINK_ERROR,
0912: util.VERIFY_ERROR,
0913: util.INCOMPATIBLE_CLASS_CHANGE_ERROR,
0914: util.LINKAGE_ERROR, util.ERROR,
0915: util.THROWABLE, }));
0916: assertEquals(Collections.EMPTY_SET, util
0917: .catchableSubset(catchableAs.getCaught()));
0918: assertEquals(noncatcherTypes, util.catchableSubset(catchableAs
0919: .getUncaught()));
0920:
0921: if (DUMP_INTERNALS) {
0922: printAllSets();
0923: }
0924: }
0925:
0926: public void testWhichCatchable3() {
0927: if (DUMP_INTERNALS) {
0928: System.err.println("\n\ntestWhichCatchable3()");
0929: }
0930:
0931: ThrowableSet set0 = mgr.EMPTY;
0932: set0 = set0.add(AnySubType.v(util.ERROR));
0933:
0934: assertTrue(set0
0935: .catchableAs(util.INCOMPATIBLE_CLASS_CHANGE_ERROR));
0936: ThrowableSet.Pair catchableAs = set0
0937: .whichCatchableAs(util.INCOMPATIBLE_CLASS_CHANGE_ERROR);
0938: Set expectedCaughtIncluded = new ExceptionHashSet(Arrays
0939: .asList(new RefLikeType[] { AnySubType
0940: .v(util.INCOMPATIBLE_CLASS_CHANGE_ERROR) }));
0941: Set expectedCaughtExcluded = Collections.EMPTY_SET;
0942: Set expectedUncaughtIncluded = new ExceptionHashSet(Arrays
0943: .asList(new RefLikeType[] { AnySubType.v(util.ERROR) }));
0944: Set expectedUncaughtExcluded = expectedCaughtIncluded;
0945: assertTrue(ExceptionTestUtility.sameMembers(
0946: expectedCaughtIncluded, expectedCaughtExcluded,
0947: catchableAs.getCaught()));
0948: assertTrue(ExceptionTestUtility.sameMembers(
0949: expectedUncaughtIncluded, expectedUncaughtExcluded,
0950: catchableAs.getUncaught()));
0951: assertEquals(new ExceptionHashSet(Arrays.asList(new RefType[] {
0952: util.THROWABLE, util.ERROR, util.LINKAGE_ERROR,
0953: util.INCOMPATIBLE_CLASS_CHANGE_ERROR,
0954: util.ABSTRACT_METHOD_ERROR, util.INSTANTIATION_ERROR,
0955: util.ILLEGAL_ACCESS_ERROR, util.NO_SUCH_FIELD_ERROR,
0956: util.NO_SUCH_METHOD_ERROR, })), util
0957: .catchableSubset(catchableAs.getCaught()));
0958: assertEquals(new ExceptionHashSet(Arrays.asList(new RefType[] {
0959: util.THROWABLE, util.ERROR, util.AWT_ERROR,
0960: util.LINKAGE_ERROR, util.CLASS_CIRCULARITY_ERROR,
0961: util.CLASS_FORMAT_ERROR,
0962: util.UNSUPPORTED_CLASS_VERSION_ERROR,
0963: util.EXCEPTION_IN_INITIALIZER_ERROR,
0964: util.NO_CLASS_DEF_FOUND_ERROR,
0965: util.UNSATISFIED_LINK_ERROR, util.VERIFY_ERROR,
0966: util.THREAD_DEATH, util.VIRTUAL_MACHINE_ERROR,
0967: util.INTERNAL_ERROR, util.OUT_OF_MEMORY_ERROR,
0968: util.STACK_OVERFLOW_ERROR, util.UNKNOWN_ERROR, })),
0969: util.catchableSubset(catchableAs.getUncaught()));
0970:
0971: set0 = catchableAs.getUncaught();
0972:
0973: assertTrue(set0.catchableAs(util.THROWABLE));
0974: catchableAs = set0.whichCatchableAs(util.THROWABLE);
0975: assertEquals(set0, catchableAs.getCaught());
0976: assertEquals(mgr.EMPTY, catchableAs.getUncaught());
0977: assertEquals(new ExceptionHashSet(Arrays.asList(new RefType[] {
0978: util.THROWABLE, util.ERROR, util.AWT_ERROR,
0979: util.LINKAGE_ERROR, util.CLASS_CIRCULARITY_ERROR,
0980: util.CLASS_FORMAT_ERROR,
0981: util.UNSUPPORTED_CLASS_VERSION_ERROR,
0982: util.EXCEPTION_IN_INITIALIZER_ERROR,
0983: util.NO_CLASS_DEF_FOUND_ERROR,
0984: util.UNSATISFIED_LINK_ERROR, util.VERIFY_ERROR,
0985: util.THREAD_DEATH, util.VIRTUAL_MACHINE_ERROR,
0986: util.INTERNAL_ERROR, util.OUT_OF_MEMORY_ERROR,
0987: util.STACK_OVERFLOW_ERROR, util.UNKNOWN_ERROR, })),
0988: util.catchableSubset(catchableAs.getCaught()));
0989: assertEquals(Collections.EMPTY_SET, util
0990: .catchableSubset(catchableAs.getUncaught()));
0991:
0992: assertTrue(set0.catchableAs(util.ERROR));
0993: catchableAs = set0.whichCatchableAs(util.ERROR);
0994: assertEquals(set0, catchableAs.getCaught());
0995: assertEquals(mgr.EMPTY, catchableAs.getUncaught());
0996: assertEquals(new ExceptionHashSet(Arrays.asList(new RefType[] {
0997: util.THROWABLE, util.ERROR, util.AWT_ERROR,
0998: util.LINKAGE_ERROR, util.CLASS_CIRCULARITY_ERROR,
0999: util.CLASS_FORMAT_ERROR,
1000: util.UNSUPPORTED_CLASS_VERSION_ERROR,
1001: util.EXCEPTION_IN_INITIALIZER_ERROR,
1002: util.NO_CLASS_DEF_FOUND_ERROR,
1003: util.UNSATISFIED_LINK_ERROR, util.VERIFY_ERROR,
1004: util.THREAD_DEATH, util.VIRTUAL_MACHINE_ERROR,
1005: util.INTERNAL_ERROR, util.OUT_OF_MEMORY_ERROR,
1006: util.STACK_OVERFLOW_ERROR, util.UNKNOWN_ERROR, })),
1007: util.catchableSubset(catchableAs.getCaught()));
1008: assertEquals(Collections.EMPTY_SET, util
1009: .catchableSubset(catchableAs.getUncaught()));
1010:
1011: assertTrue(set0.catchableAs(util.LINKAGE_ERROR));
1012: catchableAs = set0.whichCatchableAs(util.LINKAGE_ERROR);
1013: expectedCaughtIncluded = new ExceptionHashSet(Arrays
1014: .asList(new RefLikeType[] { AnySubType
1015: .v(util.LINKAGE_ERROR) }));
1016: expectedCaughtExcluded = new ExceptionHashSet(Arrays
1017: .asList(new RefLikeType[] { AnySubType
1018: .v(util.INCOMPATIBLE_CLASS_CHANGE_ERROR) }));
1019: expectedUncaughtIncluded = new ExceptionHashSet(Arrays
1020: .asList(new RefLikeType[] { AnySubType.v(util.ERROR) }));
1021: expectedUncaughtExcluded = expectedCaughtIncluded;
1022: assertTrue(ExceptionTestUtility.sameMembers(
1023: expectedCaughtIncluded, expectedCaughtExcluded,
1024: catchableAs.getCaught()));
1025: assertTrue(ExceptionTestUtility.sameMembers(
1026: expectedUncaughtIncluded, expectedUncaughtExcluded,
1027: catchableAs.getUncaught()));
1028: assertEquals(new ExceptionHashSet(Arrays.asList(new RefType[] {
1029: util.THROWABLE, util.ERROR, util.LINKAGE_ERROR,
1030: util.CLASS_CIRCULARITY_ERROR, util.CLASS_FORMAT_ERROR,
1031: util.UNSUPPORTED_CLASS_VERSION_ERROR,
1032: util.EXCEPTION_IN_INITIALIZER_ERROR,
1033: util.NO_CLASS_DEF_FOUND_ERROR,
1034: util.UNSATISFIED_LINK_ERROR, util.VERIFY_ERROR, })),
1035: util.catchableSubset(catchableAs.getCaught()));
1036: assertEquals(new ExceptionHashSet(Arrays.asList(new RefType[] {
1037: util.THROWABLE, util.ERROR, util.AWT_ERROR,
1038: util.THREAD_DEATH, util.VIRTUAL_MACHINE_ERROR,
1039: util.INTERNAL_ERROR, util.OUT_OF_MEMORY_ERROR,
1040: util.STACK_OVERFLOW_ERROR, util.UNKNOWN_ERROR, })),
1041: util.catchableSubset(catchableAs.getUncaught()));
1042:
1043: assertTrue(!set0
1044: .catchableAs(util.INCOMPATIBLE_CLASS_CHANGE_ERROR));
1045: catchableAs = set0
1046: .whichCatchableAs(util.INCOMPATIBLE_CLASS_CHANGE_ERROR);
1047: assertEquals(mgr.EMPTY, catchableAs.getCaught());
1048: assertEquals(set0, catchableAs.getUncaught());
1049: assertEquals(Collections.EMPTY_SET, util
1050: .catchableSubset(catchableAs.getCaught()));
1051: assertEquals(new ExceptionHashSet(Arrays.asList(new RefType[] {
1052: util.THROWABLE, util.ERROR, util.LINKAGE_ERROR,
1053: util.AWT_ERROR, util.THREAD_DEATH,
1054: util.VIRTUAL_MACHINE_ERROR, util.INTERNAL_ERROR,
1055: util.OUT_OF_MEMORY_ERROR, util.STACK_OVERFLOW_ERROR,
1056: util.CLASS_CIRCULARITY_ERROR, util.CLASS_FORMAT_ERROR,
1057: util.UNSUPPORTED_CLASS_VERSION_ERROR,
1058: util.EXCEPTION_IN_INITIALIZER_ERROR,
1059: util.NO_CLASS_DEF_FOUND_ERROR,
1060: util.UNSATISFIED_LINK_ERROR, util.VERIFY_ERROR,
1061: util.UNKNOWN_ERROR, })), util
1062: .catchableSubset(catchableAs.getUncaught()));
1063:
1064: catchableAs = set0.whichCatchableAs(util.ILLEGAL_ACCESS_ERROR);
1065: assertEquals(mgr.EMPTY, catchableAs.getCaught());
1066: assertEquals(set0, catchableAs.getUncaught());
1067: assertEquals(Collections.EMPTY_SET, util
1068: .catchableSubset(catchableAs.getCaught()));
1069: assertEquals(new ExceptionHashSet(Arrays.asList(new RefType[] {
1070: util.THROWABLE, util.ERROR, util.LINKAGE_ERROR,
1071: util.AWT_ERROR, util.THREAD_DEATH,
1072: util.VIRTUAL_MACHINE_ERROR, util.INTERNAL_ERROR,
1073: util.OUT_OF_MEMORY_ERROR, util.STACK_OVERFLOW_ERROR,
1074: util.CLASS_CIRCULARITY_ERROR, util.CLASS_FORMAT_ERROR,
1075: util.UNSUPPORTED_CLASS_VERSION_ERROR,
1076: util.EXCEPTION_IN_INITIALIZER_ERROR,
1077: util.NO_CLASS_DEF_FOUND_ERROR,
1078: util.UNSATISFIED_LINK_ERROR, util.VERIFY_ERROR,
1079: util.UNKNOWN_ERROR, })), util
1080: .catchableSubset(catchableAs.getUncaught()));
1081:
1082: if (DUMP_INTERNALS) {
1083: printAllSets();
1084: }
1085: }
1086:
1087: public void testWhichCatchable10() {
1088: if (DUMP_INTERNALS) {
1089: System.err.println("\n\ntestWhichCatchable3()");
1090: }
1091:
1092: ThrowableSet set0 = mgr.EMPTY;
1093: set0 = set0.add(AnySubType.v(util.THROWABLE));
1094:
1095: assertTrue(set0.catchableAs(util.ARITHMETIC_EXCEPTION));
1096: ThrowableSet.Pair catchableAs = set0
1097: .whichCatchableAs(util.ARITHMETIC_EXCEPTION);
1098: assertSameMembers(catchableAs, new RefLikeType[] { AnySubType
1099: .v(util.ARITHMETIC_EXCEPTION), }, new RefLikeType[] {},
1100: new RefLikeType[] { AnySubType.v(util.THROWABLE), },
1101: new RefLikeType[] { AnySubType
1102: .v(util.ARITHMETIC_EXCEPTION), });
1103: assertEquals(new ExceptionHashSet(Arrays.asList(new RefType[] {
1104: util.THROWABLE, util.EXCEPTION, util.RUNTIME_EXCEPTION,
1105: util.ARITHMETIC_EXCEPTION, })), util
1106: .catchableSubset(catchableAs.getCaught()));
1107: HashSet expectedUncaught = new HashSet(util.ALL_TEST_THROWABLES);
1108: expectedUncaught.remove(util.ARITHMETIC_EXCEPTION);
1109: assertEquals(expectedUncaught, util.catchableSubset(catchableAs
1110: .getUncaught()));
1111:
1112: set0 = catchableAs.getUncaught();
1113: assertTrue(set0.catchableAs(util.ABSTRACT_METHOD_ERROR));
1114: catchableAs = set0.whichCatchableAs(util.ABSTRACT_METHOD_ERROR);
1115: assertSameMembers(catchableAs, new RefLikeType[] { AnySubType
1116: .v(util.ABSTRACT_METHOD_ERROR), },
1117: new RefLikeType[] {}, new RefLikeType[] { AnySubType
1118: .v(util.THROWABLE), }, new RefLikeType[] {
1119: AnySubType.v(util.ARITHMETIC_EXCEPTION),
1120: AnySubType.v(util.ABSTRACT_METHOD_ERROR), });
1121: assertEquals(new ExceptionHashSet(Arrays.asList(new RefType[] {
1122: util.THROWABLE, util.ERROR, util.LINKAGE_ERROR,
1123: util.INCOMPATIBLE_CLASS_CHANGE_ERROR,
1124: util.ABSTRACT_METHOD_ERROR, })), util
1125: .catchableSubset(catchableAs.getCaught()));
1126: expectedUncaught.remove(util.ABSTRACT_METHOD_ERROR);
1127: assertEquals(expectedUncaught, util.catchableSubset(catchableAs
1128: .getUncaught()));
1129:
1130: set0 = catchableAs.getUncaught();
1131: assertTrue(set0.catchableAs(util.RUNTIME_EXCEPTION));
1132: catchableAs = set0.whichCatchableAs(util.RUNTIME_EXCEPTION);
1133: assertSameMembers(catchableAs, new RefLikeType[] { AnySubType
1134: .v(util.RUNTIME_EXCEPTION), },
1135: new RefLikeType[] { AnySubType
1136: .v(util.ARITHMETIC_EXCEPTION), },
1137: new RefLikeType[] { AnySubType.v(util.THROWABLE), },
1138: new RefLikeType[] {
1139: AnySubType.v(util.RUNTIME_EXCEPTION),
1140: AnySubType.v(util.ABSTRACT_METHOD_ERROR), });
1141: assertEquals(new ExceptionHashSet(Arrays.asList(new RefType[] {
1142: util.THROWABLE, util.EXCEPTION, util.RUNTIME_EXCEPTION,
1143: util.ARRAY_STORE_EXCEPTION, util.CLASS_CAST_EXCEPTION,
1144: util.ILLEGAL_MONITOR_STATE_EXCEPTION,
1145: util.INDEX_OUT_OF_BOUNDS_EXCEPTION,
1146: util.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION,
1147: util.STRING_INDEX_OUT_OF_BOUNDS_EXCEPTION,
1148: util.NEGATIVE_ARRAY_SIZE_EXCEPTION,
1149: util.NULL_POINTER_EXCEPTION,
1150: util.UNDECLARED_THROWABLE_EXCEPTION })), util
1151: .catchableSubset(catchableAs.getCaught()));
1152: expectedUncaught.remove(util.RUNTIME_EXCEPTION);
1153: expectedUncaught.remove(util.ARRAY_STORE_EXCEPTION);
1154: expectedUncaught.remove(util.CLASS_CAST_EXCEPTION);
1155: expectedUncaught.remove(util.ILLEGAL_MONITOR_STATE_EXCEPTION);
1156: expectedUncaught.remove(util.INDEX_OUT_OF_BOUNDS_EXCEPTION);
1157: expectedUncaught
1158: .remove(util.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
1159: expectedUncaught
1160: .remove(util.STRING_INDEX_OUT_OF_BOUNDS_EXCEPTION);
1161: expectedUncaught.remove(util.NEGATIVE_ARRAY_SIZE_EXCEPTION);
1162: expectedUncaught.remove(util.NULL_POINTER_EXCEPTION);
1163: expectedUncaught.remove(util.UNDECLARED_THROWABLE_EXCEPTION);
1164: assertEquals(expectedUncaught, util.catchableSubset(catchableAs
1165: .getUncaught()));
1166: }
1167:
1168: public void testAddAfterWhichCatchableAs0() {
1169: if (DUMP_INTERNALS) {
1170: System.err.println("\n\ntestAddAfterWhichCatchable0()");
1171: }
1172:
1173: ThrowableSet anyError = mgr.EMPTY.add(AnySubType.v(util.ERROR));
1174:
1175: assertTrue(anyError.catchableAs(util.LINKAGE_ERROR));
1176: ThrowableSet.Pair catchableAs = anyError
1177: .whichCatchableAs(util.LINKAGE_ERROR);
1178: assertSameMembers(catchableAs, new RefLikeType[] { AnySubType
1179: .v(util.LINKAGE_ERROR), }, new RefLikeType[] {},
1180: new RefLikeType[] { AnySubType.v(util.ERROR), },
1181: new RefLikeType[] { AnySubType.v(util.LINKAGE_ERROR), });
1182:
1183: ThrowableSet anyErrorMinusLinkage = catchableAs.getUncaught();
1184: try {
1185: ThrowableSet anyErrorMinusLinkagePlusIncompatibleClassChange = anyErrorMinusLinkage
1186: .add(util.INCOMPATIBLE_CLASS_CHANGE_ERROR);
1187: fail("add(IncompatiableClassChangeError) after removing LinkageError should currently generate an exception");
1188:
1189: // Following documents what we would like to be able to implement:
1190: assertSameMembers(
1191: anyErrorMinusLinkagePlusIncompatibleClassChange,
1192: new RefLikeType[] { AnySubType.v(util.ERROR),
1193: util.INCOMPATIBLE_CLASS_CHANGE_ERROR, },
1194: new RefLikeType[] { AnySubType
1195: .v(util.LINKAGE_ERROR), });
1196: } catch (ThrowableSet.AlreadyHasExclusionsException e) {
1197: // this is what should happen.
1198: }
1199:
1200: try {
1201: ThrowableSet anyErrorMinusLinkagePlusAnyIncompatibleClassChange = anyErrorMinusLinkage
1202: .add(AnySubType
1203: .v(util.INCOMPATIBLE_CLASS_CHANGE_ERROR));
1204: fail("add(AnySubType.v(IncompatiableClassChangeError)) after removing LinkageError should currently generate an exception");
1205:
1206: // Following documents what we would like to be able to implement:
1207: assertSameMembers(
1208: anyErrorMinusLinkagePlusAnyIncompatibleClassChange,
1209: new RefLikeType[] {
1210: AnySubType.v(util.ERROR),
1211: AnySubType
1212: .v(util.INCOMPATIBLE_CLASS_CHANGE_ERROR), },
1213: new RefLikeType[] { AnySubType
1214: .v(util.LINKAGE_ERROR), });
1215: } catch (ThrowableSet.AlreadyHasExclusionsException e) {
1216: // this is what should happen.
1217: }
1218:
1219: // Add types that should not change the set.
1220: ThrowableSet sameSet = anyErrorMinusLinkage
1221: .add(util.VIRTUAL_MACHINE_ERROR);
1222: assertTrue(sameSet == anyErrorMinusLinkage);
1223: assertSameMembers(sameSet, new RefLikeType[] { AnySubType
1224: .v(util.ERROR), }, new RefLikeType[] { AnySubType
1225: .v(util.LINKAGE_ERROR), });
1226: sameSet = anyErrorMinusLinkage.add(AnySubType
1227: .v(util.VIRTUAL_MACHINE_ERROR));
1228: assertTrue(sameSet == anyErrorMinusLinkage);
1229: assertSameMembers(sameSet, new RefLikeType[] { AnySubType
1230: .v(util.ERROR), }, new RefLikeType[] { AnySubType
1231: .v(util.LINKAGE_ERROR), });
1232:
1233: ThrowableSet anyErrorMinusLinkagePlusArrayIndex = anyErrorMinusLinkage
1234: .add(util.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
1235: assertSameMembers(anyErrorMinusLinkagePlusArrayIndex,
1236: new RefLikeType[] { AnySubType.v(util.ERROR),
1237: util.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION, },
1238: new RefLikeType[] { AnySubType.v(util.LINKAGE_ERROR), });
1239:
1240: ThrowableSet anyErrorMinusLinkagePlusAnyIndex = anyErrorMinusLinkagePlusArrayIndex
1241: .add(AnySubType.v(util.INDEX_OUT_OF_BOUNDS_EXCEPTION));
1242: assertSameMembers(
1243: anyErrorMinusLinkagePlusAnyIndex,
1244: new RefLikeType[] {
1245: AnySubType.v(util.ERROR),
1246: AnySubType
1247: .v(util.INDEX_OUT_OF_BOUNDS_EXCEPTION), },
1248: new RefLikeType[] { AnySubType.v(util.LINKAGE_ERROR), });
1249:
1250: ThrowableSet anyErrorMinusLinkagePlusAnyRuntime = anyErrorMinusLinkagePlusAnyIndex
1251: .add(AnySubType.v(util.RUNTIME_EXCEPTION));
1252: assertSameMembers(anyErrorMinusLinkagePlusAnyRuntime,
1253: new RefLikeType[] { AnySubType.v(util.ERROR),
1254: AnySubType.v(util.RUNTIME_EXCEPTION), },
1255: new RefLikeType[] { AnySubType.v(util.LINKAGE_ERROR), });
1256:
1257: try {
1258: ThrowableSet anyErrorMinusLinkagePlusAnyRuntimePlusError = anyErrorMinusLinkagePlusAnyRuntime
1259: .add(AnySubType.v(util.ERROR));
1260: fail("add(AnySubType(Error)) after removing LinkageError should currently generate an exception.");
1261:
1262: // This documents what we would like to implement:
1263: assertSameMembers(
1264: anyErrorMinusLinkagePlusAnyRuntimePlusError,
1265: new RefLikeType[] { AnySubType.v(util.ERROR),
1266: AnySubType.v(util.RUNTIME_EXCEPTION), },
1267: new RefLikeType[] {});
1268: } catch (ThrowableSet.AlreadyHasExclusionsException e) {
1269: // This is what should happen.
1270: }
1271:
1272: try {
1273: ThrowableSet anyErrorMinusLinkagePlusAnyRuntimePlusLinkageError = anyErrorMinusLinkagePlusAnyRuntime
1274: .add(AnySubType.v(util.LINKAGE_ERROR));
1275: fail("add(AnySubType(LinkageError)) after removing LinkageError should currently generate an exception.");
1276:
1277: // This documents what we would like to implement:
1278: assertSameMembers(
1279: anyErrorMinusLinkagePlusAnyRuntimePlusLinkageError,
1280: new RefLikeType[] { AnySubType.v(util.ERROR),
1281: AnySubType.v(util.RUNTIME_EXCEPTION), },
1282: new RefLikeType[] {});
1283: } catch (ThrowableSet.AlreadyHasExclusionsException e) {
1284: // This is what should happen.
1285: }
1286:
1287: }
1288:
1289: void printAllSets() {
1290: for (Iterator i = mgr.getSizeToSets().values().iterator(); i
1291: .hasNext();) {
1292: List sizeList = (List) i.next();
1293: for (Iterator j = sizeList.iterator(); j.hasNext();) {
1294: ThrowableSet s = (ThrowableSet) j.next();
1295: System.err.println(s.toString());
1296: System.err.println("\n\tMemoized Adds:");
1297: for (Iterator k = s.getMemoizedAdds().entrySet()
1298: .iterator(); k.hasNext();) {
1299: Map.Entry entry = (Map.Entry) k.next();
1300: System.err.print(' ');
1301: if (entry.getKey() instanceof ThrowableSet) {
1302: System.err
1303: .print(((ThrowableSet) entry.getKey())
1304: .toBriefString());
1305: } else {
1306: System.err.print(entry.getKey().toString());
1307: }
1308: System.err.print('=');
1309: System.err.print(((ThrowableSet) entry.getValue())
1310: .toBriefString());
1311: System.err.print('\n');
1312: }
1313: }
1314: }
1315: }
1316:
1317: // Suite that uses a prescribed order, rather than whatever
1318: // order reflection produces.
1319: public static Test cannedSuite() {
1320: TestSuite suite = new TestSuite();
1321: suite.addTest(new ThrowableSetTest("testInitialState"));
1322: suite.addTest(new ThrowableSetTest("testSingleInstance0"));
1323: suite.addTest(new ThrowableSetTest("testSingleInstance1"));
1324: suite.addTest(new ThrowableSetTest("testAddingSubclasses"));
1325: suite.addTest(new ThrowableSetTest("testAddingSets0"));
1326: suite.addTest(new ThrowableSetTest("testAddingSets1"));
1327: TestSetup setup = new ThrowableSetTestSetup(suite);
1328: return setup;
1329: }
1330:
1331: public static Test reflectionSuite() {
1332: TestSuite suite = new TestSuite(ThrowableSetTest.class);
1333: TestSetup setup = new ThrowableSetTestSetup(suite);
1334: return setup;
1335: }
1336:
1337: public static Test suite() {
1338: Scene.v().loadBasicClasses();
1339: return reflectionSuite();
1340: }
1341:
1342: public static void main(String arg[]) {
1343: if (arg.length > 0) {
1344: jdkLocation = arg[0];
1345: }
1346: Scene.v().loadBasicClasses();
1347: junit.textui.TestRunner.run(reflectionSuite());
1348: System.out.println(ThrowableSet.Manager.v()
1349: .reportInstrumentation());
1350: }
1351: }
|