-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CheckInitValidator changes and test cases.
- Loading branch information
1 parent
570fd8b
commit c12bfec
Showing
3 changed files
with
193 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
sootup.tests/src/test/java/sootup/tests/validator/CheckInitValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package sootup.tests.validator; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
import categories.Java8Test; | ||
import java.nio.file.Paths; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import sootup.core.model.SootClass; | ||
import sootup.core.model.SootMethod; | ||
import sootup.core.model.SourceType; | ||
import sootup.core.signatures.PackageName; | ||
import sootup.core.types.ClassType; | ||
import sootup.core.validation.CheckInitValidator; | ||
import sootup.core.validation.ValidationException; | ||
import sootup.jimple.parser.JimpleAnalysisInputLocation; | ||
import sootup.jimple.parser.JimpleView; | ||
|
||
@Category(Java8Test.class) | ||
public class CheckInitValidatorTest { | ||
CheckInitValidator checkInitValidator; | ||
JimpleView jimpleView; | ||
|
||
Collection<SootClass> classes; | ||
|
||
@Before | ||
public void Setup() { | ||
|
||
checkInitValidator = new CheckInitValidator(); | ||
|
||
ClassType classTypeCheckInitValidator = | ||
new ClassType() { | ||
@Override | ||
public boolean isBuiltInClass() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getFullyQualifiedName() { | ||
return "jimple.CheckInitValidator"; | ||
} | ||
|
||
@Override | ||
public String getClassName() { | ||
return "CheckInitValidator"; | ||
} | ||
|
||
@Override | ||
public PackageName getPackageName() { | ||
return new PackageName("jimple"); | ||
} | ||
}; | ||
|
||
String classPath = "src/test/resources/validator/jimple"; | ||
JimpleAnalysisInputLocation jimpleInputLocation = | ||
new JimpleAnalysisInputLocation(Paths.get(classPath), SourceType.Application); | ||
|
||
jimpleView = new JimpleView(jimpleInputLocation); | ||
final Optional<SootClass> classSource1 = jimpleView.getClass(classTypeCheckInitValidator); | ||
assertFalse(classSource1.isPresent()); | ||
|
||
classes = new HashSet<>(); // Set to track the classes to check | ||
|
||
for (SootClass aClass : jimpleView.getClasses()) { | ||
if (!aClass.isLibraryClass()) { | ||
classes.add(aClass); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testCheckInitValidatorSuccess() { | ||
List<ValidationException> validationExceptions_success; | ||
|
||
validationExceptions_success = | ||
checkInitValidator.validate( | ||
classes.stream() | ||
.filter(c -> c.getType().getClassName().equals("CheckInitValidator")) | ||
.findFirst() | ||
.get() | ||
.getMethods() | ||
.stream() | ||
.filter(m -> m.getName().equals("checkInitValidator_success")) | ||
.map(SootMethod::getBody) | ||
.findFirst() | ||
.get(), | ||
jimpleView); | ||
|
||
assertEquals(0, validationExceptions_success.size()); | ||
} | ||
|
||
@Test | ||
public void testCheckInitValidatorFail() { | ||
List<ValidationException> validationExceptions_fail; | ||
|
||
validationExceptions_fail = | ||
checkInitValidator.validate( | ||
classes.stream() | ||
.filter(c -> c.getType().getClassName().equals("CheckInitValidator")) | ||
.findFirst() | ||
.get() | ||
.getMethods() | ||
.stream() | ||
.filter(m -> m.getName().equals("checkInitValidator_fail")) | ||
.map(SootMethod::getBody) | ||
.findFirst() | ||
.get(), | ||
jimpleView); | ||
|
||
assertEquals(1, validationExceptions_fail.size()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
sootup.tests/src/test/resources/validator/jimple/CheckInitValidator.jimple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
public class CheckInitValidator extends java.lang.Object | ||
{ | ||
public void <init>() | ||
{ | ||
CheckInitValidator $l0; | ||
|
||
|
||
$l0 := @this: CheckInitValidator; | ||
specialinvoke $l0.<java.lang.Object: void <init>()>(); | ||
|
||
return; | ||
} | ||
|
||
public void checkInitValidator_success() | ||
{ | ||
CheckInitValidator $l0; | ||
unknown $l1, $l2, $l3; | ||
|
||
|
||
$l0 := @this: CheckInitValidator; | ||
$l1 = 2; | ||
$l2 = 3; | ||
$l3 = $l1 + $l2; | ||
|
||
return; | ||
} | ||
|
||
public void checkInitValidator_fail() | ||
{ | ||
CheckInitValidator $l0; | ||
unknown $l1, $l2, $l3; | ||
|
||
$l0 := @this: CheckInitValidator; | ||
$l2 = 3; | ||
$l3 = $l1 + $l2; | ||
|
||
return; | ||
} | ||
} |