Search in sources :

Example 46 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestBreakWithLabel method test.

@Test
public void test() throws Exception {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("loop0:"));
    assertThat(code, containsOne("break loop0;"));
    Method test = getReflectMethod("test", int[][].class, int.class);
    int[][] testArray = { { 1, 2 }, { 3, 4 } };
    assertTrue((Boolean) invoke(test, testArray, 3));
    assertFalse((Boolean) invoke(test, testArray, 5));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) Method(java.lang.reflect.Method) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 47 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestRFieldAccess method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestRFieldAccess.class);
    String code = cls.getCode().toString();
    assertThat(code, countString(2, "return R.id.Button01;"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) JadxMatchers.countString(jadx.tests.api.utils.JadxMatchers.countString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 48 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestInvokeInCatch method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("try {"));
    assertThat(code, containsOne("exc();"));
    assertThat(code, not(containsString("return;")));
    assertThat(code, containsOne("} catch (IOException e) {"));
    assertThat(code, containsOne("if (b == 1) {"));
    assertThat(code, containsOne("log(TAG, \"Error: {}\", e.getMessage());"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 49 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestArrayForEach method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsLines(2, "int sum = 0;", "for (int n : a) {", indent(1) + "sum += n;", "}", "return sum;"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 50 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestSwitchLabels method testWithDisabledConstReplace.

@Test
public void testWithDisabledConstReplace() {
    getArgs().setReplaceConsts(false);
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, not(containsString("case CONST_ABC")));
    assertThat(code, containsString("case 2748"));
    assertThat(code, not(containsString("return CONST_CDE;")));
    assertThat(code, containsString("return 3294;"));
    cls.addInnerClass(getClassNode(TestCls.Inner.class));
    assertThat(code, not(containsString("case CONST_CDE_PRIVATE")));
    assertThat(code, not(containsString(".CONST_ABC;")));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Aggregations

ClassNode (jadx.core.dex.nodes.ClassNode)236 Test (org.junit.Test)201 IntegrationTest (jadx.tests.api.IntegrationTest)197 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)93 JadxMatchers.countString (jadx.tests.api.utils.JadxMatchers.countString)17 MethodNode (jadx.core.dex.nodes.MethodNode)12 FieldNode (jadx.core.dex.nodes.FieldNode)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)7 InsnNode (jadx.core.dex.nodes.InsnNode)7 ClassInfo (jadx.core.dex.info.ClassInfo)6 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)6 DexNode (jadx.core.dex.nodes.DexNode)5 InsnArg (jadx.core.dex.instructions.args.InsnArg)4 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)4 SmaliTest (jadx.tests.api.SmaliTest)4 ArrayList (java.util.ArrayList)4 FieldReplaceAttr (jadx.core.dex.attributes.nodes.FieldReplaceAttr)3 FieldInfo (jadx.core.dex.info.FieldInfo)3 MethodInfo (jadx.core.dex.info.MethodInfo)3