test: improve test checks
This commit is contained in:
@@ -36,9 +36,9 @@ public class AType<T extends IAttribute> {
|
||||
public static final AType<AttrList<LoopInfo>> LOOP = new AType<>();
|
||||
public static final AType<AttrList<EdgeInsnAttr>> EDGE_INSN = new AType<>();
|
||||
|
||||
public static final AType<AttrList<JadxError>> JADX_ERROR = new AType<>();
|
||||
public static final AType<AttrList<JadxWarn>> JADX_WARN = new AType<>();
|
||||
public static final AType<AttrList<String>> COMMENTS = new AType<>();
|
||||
public static final AType<AttrList<JadxError>> JADX_ERROR = new AType<>(); // code failed to decompile completely
|
||||
public static final AType<AttrList<JadxWarn>> JADX_WARN = new AType<>(); // mark code as inconsistent (code can be viewed)
|
||||
public static final AType<AttrList<String>> COMMENTS = new AType<>(); // any additional info about decompilation
|
||||
|
||||
public static final AType<ExcHandlerAttr> EXC_HANDLER = new AType<>();
|
||||
public static final AType<CatchAttr> CATCH_BLOCK = new AType<>();
|
||||
|
||||
@@ -22,6 +22,8 @@ import jadx.core.ProcessClass;
|
||||
import jadx.core.codegen.CodeGen;
|
||||
import jadx.core.dex.attributes.AFlag;
|
||||
import jadx.core.dex.attributes.AType;
|
||||
import jadx.core.dex.attributes.AttrList;
|
||||
import jadx.core.dex.attributes.IAttributeNode;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.core.dex.nodes.MethodNode;
|
||||
import jadx.core.dex.nodes.RootNode;
|
||||
@@ -40,6 +42,7 @@ import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -176,15 +179,30 @@ public abstract class IntegrationTest extends TestUtils {
|
||||
}
|
||||
|
||||
protected static void checkCode(ClassNode cls) {
|
||||
assertTrue("Inconsistent cls: " + cls,
|
||||
!cls.contains(AFlag.INCONSISTENT_CODE) && !cls.contains(AType.JADX_ERROR));
|
||||
assertFalse("Inconsistent cls: " + cls, hasErrors(cls));
|
||||
for (MethodNode mthNode : cls.getMethods()) {
|
||||
assertTrue("Inconsistent method: " + mthNode,
|
||||
!mthNode.contains(AFlag.INCONSISTENT_CODE) && !mthNode.contains(AType.JADX_ERROR));
|
||||
assertFalse("Method with problems: " + mthNode, hasErrors(mthNode));
|
||||
}
|
||||
assertThat(cls.getCode().toString(), not(containsString("inconsistent")));
|
||||
}
|
||||
|
||||
private static boolean hasErrors(IAttributeNode node) {
|
||||
if (node.contains(AFlag.INCONSISTENT_CODE)
|
||||
|| node.contains(AType.JADX_ERROR)
|
||||
|| node.contains(AType.JADX_WARN)) {
|
||||
return true;
|
||||
}
|
||||
AttrList<String> commentsAttr = node.get(AType.COMMENTS);
|
||||
if (commentsAttr != null) {
|
||||
for (String comment : commentsAttr.getList()) {
|
||||
if (comment.contains("JADX WARN")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void runAutoCheck(String clsName) {
|
||||
try {
|
||||
// run 'check' method from original class
|
||||
|
||||
Reference in New Issue
Block a user