Search in sources :

Example 1 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testGReturnStmt.

@Ignore("Fails")
@Test
public void testGReturnStmt() {
    Stmt s = Grimp.v().newReturnStmt(IntConstant.v(1));
    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    expectedRep.add(utility.ILLEGAL_MONITOR_STATE_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.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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testJRemExpr.

@Test
public void testJRemExpr() {
    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 = Jimple.v().newLocal("intLocal", IntType.v());
    Local longLocal = Jimple.v().newLocal("longLocal", LongType.v());
    Local floatLocal = Jimple.v().newLocal("floatLocal", FloatType.v());
    Local doubleLocal = Jimple.v().newLocal("doubleLocal", DoubleType.v());
    RemExpr v = Jimple.v().newRemExpr(intLocal, IntConstant.v(0));
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Jimple.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 = Jimple.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 = Jimple.v().newRemExpr(intLocal, intLocal);
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Jimple.v().newRemExpr(longLocal, LongConstant.v(0));
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Jimple.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 = Jimple.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 = Jimple.v().newRemExpr(longLocal, longLocal);
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Jimple.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 = Jimple.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 = Jimple.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 = Jimple.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 = Jimple.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 = Jimple.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 = Jimple.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 = Jimple.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)

Example 3 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testGInstanceFieldRef.

@Test
public void testGInstanceFieldRef() {
    Local local = Grimp.v().newLocal("local", utility.INCOMPATIBLE_CLASS_CHANGE_ERROR);
    Set expectedRep = new ExceptionHashSet(utility.VM_AND_RESOLVE_FIELD_ERRORS_REP);
    expectedRep.add(utility.NULL_POINTER_EXCEPTION);
    Set expectedCatch = new ExceptionHashSet(utility.VM_AND_RESOLVE_FIELD_ERRORS_PLUS_SUPERTYPES);
    expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
    expectedCatch.add(utility.RUNTIME_EXCEPTION);
    expectedCatch.add(utility.EXCEPTION);
    Value v = Grimp.v().newInstanceFieldRef(local, Scene.v().makeFieldRef(utility.THROWABLE.getSootClass(), "detailMessage", RefType.v("java.lang.String"), false));
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(v)));
}
Also used : ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Set(java.util.Set) ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Value(soot.Value) Local(soot.Local) Test(org.junit.Test)

Example 4 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testGArrayRef.

@Test
public void testGArrayRef() {
    ArrayRef arrayRef = Grimp.v().newArrayRef(Grimp.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 5 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testJInvokeStmt.

@Ignore("Fails")
@Test
public void testJInvokeStmt() {
    List voidList = new ArrayList();
    Stmt s = Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(Jimple.v().newLocal("local1", RefType.v("java.lang.Object")), Scene.v().makeMethodRef(Scene.v().getSootClass("java.lang.Object"), "wait", voidList, VoidType.v(), false), voidList));
    ExceptionHashSet expectedRep = new ExceptionHashSet(utility.VM_AND_RESOLVE_METHOD_ERRORS_REP);
    expectedRep.add(utility.NULL_POINTER_EXCEPTION);
    ExceptionHashSet expectedCatch = new ExceptionHashSet(utility.VM_AND_RESOLVE_METHOD_ERRORS_PLUS_SUPERTYPES);
    expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
    expectedCatch.add(utility.RUNTIME_EXCEPTION);
    expectedCatch.add(utility.EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, immaculateAnalysis.mightThrow(s)));
    assertEquals(expectedCatch, utility.catchableSubset(immaculateAnalysis.mightThrow(s)));
    assertTrue(ExceptionTestUtility.sameMembers(utility.ALL_THROWABLES_REP, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    assertEquals(utility.ALL_TEST_THROWABLES, utility.catchableSubset(unitAnalysis.mightThrow(s)));
    SootClass bogusClass = new SootClass("BogusClass");
    bogusClass.addMethod(Scene.v().makeSootMethod("emptyMethod", voidList, VoidType.v(), Modifier.STATIC));
    s = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(Scene.v().makeMethodRef(bogusClass, "emptyMethod", voidList, VoidType.v(), true), voidList));
    assertTrue(ExceptionTestUtility.sameMembers(utility.ALL_ERRORS_REP, Collections.EMPTY_SET, immaculateAnalysis.mightThrow(s)));
    assertEquals(utility.ALL_TEST_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(immaculateAnalysis.mightThrow(s)));
    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) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SootClass(soot.SootClass) ThrowStmt(soot.jimple.ThrowStmt) IfStmt(soot.jimple.IfStmt) Stmt(soot.jimple.Stmt) Ignore(org.junit.Ignore) 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