Search in sources :

Example 16 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testJThrowStmt.

@Test
public void testJThrowStmt() {
    // First test with an argument that is included in
    // PERENNIAL_THROW_EXCEPTIONS.
    ThrowStmt s = Jimple.v().newThrowStmt(Jimple.v().newLocal("local0", RefType.v("java.lang.NullPointerException")));
    Set expectedRep = new ExceptionHashSet(utility.PERENNIAL_THROW_EXCEPTIONS);
    expectedRep.remove(utility.NULL_POINTER_EXCEPTION);
    expectedRep.add(AnySubType.v(utility.NULL_POINTER_EXCEPTION));
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    assertEquals(utility.PERENNIAL_THROW_EXCEPTIONS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(s)));
    // Throw a local of type IncompatibleClassChangeError.
    Local local = Jimple.v().newLocal("local1", utility.INCOMPATIBLE_CLASS_CHANGE_ERROR);
    s.setOp(local);
    expectedRep = new ExceptionHashSet(utility.THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE);
    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) Local(soot.Local) ThrowStmt(soot.jimple.ThrowStmt) Test(org.junit.Test)

Example 17 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testJEnterMonitorStmt.

@Test
public void testJEnterMonitorStmt() {
    Stmt s = Jimple.v().newEnterMonitorStmt(StringConstant.v("test"));
    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
    expectedRep.add(utility.NULL_POINTER_EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    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 18 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testJArrayRef.

@Test
public void testJArrayRef() {
    ArrayRef arrayRef = Jimple.v().newArrayRef(Jimple.v().newLocal("local1", ArrayType.v(RefType.v("java.lang.Object"), 1)), IntConstant.v(0));
    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    expectedRep.add(utility.NULL_POINTER_EXCEPTION);
    expectedRep.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(arrayRef)));
    Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
    expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
    expectedCatch.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
    expectedCatch.add(utility.INDEX_OUT_OF_BOUNDS_EXCEPTION);
    expectedCatch.add(utility.RUNTIME_EXCEPTION);
    expectedCatch.add(utility.EXCEPTION);
    assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(arrayRef)));
}
Also used : ArrayRef(soot.jimple.ArrayRef) ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Set(java.util.Set) ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Test(org.junit.Test)

Example 19 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testGAssignStmt.

@Test
public void testGAssignStmt() {
    // local0 = 0
    Stmt s = Grimp.v().newAssignStmt(Grimp.v().newLocal("local0", IntType.v()), IntConstant.v(0));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(s)));
    ArrayRef arrayRef = Grimp.v().newArrayRef(Grimp.v().newLocal("local1", ArrayType.v(RefType.v("java.lang.Object"), 1)), IntConstant.v(0));
    Local scalarRef = Grimp.v().newLocal("local2", RefType.v("java.lang.Object"));
    // local2 = local1[0]
    s = Grimp.v().newAssignStmt(scalarRef, arrayRef);
    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    expectedRep.add(utility.NULL_POINTER_EXCEPTION);
    expectedRep.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
    expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
    expectedCatch.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
    expectedCatch.add(utility.INDEX_OUT_OF_BOUNDS_EXCEPTION);
    expectedCatch.add(utility.RUNTIME_EXCEPTION);
    expectedCatch.add(utility.EXCEPTION);
    assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(s)));
    // local1[0] = local2
    s = Grimp.v().newAssignStmt(arrayRef, scalarRef);
    expectedRep.add(utility.ARRAY_STORE_EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    expectedCatch.add(utility.ARRAY_STORE_EXCEPTION);
    assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
Also used : ArrayRef(soot.jimple.ArrayRef) ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Set(java.util.Set) ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Local(soot.Local) ThrowStmt(soot.jimple.ThrowStmt) IfStmt(soot.jimple.IfStmt) Stmt(soot.jimple.Stmt) Test(org.junit.Test)

Example 20 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testGRemExpr.

@Test
public void testGRemExpr() {
    Set vmAndArithmetic = new ExceptionHashSet(utility.VM_ERRORS);
    vmAndArithmetic.add(utility.ARITHMETIC_EXCEPTION);
    Set vmAndArithmeticAndSupertypes = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
    vmAndArithmeticAndSupertypes.add(utility.ARITHMETIC_EXCEPTION);
    vmAndArithmeticAndSupertypes.add(utility.RUNTIME_EXCEPTION);
    vmAndArithmeticAndSupertypes.add(utility.EXCEPTION);
    Local intLocal = Grimp.v().newLocal("intLocal", IntType.v());
    Local longLocal = Grimp.v().newLocal("longLocal", LongType.v());
    Local floatLocal = Grimp.v().newLocal("floatLocal", FloatType.v());
    Local doubleLocal = Grimp.v().newLocal("doubleLocal", DoubleType.v());
    RemExpr v = Grimp.v().newRemExpr(intLocal, IntConstant.v(0));
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(intLocal, IntConstant.v(2));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(IntConstant.v(0), IntConstant.v(2));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(intLocal, intLocal);
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(Grimp.v().newAddExpr(intLocal, intLocal), Grimp.v().newMulExpr(intLocal, intLocal));
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(longLocal, LongConstant.v(0));
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(longLocal, LongConstant.v(2));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(LongConstant.v(0), LongConstant.v(2));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(longLocal, longLocal);
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(Grimp.v().newAddExpr(longLocal, longLocal), Grimp.v().newMulExpr(longLocal, longLocal));
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(floatLocal, FloatConstant.v(0.0f));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(floatLocal, FloatConstant.v(2.0f));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(FloatConstant.v(0), FloatConstant.v(2.0f));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(floatLocal, floatLocal);
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(doubleLocal, DoubleConstant.v(0.0));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(doubleLocal, DoubleConstant.v(2.0));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(DoubleConstant.v(0), DoubleConstant.v(2.0));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Grimp.v().newRemExpr(doubleLocal, doubleLocal);
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
}
Also used : ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Set(java.util.Set) ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) RemExpr(soot.jimple.RemExpr) Local(soot.Local) 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