Search in sources :

Example 11 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testJDivExpr.

@Test
public void testJDivExpr() {
    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());
    DivExpr v = Jimple.v().newDivExpr(intLocal, IntConstant.v(0));
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Jimple.v().newDivExpr(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().newDivExpr(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().newDivExpr(intLocal, intLocal);
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Jimple.v().newDivExpr(longLocal, LongConstant.v(0));
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Jimple.v().newDivExpr(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().newDivExpr(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().newDivExpr(longLocal, longLocal);
    assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
    assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
    v = Jimple.v().newDivExpr(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().newDivExpr(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().newDivExpr(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().newDivExpr(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().newDivExpr(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().newDivExpr(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().newDivExpr(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().newDivExpr(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 : DivExpr(soot.jimple.DivExpr) ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Set(java.util.Set) ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Local(soot.Local) Test(org.junit.Test)

Example 12 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testBArrayLengthInst.

@Test
public void testBArrayLengthInst() {
    soot.baf.ArrayLengthInst i = soot.baf.Baf.v().newArrayLengthInst();
    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    expectedRep.add(utility.NULL_POINTER_EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(i)));
    Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
    expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
    expectedCatch.add(utility.RUNTIME_EXCEPTION);
    expectedCatch.add(utility.EXCEPTION);
    assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(i)));
}
Also used : ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Set(java.util.Set) ExceptionHashSet(soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet) Test(org.junit.Test)

Example 13 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testJReturnVoidStmt.

@Ignore("Fails")
@Test
public void testJReturnVoidStmt() {
    Stmt s = Jimple.v().newReturnVoidStmt();
    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 14 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testGExitMonitorStmt.

@Test
public void testGExitMonitorStmt() {
    Stmt s = Grimp.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 15 with ExceptionHashSet

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

the class UnitThrowAnalysisTest method testJNopStmt.

@Test
public void testJNopStmt() {
    Stmt s = Jimple.v().newNopStmt();
    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, 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)

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