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)));
}
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)));
}
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)));
}
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)));
}
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)));
}
Aggregations