Commit 7b14e322 authored by Skylot's avatar Skylot

test: improve test checks

parent 21acaa8d
...@@ -36,9 +36,9 @@ public class AType<T extends IAttribute> { ...@@ -36,9 +36,9 @@ public class AType<T extends IAttribute> {
public static final AType<AttrList<LoopInfo>> LOOP = new AType<>(); public static final AType<AttrList<LoopInfo>> LOOP = new AType<>();
public static final AType<AttrList<EdgeInsnAttr>> EDGE_INSN = 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<JadxError>> JADX_ERROR = new AType<>(); // code failed to decompile completely
public static final AType<AttrList<JadxWarn>> JADX_WARN = new AType<>(); 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<>(); 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<ExcHandlerAttr> EXC_HANDLER = new AType<>();
public static final AType<CatchAttr> CATCH_BLOCK = new AType<>(); public static final AType<CatchAttr> CATCH_BLOCK = new AType<>();
......
...@@ -22,6 +22,8 @@ import jadx.core.ProcessClass; ...@@ -22,6 +22,8 @@ import jadx.core.ProcessClass;
import jadx.core.codegen.CodeGen; import jadx.core.codegen.CodeGen;
import jadx.core.dex.attributes.AFlag; import jadx.core.dex.attributes.AFlag;
import jadx.core.dex.attributes.AType; 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.ClassNode;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.nodes.RootNode; import jadx.core.dex.nodes.RootNode;
...@@ -40,6 +42,7 @@ import static org.hamcrest.Matchers.empty; ...@@ -40,6 +42,7 @@ import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
...@@ -176,15 +179,30 @@ public abstract class IntegrationTest extends TestUtils { ...@@ -176,15 +179,30 @@ public abstract class IntegrationTest extends TestUtils {
} }
protected static void checkCode(ClassNode cls) { protected static void checkCode(ClassNode cls) {
assertTrue("Inconsistent cls: " + cls, assertFalse("Inconsistent cls: " + cls, hasErrors(cls));
!cls.contains(AFlag.INCONSISTENT_CODE) && !cls.contains(AType.JADX_ERROR));
for (MethodNode mthNode : cls.getMethods()) { for (MethodNode mthNode : cls.getMethods()) {
assertTrue("Inconsistent method: " + mthNode, assertFalse("Method with problems: " + mthNode, hasErrors(mthNode));
!mthNode.contains(AFlag.INCONSISTENT_CODE) && !mthNode.contains(AType.JADX_ERROR));
} }
assertThat(cls.getCode().toString(), not(containsString("inconsistent"))); 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) { private void runAutoCheck(String clsName) {
try { try {
// run 'check' method from original class // run 'check' method from original class
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment