@@ -0,0 +1,45 @@
|
||||
package jadx.tests.internal.conditions;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestConditions10 extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
public void test(boolean a, int b) throws Exception {
|
||||
if (a || b > 2) {
|
||||
b++;
|
||||
}
|
||||
if (!a || (b >= 0 && b <= 11)) {
|
||||
System.out.println("1");
|
||||
} else {
|
||||
System.out.println("2");
|
||||
}
|
||||
System.out.println("3");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, not(containsString("return")));
|
||||
assertThat(code, containsOne("if (a || b > 2) {"));
|
||||
assertThat(code, containsOne("b++;"));
|
||||
assertThat(code, containsOne("if (!a || (b >= 0 && b <= 11)) {"));
|
||||
assertThat(code, containsOne("System.out.println(\"1\");"));
|
||||
assertThat(code, containsOne("} else {"));
|
||||
assertThat(code, containsOne("System.out.println(\"2\");"));
|
||||
assertThat(code, containsOne("System.out.println(\"3\");"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package jadx.tests.internal.conditions;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestConditions11 extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
public void test(boolean a, int b) {
|
||||
if (a || b > 2) {
|
||||
f();
|
||||
}
|
||||
}
|
||||
|
||||
private void f() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsOne("if (a || b > 2) {"));
|
||||
assertThat(code, containsOne("f();"));
|
||||
assertThat(code, not(containsString("return")));
|
||||
assertThat(code, not(containsString("else")));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package jadx.tests.internal.conditions;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestConditions12 extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
static boolean autoStop = true;
|
||||
static boolean qualityReading = false;
|
||||
static int lastValidRaw = -1;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
int a = 5;
|
||||
int b = 30;
|
||||
dataProcess(a, b);
|
||||
}
|
||||
|
||||
public static void dataProcess(int raw, int quality) {
|
||||
if (quality >= 10 && raw != 0) {
|
||||
System.out.println("OK" + raw);
|
||||
qualityReading = false;
|
||||
} else if (raw == 0 || quality < 6 || !qualityReading) {
|
||||
System.out.println("Not OK" + raw);
|
||||
} else {
|
||||
System.out.println("Quit OK" + raw);
|
||||
}
|
||||
if (quality < 30) {
|
||||
int timeLeft = 30 - quality;
|
||||
if (quality >= 10) {
|
||||
System.out.println("Processing" + timeLeft);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Finish Processing");
|
||||
if (raw > 0) {
|
||||
lastValidRaw = raw;
|
||||
}
|
||||
}
|
||||
if (quality >= 30 && autoStop) {
|
||||
System.out.println("Finished");
|
||||
}
|
||||
if (!autoStop && lastValidRaw > -1 && quality < 10) {
|
||||
System.out.println("Finished");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsOne("if (quality >= 10 && raw != 0) {"));
|
||||
assertThat(code, containsOne("} else if (raw == 0 || quality < 6 || !qualityReading) {"));
|
||||
assertThat(code, containsOne("if (quality < 30) {"));
|
||||
assertThat(code, containsOne("if (quality >= 10) {"));
|
||||
assertThat(code, containsOne("if (raw > 0) {"));
|
||||
assertThat(code, containsOne("if (quality >= 30 && autoStop) {"));
|
||||
assertThat(code, containsOne("if (!autoStop && lastValidRaw > -1 && quality < 10) {"));
|
||||
assertThat(code, not(containsString("return")));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package jadx.tests.internal.conditions;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestConditions13 extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
static boolean qualityReading;
|
||||
|
||||
public static void dataProcess(int raw, int quality) {
|
||||
if (quality >= 10 && raw != 0) {
|
||||
System.out.println("OK" + raw);
|
||||
qualityReading = false;
|
||||
} else if (raw == 0 || quality < 6 || !qualityReading) {
|
||||
System.out.println("Not OK" + raw);
|
||||
} else {
|
||||
System.out.println("Quit OK" + raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsOne("if (quality >= 10 && raw != 0) {"));
|
||||
assertThat(code, containsOne("System.out.println(\"OK\" + raw);"));
|
||||
assertThat(code, containsOne("qualityReading = false;"));
|
||||
assertThat(code, containsOne("} else if (raw == 0 || quality < 6 || !qualityReading) {"));
|
||||
assertThat(code, not(containsString("return")));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import org.junit.Test;
|
||||
public class TestConditions2 extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
int c;
|
||||
String d;
|
||||
String f;
|
||||
|
||||
@@ -21,6 +21,18 @@ public class TestConditions5 extends InternalJadxTest {
|
||||
throw new AssertionError(a1 + " != " + a2);
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertEquals2(Object a1, Object a2) {
|
||||
if (a1 != null) {
|
||||
if (!a1.equals(a2)) {
|
||||
throw new AssertionError(a1 + " != " + a2);
|
||||
}
|
||||
} else {
|
||||
if (a2 != null) {
|
||||
throw new AssertionError(a1 + " != " + a2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package jadx.tests.internal.conditions;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestConditions9 extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
public void test(boolean a, int b) throws Exception {
|
||||
if (!a || (b >= 0 && b <= 11)) {
|
||||
System.out.println('1');
|
||||
} else {
|
||||
System.out.println('2');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsOne("if (!a || (b >= 0 && b <= 11)) {"));
|
||||
assertThat(code, containsOne("System.out.println('1');"));
|
||||
assertThat(code, containsOne("} else {"));
|
||||
assertThat(code, containsOne("System.out.println('2');"));
|
||||
assertThat(code, not(containsString("return;")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package jadx.tests.internal.conditions;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestSimpleConditions extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
public boolean test1(boolean[] a) {
|
||||
return (a[0] && a[1] && a[2]) || (a[3] && a[4]);
|
||||
}
|
||||
|
||||
public boolean test2(boolean[] a) {
|
||||
return a[0] || a[1] || a[2] || a[3];
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsString("return (a[0] && a[1] && a[2]) || (a[3] && a[4]);"));
|
||||
assertThat(code, containsString("return a[0] || a[1] || a[2] || a[3];"));
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static jadx.tests.utils.JadxMatchers.containsOne;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestLoopCondition2 extends InternalJadxTest {
|
||||
@@ -27,6 +27,9 @@ public class TestLoopCondition2 extends InternalJadxTest {
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsString("while (a && i < 10) {"));
|
||||
assertThat(code, containsOne("int i = 0;"));
|
||||
assertThat(code, containsOne("while (a && i < 10) {"));
|
||||
assertThat(code, containsOne("i++;"));
|
||||
assertThat(code, containsOne("return i;"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user