fix: improve 'out' block detection in switch (#826)

This commit is contained in:
Skylot
2020-01-21 18:11:34 +03:00
parent 62ca30bbc6
commit 2107da2e1a
14 changed files with 345 additions and 168 deletions
@@ -10,6 +10,10 @@ public class JadxCodeAssertions extends AbstractStringAssert<JadxCodeAssertions>
super(code, JadxCodeAssertions.class);
}
public JadxCodeAssertions containsOne(String substring) {
return countString(1, substring);
}
public JadxCodeAssertions countString(int count, String substring) {
isNotNull();
int actualCount = TestUtils.count(actual, substring);
@@ -17,7 +17,7 @@ public class TestSwitch2 extends IntegrationTest {
boolean isScrolling;
float multiTouchZoomOldDist;
void test(int action) {
public void test(int action) {
switch (action & 255) {
case 0:
this.isLongtouchable = true;
@@ -2,7 +2,6 @@ package jadx.tests.integration.switches;
import org.junit.jupiter.api.Test;
import jadx.NotYetImplemented;
import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
@@ -12,6 +11,7 @@ public class TestSwitchFallThrough extends IntegrationTest {
public static class TestCls {
public int r;
@SuppressWarnings("fallthrough")
public void test(int a) {
int i = 10;
switch (a) {
@@ -43,12 +43,14 @@ public class TestSwitchFallThrough extends IntegrationTest {
}
}
@NotYetImplemented("switch fallthrough")
@Test
public void test() {
assertThat(getClassNode(TestCls.class))
.code()
.containsOnlyOnce("switch");
.containsOne("switch (a) {")
.containsOne("r = i;")
.containsOne("r = -1;")
.countString(2, "break;");
// code correctness checks done in 'check' method
}
}
@@ -47,6 +47,8 @@ public class TestSwitchReturnFromCase extends IntegrationTest {
String code = cls.getCode().toString();
assertThat(code, containsString("switch (a % 10) {"));
// case 5: removed
assertEquals(5, count(code, "case "));
assertEquals(3, count(code, "break;"));
@@ -26,6 +26,7 @@ public class TestSwitchWithFallThroughCase extends IntegrationTest {
}
break;
}
// fallthrough
case 2:
if (b) {
str += "2";