Search in sources :

Example 26 with ExceptionHashSet

use of soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet in project soot by Sable.

the class UnitThrowAnalysisTest method testJExitMonitorStmt.

@Test
public void testJExitMonitorStmt() {
    Stmt s = Jimple.v().newExitMonitorStmt(StringConstant.v("test"));
    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    expectedRep.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION);
    expectedRep.add(utility.NULL_POINTER_EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
    expectedCatch.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION);
    expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
    expectedCatch.add(utility.RUNTIME_EXCEPTION);
    expectedCatch.add(utility.EXCEPTION);
    assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
Also used : ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Set(java.util.Set) ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) ThrowStmt(soot.jimple.ThrowStmt) IfStmt(soot.jimple.IfStmt) Stmt(soot.jimple.Stmt) Test(org.junit.Test)

Example 27 with ExceptionHashSet

use of soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet in project soot by Sable.

the class UnitThrowAnalysisTest method testGThrowStmt.

@Test
public void testGThrowStmt() {
    ThrowStmt s = Grimp.v().newThrowStmt(Grimp.v().newLocal("local0", RefType.v("java.util.zip.ZipException")));
    Set expectedRep = new ExceptionHashSet(utility.PERENNIAL_THROW_EXCEPTIONS);
    expectedRep.add(AnySubType.v(Scene.v().getRefType("java.util.zip.ZipException")));
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    Set expectedCatch = new ExceptionHashSet(utility.PERENNIAL_THROW_EXCEPTIONS_PLUS_SUPERTYPES);
    // We don't need to add java.util.zip.ZipException, since it is not
    // in the universe of test Throwables.
    assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(s)));
    // Now throw a new IncompatibleClassChangeError.
    s = Grimp.v().newThrowStmt(Grimp.v().newNewInvokeExpr(utility.INCOMPATIBLE_CLASS_CHANGE_ERROR, Scene.v().makeMethodRef(utility.INCOMPATIBLE_CLASS_CHANGE_ERROR.getSootClass(), "void <init>", Collections.EMPTY_LIST, VoidType.v(), false), new ArrayList()));
    assertTrue(ExceptionTestUtility.sameMembers(utility.THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    assertEquals(utility.THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(s)));
    // Throw a local of type IncompatibleClassChangeError.
    Local local = Grimp.v().newLocal("local1", utility.INCOMPATIBLE_CLASS_CHANGE_ERROR);
    s.setOp(local);
    expectedRep = new ExceptionHashSet(utility.PERENNIAL_THROW_EXCEPTIONS);
    expectedRep.remove(utility.INCOMPATIBLE_CLASS_CHANGE_ERROR);
    expectedRep.add(AnySubType.v(utility.INCOMPATIBLE_CLASS_CHANGE_ERROR));
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    assertEquals(utility.THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUBTYPES_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(s)));
    // Throw a local of unknown type.
    local = Jimple.v().newLocal("local1", soot.UnknownType.v());
    s.setOp(local);
    assertTrue(ExceptionTestUtility.sameMembers(utility.ALL_THROWABLES_REP, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    assertEquals(utility.ALL_TEST_THROWABLES, utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
Also used : ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Set(java.util.Set) ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) ArrayList(java.util.ArrayList) Local(soot.Local) ThrowStmt(soot.jimple.ThrowStmt) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)27 ExceptionHashSet (soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet)27 Set (java.util.Set)25 ThrowStmt (soot.jimple.ThrowStmt)16 IfStmt (soot.jimple.IfStmt)14 Stmt (soot.jimple.Stmt)14 Local (soot.Local)9 Ignore (org.junit.Ignore)7 Value (soot.Value)4 ArrayRef (soot.jimple.ArrayRef)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 SootClass (soot.SootClass)2 DivExpr (soot.jimple.DivExpr)2 RemExpr (soot.jimple.RemExpr)2 AnySubType (soot.AnySubType)1 RefLikeType (soot.RefLikeType)1