From 7b14e322d33b43868eb77eac362ef09b40aae85a Mon Sep 17 00:00:00 2001 From: Skylot Date: Mon, 24 Dec 2018 13:38:42 +0300 Subject: [PATCH] test: improve test checks --- .../java/jadx/core/dex/attributes/AType.java | 6 ++--- .../java/jadx/tests/api/IntegrationTest.java | 26 ++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/AType.java b/jadx-core/src/main/java/jadx/core/dex/attributes/AType.java index f2ca9ba9f..2277b2add 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/AType.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/AType.java @@ -36,9 +36,9 @@ public class AType { public static final AType> LOOP = new AType<>(); public static final AType> EDGE_INSN = new AType<>(); - public static final AType> JADX_ERROR = new AType<>(); - public static final AType> JADX_WARN = new AType<>(); - public static final AType> COMMENTS = new AType<>(); + public static final AType> JADX_ERROR = new AType<>(); // code failed to decompile completely + public static final AType> JADX_WARN = new AType<>(); // mark code as inconsistent (code can be viewed) + public static final AType> COMMENTS = new AType<>(); // any additional info about decompilation public static final AType EXC_HANDLER = new AType<>(); public static final AType CATCH_BLOCK = new AType<>(); diff --git a/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java b/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java index 51c55ea9a..e993c56a1 100644 --- a/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java +++ b/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java @@ -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 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